[MOD-14952] Support normalization in QuantPreprocessor#1000
Open
dor-forer wants to merge 7 commits into
Open
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-14952-support-quant-normalization
branch
from
July 22, 2026 15:22
0bf91f7 to
f438a59
Compare
2 tasks
* Support norm in QuantPreprocessor * Remove unnecessary allocation and duplicated code (cherry picked from commit 027d551)
dor-forer
force-pushed
the
dor-forer-MOD-14952-support-quant-normalization
branch
from
July 23, 2026 11:59
f438a59 to
d37077d
Compare
dor-forer
marked this pull request as ready for review
July 23, 2026 12:21
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dor-forer-MOD-14953-calc-distance-for-query #1000 +/- ##
============================================================================
Coverage 97.10% 97.11%
============================================================================
Files 141 141
Lines 8268 8296 +28
============================================================================
+ Hits 8029 8057 +28
Misses 239 239 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Base automatically changed from
dor-forer-MOD-14953-calc-distance-for-query
to
main
July 23, 2026 15:18
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
This PR is stacked on #999. Review only the incremental diff against
dor-forer-MOD-14953-calc-distance-for-query.Cherry-picks ARM's
027d5510b2bf7add6a45be9b0c07cda38c15b5cafrom ARM-software/VectorSimilarity-for-Arm#2.This PR adds an optional normalization-aware mode to
QuantPreprocessor. It stores the mean-vector inner product as additional SQ8 metadata for normalized storage and queries, extends SQ8 metadata sizing, and shares a float-based quantization implementation to avoid duplicated logic.Existing
QuantPreprocessorconfigurations retain their current behavior. FP32 and FP16 tests cover normalization for L2 and inner-product metrics.Which issues this PR fixes
Main objects this PR modified
QuantPreprocessorvecsim_types::sq8Mark if applicable
Validation
make formatmake check-formattest_componentsandtest_hnswtest_components: 30/30 passedtest_hnswwithROOTconfigured: 170/170 passedgit diff --check dor-forer-MOD-14953-calc-distance-for-query...HEADNote
Medium Risk
Changes SQ8 blob layout and quantization math for a new API mode; default behavior is unchanged but any consumer must match metadata counts and distance kernels to the stacked PR.
Overview
Adds an optional
WithNormmode toQuantPreprocessorso SQ8 storage can quantize mean-centered vectors while queries stay in the originalDataTypespace.When
WithNorm=true, storage quantization subtracts a supplied FP32 mean before min/max scaling; query preprocessing still copies raw values but recordsy_mean_ip = Σ(mean_i · y_i). Storage metadata gainsx_mean_ip(inner product of the original vector with the mean before centering).vecsim_types::sq8grows compile-timestorage_metadata_count/query_metadata_count(and index helpers) by one float when normalization is enabled. Cosine is explicitly disallowed withWithNorm.The quantization path is refactored through a shared
quantize_implon FP32 values (FP16 and norm paths widen/center into a temp buffer; plain FP32 without norm can still quantize in place). DefaultWithNorm=falsekeeps prior blob sizes and behavior.Unit tests cover L2 and IP for
floatandfloat16, checking centered-quantization parity, blob sizes, and the new metadata slots.Reviewed by Cursor Bugbot for commit d37077d. Bugbot is set up for automated code reviews on this repo. Configure here.