[MOD-14953] Add calcDistanceForQuery to IndexCalculatorInterface#999
Merged
Conversation
* IndexCalculatorInterface change Add calcDistanceForQuery() API and use it in HNSW index * Improve tests (cherry picked from commit ed1df68)
dor-forer
force-pushed
the
dor-forer-MOD-14953-calc-distance-for-query
branch
from
July 22, 2026 09:02
29ac23a to
2fe184d
Compare
2 tasks
dor-forer
marked this pull request as ready for review
July 22, 2026 11:51
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #999 +/- ##
==========================================
- Coverage 97.14% 97.10% -0.05%
==========================================
Files 141 141
Lines 8245 8268 +23
==========================================
+ Hits 8010 8029 +19
- Misses 235 239 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
2 tasks
ofiryanai
approved these changes
Jul 23, 2026
| if (label == 1) { // the result in the hnsw index | ||
| expected_score = hnsw_index->calcDistance(norm_double_query, norm_double_vec); | ||
| expected_score = | ||
| hnsw_index->calcDistanceForQuery(norm_double_vec, norm_double_query); |
Collaborator
There was a problem hiding this comment.
AI suggest to increase coverage:
This HNSW instance defaults
query_dist_functo dist_func, so it does not verify that HNSW selects the distinctStoredToQuerydispatch. Add an integration test that installs different stored↔stored and stored↔query functions
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.
Describe the changes in the pull request
Cherry-picks ARM's
ed1df68a4f1585747068a0560720fd76fb92a6b9from ARM-software/VectorSimilarity-for-Arm#1.This PR adds
calcDistanceForQueryso stored candidates and query blobs can use asymmetric representations and operand ordering.It also introduces a construction-time
DistanceDispatchselected throughgetDistanceDispatch(DistanceMode). HNSW caches one dispatch for stored-to-stored distances and another for stored-to-query distances, avoiding calculator vtable lookups in the hot path.The dispatch has separate optimized representations:
HNSW search and batch-iterator paths use the stored-to-query dispatch. Index construction and maintenance continue using the stored-to-stored dispatch. Component tests cover symmetric defaults, asymmetric query functions, stateless dispatch, and contextual dispatch.
Which issues this PR fixes
Main objects this PR modified
IndexCalculatorInterface,DistanceCalculatorInterface, andDistanceDispatchVecSimIndexAbstractHNSWIndexandHNSW_BatchIteratorMark if applicable
Validation
make formatmake check-formattest_componentsandtest_hnswtest_components: 28/28 passedtest_hnswexcluding the two external serialization fixtures: 168/168 passedHNSWTest/0.hnsw_blob_sanity_testpassed