Repository navigation
Expose metric-aware quantizer centroid distance - #1395
Mark Hildebrand (hildebrandmw) merged 6 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The public trait change is breaking, and cosine correction and overflow handling remain unresolved.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds a metric-aware squared centroid-distance API to spherical quantizers.
Changes:
- Implements distance calculation and validation.
- Re-exports the new error type.
- Forwards the API through
Quantizerimplementations and adds tests.
File summaries
| File | Summary |
|---|---|
diskann-quantization/src/spherical/quantizer.rs |
Implements centroid-distance logic, validation, and tests. |
diskann-quantization/src/spherical/mod.rs |
Re-exports the new error type. |
diskann-quantization/src/spherical/iface.rs |
Adds and forwards the public trait method. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Mark Hildebrand (hildebrandmw)
left a comment
There was a problem hiding this comment.
Thanks - a few maintainability requests on my end with respect to testing. It's okay that this is technically an API breaking change.
Also feel free to ignore Copilot's claims about divergence in the cosine correction. There appears to be an existing bug with pre-scales not being correctly rejected when Cosine is used. As long as the implementation follows SphericalQuantizer::preprocess, it's fine.
Mark Hildebrand (hildebrandmw)
left a comment
There was a problem hiding this comment.
One request for documentation update, otherwise looks great to me. Thanks!
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1395 +/- ##
==========================================
- Coverage 92.07% 92.06% -0.01%
==========================================
Files 586 586
Lines 119997 120082 +85
==========================================
+ Hits 110488 110557 +69
- Misses 9509 9525 +16
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mark Hildebrand (hildebrandmw)
left a comment
There was a problem hiding this comment.
Please open an issue for a follow-up to tighten the public API of the quantizer make providing pre-scaling with the Cosine metric impossible. Silently ignoring pre-scaling when provided is not behavior I want to keep long-term in this API.
@microsoft-github-policy-service agree company="Microsoft" |
…zer-centroid-distance
683cabe
into
microsoft:main
Summary
pre_scaleQuantizertrait implementationsMotivation
LibVector needs to compare a current data centroid with the original centroid persisted in a trained quantizer. Keeping this computation in
diskann-quantizationavoids reconstructing private quantizer state in an external FFI layer. Squared-L2 and inner-product quantizers store a pre-scaled shift, so the API removes that scale before comparison. Cosine training averages individually normalized vectors and does not pre-scale the stored centroid, so the supplied averaged centroid is compared directly without being normalized again.Formula
Validation
cargo test -p diskann-quantizationpre_scaleto verify that cosine ignores scalingcargo fmt --all -- --checkpassescargo clippy --workspace --all-targets --config 'build.rustflags=["-Dwarnings"]'passesgit diff --checkpasses