fix(index): store the converted metric in IvfTransformer::new_flat - #9399
Open
LuciferYang wants to merge 3 commits into
Open
LuciferYang wants to merge 3 commits into
LuciferYang wants to merge 3 commits into
Conversation
new_flat computed the cosine-converted L2 metric for its PartitionTransformer but stored the original distance type on IvfTransformer, so find_partitions/compute_partitions assigned with Cosine over data partitioned under L2-on-normalized. Store the converted metric like every sibling constructor. Assisted-by: GLM-5.3
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
Storing the converted L2 metric matches the transformer’s existing normalize-then-L2 contract and prevents the Cosine variant from reaching unsupported partition-distance code. The added regression covers this invariant; I found no blocking or material residual risk.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9398
new_flatconverts cosine to L2 for its transform chain (normalize, then assign with L2) and then handed the original metric toIvfTransformer::new, unlikewith_pqand the constructor above it. The stored metric is what the transformer's ownfind_partitions,compute_partitions, andcompute_residualuse, so a cosine flat transformer measured in cosine while its chain had assigned in L2. It now storesdt, so all four agree.Partition choice is unchanged: the vectors and centroids are normalized by then, and cosine and L2 rank unit vectors the same way. What changes is the scale of the distances those three methods return, which now matches the
__ivf_centroid_distvalues the chain produces.How was this patch tested?
test_new_flat_keeps_the_converted_metricbuilds a cosine and an L2 flat transformer over the same unit centroids and assertsfind_partitionsreturns the same partitions and the same distances for both. With the original metric stored, the cosine one returns cosine distances and the test fails. The file had no test module before, so this adds one.