Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-19284 : Refactor - Extract duplicated vector distance function registration #9904

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

0xC0FFE2
Copy link

Extracted duplicated vector distance function registration code into a helper method to improve code clarity and maintenance.

https://hibernate.atlassian.net/browse/HHH-19284


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


@0xC0FFE2 0xC0FFE2 marked this pull request as draft March 26, 2025 11:16
@0xC0FFE2 0xC0FFE2 marked this pull request as ready for review March 26, 2025 11:39
@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Mar 26, 2025

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

@0xC0FFE2 0xC0FFE2 changed the title HHH-19284 : Extract duplicated vector distance function registration HHH-19284 : Refactor - Extract duplicated vector distance function registration Mar 27, 2025
Copy link
Member

@yrodiere yrodiere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @0xC0FFE2 ,

Thanks for your contribution.

While I agree your code is a slight improvement, I want to stress that refactoring for the sake of it is not something the whole Hibernate team sees with a good eye, especially if it's just some very localized problem: the cost of doing that refactoring and reviewing it often outweighs the benefits.

I'm ready to merge this, but:

  1. If you are looking for ways to contribute to Hibernate, please have a look at the good first issues.
  2. Please rebase your branch on the main branch to remove the "merge commit" -- we don't allow those.

@gavinking
Copy link
Member

I'm ready to merge this

I for one would not merge this, not unless a similar change is done in the VectorContributors for the other dialects. As it is, this introduces an inconsistency between the dialects.

@0xC0FFE2
Copy link
Author

0xC0FFE2 commented Apr 9, 2025

Hello , @yrodiere @gavinking

I apologize for the inconsistency in my initial PR. Per the reviewers' feedback, I've now refactored all FunctionContributor classes to ensure consistency

  • MariaDBFunctionContributor - kept as initially refactored
  • OracleVectorFunctionContributor - refactored
  • PGVectorFunctionContributor - refactored

image

image

For the other VectorContributor classes, I've decided to keep them in their current state as they are already concise and clearly structured. Applying similar refactoring would actually increase code length and complexity without significant benefits.

I've also rebased my branch on the main branch to remove the merge commit as requested.

Thank you for your detailed feedback.

Copy link
Member

@yrodiere yrodiere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Please don't use spaces for indentation though -- not because one or the other is better, but for consistency with the rest of the codebase.

See:

https://github.com/hibernate/hibernate-orm/blob/main/CONTRIBUTING.md#getting-started
https://hibernate.org/community/contribute/intellij-idea/

@0xC0FFE2 0xC0FFE2 force-pushed the main branch 2 times, most recently from 693ab35 to 37437d9 Compare April 9, 2025 11:20
@0xC0FFE2 0xC0FFE2 requested a review from yrodiere April 9, 2025 11:22
@0xC0FFE2
Copy link
Author

0xC0FFE2 commented Apr 9, 2025

@yrodiere

Thank you for pointing this out.

I've updated the code to use tabs instead of spaces for indentation to match the project's coding style.

I'll make sure to follow the contribution guidelines more carefully in the futurre
thanks.

Copy link
Member

@yrodiere yrodiere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the cleanup.

Though as I said above... next time you want to contribute, please consider having a look at the good first issues instead :)

@0xC0FFE2
Copy link
Author

0xC0FFE2 commented Apr 9, 2025

thanks.

@yrodiere
Copy link
Member

yrodiere commented Apr 9, 2025

Looks like format checks are still failing? Probably some trailing tabs/spaces at the end of lines, or missing line break at the end of a file? See below.

I think just running a build locally should automatically fix your format issues: ./gradlew build -x test

> The following files had format violations:
      src/main/java/org/hibernate/vector/MariaDBFunctionContributor.java
          @@ -25,19 +25,19 @@
           \t\t\tfinal·TypeConfiguration·typeConfiguration·=·functionContributions.getTypeConfiguration();
           \t\t\tfinal·BasicTypeRegistry·basicTypeRegistry·=·typeConfiguration.getBasicTypeRegistry();
           \t\t\tfinal·BasicType<Double>·doubleType·=·basicTypeRegistry.resolve(StandardBasicTypes.DOUBLE);
          -\t\t\t
          +
           \t\t\tregisterVectorDistanceFunction(functionRegistry,·"cosine_distance",·"vec_distance_cosine",·doubleType);
           \t\t\tregisterVectorDistanceFunction(functionRegistry,·"euclidean_distance",·"vec_distance_euclidean",·doubleType);
           \t\t\tfunctionRegistry.registerAlternateKey("l2_distance",·"euclidean_distance");
           \t\t}
           \t}
          -\t
          +
           \tprivate·void·registerVectorDistanceFunction(
           \t\t\tSqmFunctionRegistry·functionRegistry,
           \t\t\tString·functionName,
           \t\t\tString·templatePattern,
           \t\t\tBasicType<Double>·returnType)·{
          -\t\t
          +
           \t\tfunctionRegistry.patternDescriptorBuilder(functionName,·templatePattern·+·"(?1,?2)")
           \t\t\t\t.setArgumentsValidator(StandardArgumentsValidators.composite(
           \t\t\t\t\t\tStandardArgumentsValidators.exactly(2),
          @@ -52,4 +52,4 @@
           \tpublic·int·ordinal()·{
           \t\treturn·200;
           \t}
          -}
          +}
      src/main/java/org/hibernate/vector/OracleVectorFunctionContributor.java
          @@ -80,4 +80,4 @@
           \tpublic·int·ordinal()·{
           \t\treturn·200;
           \t}
          -}
          +}
      src/main/java/org/hibernate/vector/PGVectorFunctionContributor.java
          @@ -38,7 +38,7 @@
           
           \t\t\tregisterVectorDistanceFunction(functionRegistry,·"negative_inner_product",·"?1<#>?2",·doubleType);
           \t\t\tregisterVectorDistanceFunction(functionRegistry,·"inner_product",·"(?1<#>?2)*-1",·doubleType);
          -\t\t\t
          +
           \t\t\tregisterNamedVectorFunction(functionRegistry,·"vector_dims",·integerType,·1);
           \t\t\tregisterNamedVectorFunction(functionRegistry,·"vector_norm",·doubleType,·1);
           \t\t}
          @@ -80,4 +80,4 @@
           \tpublic·int·ordinal()·{
           \t\treturn·200;

@0xC0FFE2
Copy link
Author

0xC0FFE2 commented Apr 9, 2025

@yrodiere

I ran ./gradlew build -x test as you suggested.

Thanks and sorry for the format error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants