Fix SymphonyQG inner-product query correction - #102
Merged
Merged
Conversation
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.
Problem and change
SymphonyQG added the inner-product distance constant twice when estimating neighbors: the encoder's
f_addalready includes1, whileBatchQuerysupplied the vertex distance1 - q·cunchanged. With 64-dimensional constant vectorsx = c = 0.125andq = 0.0625, the neighbor estimate was1.5instead of0.5, even though the residual is zero.Make
BatchQuerymetric-aware and convert IP vertex distances to the query correctiondist - 1 = -q·c, following IVF's query-side convention. Search and graph construction retain the original vertex distance separately for results. The encoder factors and estimator remain unchanged.Regression coverage checks exact neighbor distances for zero and collinear residuals in both metrics, across dimensions 64, 1024, and 1088 (both FastScan accumulation paths). Python coverage verifies returned distances and save/load behavior. This fixes the internal distance offset; no recall or performance improvement is claimed.
Validation
RABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF: all 86 tests passed.python -m pytest tests/python/test_symqg.py tests/python/test_symqg_batch.py -q: 30 passed../scripts/check-format.sh,./scripts/check-python.sh, andgit diff --check: passed.qg_test.cppand included headers: passed using a GCC 9 compilation database. Clang 15 could not parse the machine's GCC 14 OpenMP headers; the compatible GCC 9 configuration resolved that tooling issue. Full pre-merge clang-tidy was not run.Compatibility
BatchQuerygains an optional metric argument, defaulting to L2; existing two-argument L2 callers remain valid. IP callers must passMETRIC_IP, andg_add()then represents the estimator correction rather than the vertex result distance. Both SymphonyQG consumers are updated. No Python API, index-format, or dependency changes.