Repository navigation
Fix scalar L2 quantized score shift - #9518
IvanPleshkov merged 3 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe fix targets Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related issues
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/quantization/tests/integration/test_simple.rs (1)
243-290: ⚡ Quick winExercise the intended quantile path in this regression test.
With
vectors_count = 80, theSome(0.99)quantile argument is ignored becausefind_quantile_intervalreturnsNonefor counts below 127. Bump the count to at least 127 so this test covers the quantile-based scalar encoding path it appears to target.Proposed test-strengthening change
- let vectors_count = 80; + let vectors_count = 129;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/quantization/tests/integration/test_simple.rs` around lines 243 - 290, The test sets vectors_count to 80, which is below the minimum threshold of 127 required by find_quantile_interval to exercise the quantile-based scalar encoding path that the test intends to cover. Increase the vectors_count variable from 80 to at least 127 so that when EncodedVectorsU8::encode is called with Some(0.99) as the quantile argument, the quantile-based encoding path is actually executed and tested rather than being ignored.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lib/quantization/tests/integration/test_simple.rs`:
- Around line 243-290: The test sets vectors_count to 80, which is below the
minimum threshold of 127 required by find_quantile_interval to exercise the
quantile-based scalar encoding path that the test intends to cover. Increase the
vectors_count variable from 80 to at least 127 so that when
EncodedVectorsU8::encode is called with Some(0.99) as the quantile argument, the
quantile-based encoding path is actually executed and tested rather than being
ignored.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: d3304bcc-68c2-49f9-ab4b-dbe6e13c3201
📒 Files selected for processing (2)
lib/quantization/src/encoded_vectors_u8.rslib/quantization/tests/integration/test_simple.rs
|
Expanded the regression into affine metamorphic score checks, not just the original translated-L2 case. It now covers translation invariance for L1/L2 and positive scaling behavior for Dot/L1/L2, each with normal and inverted scoring. I also bumped the fixture size so the 0.99 quantile path is actually exercised. Focused check passes: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/quantization/tests/integration/test_simple.rs (1)
352-373: 💤 Low valueConsider adding DistanceType::Cosine to positive scaling test for completeness.
While Cosine shares the same
get_shiftimplementation path with Dot (both returnactual_dim * offset²), explicitly testing Cosine would improve test coverage comprehensiveness and align with the PR objectives mentioning "each distance metric is tested."Expected scale factor for Cosine would be
6.25(same as Dot).📋 Optional test case additions
#[rstest] #[case(DistanceType::Dot, false, 6.25)] #[case(DistanceType::Dot, true, 6.25)] + #[case(DistanceType::Cosine, false, 6.25)] + #[case(DistanceType::Cosine, true, 6.25)] #[case(DistanceType::L1, false, 2.5)] #[case(DistanceType::L1, true, 2.5)] #[case(DistanceType::L2, false, 6.25)] #[case(DistanceType::L2, true, 6.25)]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/quantization/tests/integration/test_simple.rs` around lines 352 - 373, The test function test_scalar_quantized_scores_follow_positive_scaling is missing parametrized test cases for DistanceType::Cosine. Add two additional #[case] attributes to the rstest macro before the function definition: one for DistanceType::Cosine with invert=false and expected_scale=6.25, and another for DistanceType::Cosine with invert=true and expected_scale=6.25, to ensure consistent test coverage across all distance metrics including Cosine.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lib/quantization/tests/integration/test_simple.rs`:
- Around line 352-373: The test function
test_scalar_quantized_scores_follow_positive_scaling is missing parametrized
test cases for DistanceType::Cosine. Add two additional #[case] attributes to
the rstest macro before the function definition: one for DistanceType::Cosine
with invert=false and expected_scale=6.25, and another for DistanceType::Cosine
with invert=true and expected_scale=6.25, to ensure consistent test coverage
across all distance metrics including Cosine.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: c4464a90-5534-4888-8e26-7d730d036bb9
📒 Files selected for processing (2)
lib/quantization/src/encoded_vectors_u8.rslib/quantization/tests/integration/test_simple.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- lib/quantization/src/encoded_vectors_u8.rs
|
@RitwijParmar, fix please CI to make it possible to merge, |
IvanPleshkov
left a comment
There was a problem hiding this comment.
This is a totally correct fix. L2 shift should be zero, like L1.
|
Thanks Ivan. Ran Also checked |
|
Fixed the Clippy needless borrow too. Checked |
|
Thanks for the contribution! |
* fix scalar L2 quantized score shift * Format scalar quantization imports * Fix quantization test clippy
Summary
Fixes the scalar int8 L2 scoring path so rescore=false scores do not include the dot-product quantizer offset-squared shift.
For squared L2, a common quantizer offset cancels before squaring. Reusing the dot/cosine shift made approximate Euclid scores depend on translating every stored vector and the query by the same constant.
I also expanded the regression into scalar-quantization metamorphic score contracts:
That keeps this from being a one-off reproduction and makes the affine score behavior explicit for future quantization changes.
Closes #9515.
Tests