You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "ChrisHegarty (via GitHub)" <gi...@apache.org> on 2024/02/20 09:54:16 UTC

[PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

ChrisHegarty opened a new pull request, #13119:
URL: https://github.com/apache/lucene/pull/13119

   This commit updates the FieldInfosFormat translation of vector similarity functions to be independent of the `VectorSimilartyFunction` enum.
   
   The `VectorSimilartyFunction` enum lives outside of the codec format, and the format should not inadvertently depend upon the declaration order or values in VectorSimilartyFunction. The format should be in charge of the translation of similarity function to format ordinal (and visa versa). In reality, and for now, the translation remains the same as the declaration order, but this may not be the case in the future.
   
   Note: did we introduce a potential index corruption issue when adding maximum inner product in 9.8.0? since the format was not updated when the enum value was added - the ordinal for maximum inner product is unknown to Lucene 9.7.0, which uses the same format.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

Posted by "ChrisHegarty (via GitHub)" <gi...@apache.org>.
ChrisHegarty commented on code in PR #13119:
URL: https://github.com/apache/lucene/pull/13119#discussion_r1497177281


##########
lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99HnswVectorsReader.java:
##########
@@ -171,15 +172,25 @@ private void validateFieldEntry(FieldInfo info, FieldEntry fieldEntry) {
     }
   }
 
+  // List of vector similarity functions. This list is defined here, in order
+  // to avoid an undesirable dependency on the declaration and order of values
+  // in VectorSimilarityFunction. The list values and order have been chosen to
+  // match that of VectorSimilarityFunction in, at least, Lucene 9.10. Values
+  // should only be appended to the end of the list.
+  public static final List<VectorSimilarityFunction> SIMILARITY_FUNCTIONS =

Review Comment:
   There's a little duplication here, but we want the codecs to be largely independent.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #13119:
URL: https://github.com/apache/lucene/pull/13119#issuecomment-1954160317

   > > Hi, as stated in the other issue: I am not really happy to have that enum at all! The similarity/distance functions should be pluggable using `NamedSPILoader`. To implement that, the ordinals must removed in a new file format version and instead names be written using the Codec utility classes.
   > 
   > Agreed on where we wanna get to. Just trying to get there incrementally, since format changes are quite noisy.
   > 
   > > As a first step this PR is fine as it does not change file format and just decouples the ordinals from the enum. In future, when we have SPI, we can use the current code of the ordinals
   > 
   > Exactly, this is just a first step. It (for the most part) encapsulates the translation in the format. When we add a new format and/or evolve VectorSimilarityFunction, this format should be largely immune to the change.
   > 
   > > In my opinion, the strings as lookup keys are not needed: Just define it as `List<VectorSimilarityFunction>` to get the link between them. At a later stage the backwards layer could then fallback to the list with SPI instances to lookup the legacy ordinals. The coec and the enum are still _enough_ decoupled.
   > 
   > Yeah, that's probably good enough for now. Updated.
   
   The comment is a bit outdated. I was thinking of making it even more vebose by having 2 maps for the lookup...
   
   +1 looks fine.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #13119:
URL: https://github.com/apache/lucene/pull/13119#issuecomment-1954105604

   > Index format wise, I think the index corruption can occur when reading a Lucene 9.8.0 index with Lucene 9.7.0, as the format would allow that, but I am not sure this is an expected scenario.
   
   This is perfectly fine.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

Posted by "ChrisHegarty (via GitHub)" <gi...@apache.org>.
ChrisHegarty merged PR #13119:
URL: https://github.com/apache/lucene/pull/13119


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

Posted by "ChrisHegarty (via GitHub)" <gi...@apache.org>.
ChrisHegarty commented on PR #13119:
URL: https://github.com/apache/lucene/pull/13119#issuecomment-1953858737

   This PR is a prerequisite for future work to make the similarity function symbolic and lookup-able, see https://github.com/apache/lucene/pull/13076#issuecomment-1930363479.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

Posted by "benwtrent (via GitHub)" <gi...@apache.org>.
benwtrent commented on code in PR #13119:
URL: https://github.com/apache/lucene/pull/13119#discussion_r1497494311


##########
lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99HnswVectorsReader.java:
##########
@@ -171,15 +172,25 @@ private void validateFieldEntry(FieldInfo info, FieldEntry fieldEntry) {
     }
   }
 
+  // List of vector similarity functions. This list is defined here, in order
+  // to avoid an undesirable dependency on the declaration and order of values
+  // in VectorSimilarityFunction. The list values and order have been chosen to
+  // match that of VectorSimilarityFunction in, at least, Lucene 9.10. Values
+  // should only be appended to the end of the list.
+  public static final List<VectorSimilarityFunction> SIMILARITY_FUNCTIONS =

Review Comment:
   🤔 OK, this is really weird to me. For some reason, we are writing the dimension & similarity into the vector metdata but that information is retained in the field info already. 
   
   I honestly don't know why we do this. Are we concerned that things will become out of sync? @msokolov maybe you know? I see this pattern all the way back in Lucene90.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

Posted by "ChrisHegarty (via GitHub)" <gi...@apache.org>.
ChrisHegarty commented on PR #13119:
URL: https://github.com/apache/lucene/pull/13119#issuecomment-1954132655

   > Hi, as stated in the other issue: I am not really happy to have that enum at all! The similarity/distance functions should be pluggable using `NamedSPILoader`. To implement that, the ordinals must removed in a new file format version and instead names be written using the Codec utility classes.
   
   Agreed on where we wanna get to. Just trying to get there incrementally, since format changes are quite noisy.
   
   > As a first step this PR is fine as it does not change file format and just decouples the ordinals from the enum. In future, when we have SPI, we can use the current code of the ordinals
   
   Exactly, this is just a first step. It (for the most part) encapsulates the translation in the format. When we add a new format and/or evolve VectorSimilarityFunction, this format should be largely immune to the change.
   
   > In my opinion, the strings as lookup keys are not needed: Just define it as `List<VectorSimilarityFunction>` to get the link between them. At a later stage the backwards layer could then fallback to the list with SPI instances to lookup the legacy ordinals. The coec and the enum are still _enough_ decoupled.
   
   Yeah, that's probably good enough for now. Updated.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

Posted by "msokolov (via GitHub)" <gi...@apache.org>.
msokolov commented on PR #13119:
URL: https://github.com/apache/lucene/pull/13119#issuecomment-1963094604

   >  OK, this is really weird to me. For some reason, we are writing the dimension & similarity into the vector metdata but that information is retained in the field info already.
   
   @benwtrent honestly don't remember, but I do know that early on we tried things a few different ways. There was some discussion about whether the similarity function and dimensions should be in the codec vs in the field info. I suspect it evolved and we did not end up removing the redundant version?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

Posted by "ChrisHegarty (via GitHub)" <gi...@apache.org>.
ChrisHegarty commented on PR #13119:
URL: https://github.com/apache/lucene/pull/13119#issuecomment-1954278599

   I see now that we have a similar dependency in `Lucene99HnswVectorsReader`. I'll update in a similar way.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

Posted by "tteofili (via GitHub)" <gi...@apache.org>.
tteofili commented on code in PR #13119:
URL: https://github.com/apache/lucene/pull/13119#discussion_r1495629501


##########
lucene/core/src/java/org/apache/lucene/codecs/lucene94/Lucene94FieldInfosFormat.java:
##########
@@ -111,6 +112,8 @@
  *         <li>0: EUCLIDEAN distance. ({@link VectorSimilarityFunction#EUCLIDEAN})
  *         <li>1: DOT_PRODUCT similarity. ({@link VectorSimilarityFunction#DOT_PRODUCT})
  *         <li>2: COSINE similarity. ({@link VectorSimilarityFunction#COSINE})
+ *         <li>3: MAXIMUM_INNER_PRODUCT similarity. ({@link
+ *             VectorSimilarityFunction#MAXIMUM_INNER_PRODUCT})

Review Comment:
   probably it'd make sense to do it in a different PR, for easier tracking



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

Posted by "ChrisHegarty (via GitHub)" <gi...@apache.org>.
ChrisHegarty commented on PR #13119:
URL: https://github.com/apache/lucene/pull/13119#issuecomment-1954136856

   > > Index format wise, I think the index corruption can occur when reading a Lucene 9.8.0 index with Lucene 9.7.0, as the format would allow that, but I am not sure this is an expected scenario.
   > 
   > This is perfectly fine.
   
   Ok cool. I was worried for nothing then.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

Posted by "benwtrent (via GitHub)" <gi...@apache.org>.
benwtrent commented on PR #13119:
URL: https://github.com/apache/lucene/pull/13119#issuecomment-1963483170

   @msokolov thanks for clarifying. I just wanted to make sure there wasn't an important reason that I missed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

Posted by "ChrisHegarty (via GitHub)" <gi...@apache.org>.
ChrisHegarty commented on PR #13119:
URL: https://github.com/apache/lucene/pull/13119#issuecomment-1959890082

   Thanks for the reviews. All comments have been addressed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

Posted by "benwtrent (via GitHub)" <gi...@apache.org>.
benwtrent commented on code in PR #13119:
URL: https://github.com/apache/lucene/pull/13119#discussion_r1499170841


##########
lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99HnswVectorsReader.java:
##########
@@ -171,15 +172,25 @@ private void validateFieldEntry(FieldInfo info, FieldEntry fieldEntry) {
     }
   }
 
+  // List of vector similarity functions. This list is defined here, in order
+  // to avoid an undesirable dependency on the declaration and order of values
+  // in VectorSimilarityFunction. The list values and order have been chosen to
+  // match that of VectorSimilarityFunction in, at least, Lucene 9.10. Values
+  // should only be appended to the end of the list.
+  public static final List<VectorSimilarityFunction> SIMILARITY_FUNCTIONS =

Review Comment:
   Since (for some unknown reason to me), we already write out the values to the codec files & we don't want to break the current codec, this is fine with me. 
   
   I think if/when we create a new HNSW/vector codecs in the future, we should consider not writing the danged similarity functions in two places. 



##########
lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99HnswVectorsReader.java:
##########
@@ -171,15 +172,25 @@ private void validateFieldEntry(FieldInfo info, FieldEntry fieldEntry) {
     }
   }
 
+  // List of vector similarity functions. This list is defined here, in order
+  // to avoid an undesirable dependency on the declaration and order of values
+  // in VectorSimilarityFunction. The list values and order have been chosen to
+  // match that of VectorSimilarityFunction in, at least, Lucene 9.10. Values
+  // should only be appended to the end of the list.
+  public static final List<VectorSimilarityFunction> SIMILARITY_FUNCTIONS =

Review Comment:
   Could you add/complete your comment indicating that the values here need to be in order and the SAME order as the field info ones for bwc?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] FieldInfosFormat translation should be independent of VectorSimilartyFunction enum [lucene]

Posted by "ChrisHegarty (via GitHub)" <gi...@apache.org>.
ChrisHegarty commented on code in PR #13119:
URL: https://github.com/apache/lucene/pull/13119#discussion_r1495556754


##########
lucene/core/src/java/org/apache/lucene/codecs/lucene94/Lucene94FieldInfosFormat.java:
##########
@@ -111,6 +112,8 @@
  *         <li>0: EUCLIDEAN distance. ({@link VectorSimilarityFunction#EUCLIDEAN})
  *         <li>1: DOT_PRODUCT similarity. ({@link VectorSimilarityFunction#DOT_PRODUCT})
  *         <li>2: COSINE similarity. ({@link VectorSimilarityFunction#COSINE})
+ *         <li>3: MAXIMUM_INNER_PRODUCT similarity. ({@link
+ *             VectorSimilarityFunction#MAXIMUM_INNER_PRODUCT})

Review Comment:
   I'm not sure whether or not to add this here, since maximum inner product was added in 9.8.0!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org