Repository navigation
TQ E2E test - #8788
TQ E2E test#8788
Conversation
📝 WalkthroughWalkthroughThe pull request adds integration tests for TurboQuant (TQ) vector quantization functionality. It introduces a new test module in Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 (3)
lib/quantization/tests/integration/test_tq.rs (3)
80-289: Consider extracting anencode_datasethelper to cut the ~50-line copy/paste across 8 tests.Each of the eight active tests repeats the same
VectorParameters→get_quantized_vector_size→EncodedVectorsTQ::encode→ optionalencode_queryblock. With L1/L2 tests planned to land later, the duplication will only grow. A small helper (parameterized bydistance_type,bits,dim, and the data slice) would shrink each test to its meaningful core (data generation + scoring loop + tolerance) and make tolerance/seed changes a one-line edit.♻️ Sketch of a helper
fn encode_dataset( vector_data: &[Vec<f32>], dim: usize, distance_type: DistanceType, bits: TQBits, ) -> EncodedVectorsTQ<TestEncodedStorage> { let vector_parameters = VectorParameters { dim, deprecated_count: None, distance_type, invert: false, }; let quantized_vector_size = EncodedVectorsTQ::<TestEncodedStorage>::get_quantized_vector_size( &vector_parameters, bits, MODE, ); EncodedVectorsTQ::encode( vector_data.iter(), TestEncodedStorageBuilder::new(None, quantized_vector_size), &vector_parameters, VECTORS_COUNT, bits, MODE, None, &AtomicBool::new(false), ) .unwrap() }Each test then becomes roughly: build
vector_data+query→encode_dataset(...)→encode_query→ score loop.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/quantization/tests/integration/test_tq.rs` around lines 80 - 289, Tests repeat the same VectorParameters → EncodedVectorsTQ::get_quantized_vector_size → EncodedVectorsTQ::encode → optional encode_query logic across multiple tests; extract that into a small helper (e.g., encode_dataset) that accepts vector_data: &[Vec<f32>], dim: usize, distance_type: DistanceType, bits: TQBits and returns EncodedVectorsTQ<TestEncodedStorage>, using VectorParameters { dim, deprecated_count: None, distance_type, invert: false } and calling EncodedVectorsTQ::<TestEncodedStorage>::get_quantized_vector_size and EncodedVectorsTQ::encode (with TestEncodedStorageBuilder::new(...) and AtomicBool::new(false)), unwrap the result, then replace each test's duplicated block with a call to this helper and only keep the data generation, optional encode_query, and scoring loop in the tests.
515-563: Minor: tighten thedim=1upper bound or document the< 10.0choice.For
dim=1with inputs inU[-1, 1], the true dot product is in[-1, 1]. A bound of10.0is very loose — anything from a stray scaling bug to a sign flip would still pass. If the intent is just "doesn't blow up to inf/NaN",is_finite()already covers that; if it's "stays in a sane post-quantization range", something tighter (e.g. a small constant times the data range) would catch more regressions. Not blocking, just a calibration nit.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/quantization/tests/integration/test_tq.rs` around lines 515 - 563, The assertion in test_tq_dim_one_dot currently allows scores with absolute value < 10.0 which is excessively loose for dim=1; update the test (in function test_tq_dim_one_dot) to either (a) tighten the numeric bound on encoded.score_point(&query_u8, index as u32, &counter) to a small constant that reflects the expected data range (e.g. abs(score) < 2.0 or another calculated bound based on the input range and quantization error), or (b) remove the loose numeric check and only assert is_finite() but add a clarifying comment documenting why only finiteness is required; adjust the assertion message to reflect the new bound or the documented intent. Ensure the change is applied around the call sites EncodedVectorsTQ::encode and encoded.score_point so the test behavior is clear.
565-676: Prefer#[ignore]over commented-out test bodies for the L1/L2 placeholders.Commenting out ~110 lines of test code means they won't compile and silently rot through any refactor of
EncodedVectorsTQ::encode,score_point, orDistanceType. Marking them#[ignore](or using#[should_panic(expected = "not implemented")]if you want to actively pin the current panic) keeps them compiling and discoverable viacargo test -- --ignored, while still skipping them in normal CI runs. Theerror_dot-as-placeholder caveat can move into an inline comment on the live test.This also pairs naturally with the helper extraction suggested above — once the helper exists, the L1/L2 bodies shrink to a few lines each.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/quantization/tests/integration/test_tq.rs` around lines 565 - 676, Replace the large commented-out test blocks for test_tq_l2 and test_tq_l1 with real test functions annotated with #[test] and #[ignore] (or #[should_panic(expected = "not implemented")] if you prefer), so they continue to compile and exercise EncodedVectorsTQ::encode, EncodedVectorsTQ::encode_query, score_point, and DistanceType variants; keep the current TODO about error_dot as an inline comment in each test and optionally extract the shared setup into a helper to shrink the bodies as suggested so these tests remain discoverable via cargo test -- --ignored without running in normal CI.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@lib/quantization/tests/integration/test_tq.rs`:
- Around line 80-289: Tests repeat the same VectorParameters →
EncodedVectorsTQ::get_quantized_vector_size → EncodedVectorsTQ::encode →
optional encode_query logic across multiple tests; extract that into a small
helper (e.g., encode_dataset) that accepts vector_data: &[Vec<f32>], dim: usize,
distance_type: DistanceType, bits: TQBits and returns
EncodedVectorsTQ<TestEncodedStorage>, using VectorParameters { dim,
deprecated_count: None, distance_type, invert: false } and calling
EncodedVectorsTQ::<TestEncodedStorage>::get_quantized_vector_size and
EncodedVectorsTQ::encode (with TestEncodedStorageBuilder::new(...) and
AtomicBool::new(false)), unwrap the result, then replace each test's duplicated
block with a call to this helper and only keep the data generation, optional
encode_query, and scoring loop in the tests.
- Around line 515-563: The assertion in test_tq_dim_one_dot currently allows
scores with absolute value < 10.0 which is excessively loose for dim=1; update
the test (in function test_tq_dim_one_dot) to either (a) tighten the numeric
bound on encoded.score_point(&query_u8, index as u32, &counter) to a small
constant that reflects the expected data range (e.g. abs(score) < 2.0 or another
calculated bound based on the input range and quantization error), or (b) remove
the loose numeric check and only assert is_finite() but add a clarifying comment
documenting why only finiteness is required; adjust the assertion message to
reflect the new bound or the documented intent. Ensure the change is applied
around the call sites EncodedVectorsTQ::encode and encoded.score_point so the
test behavior is clear.
- Around line 565-676: Replace the large commented-out test blocks for
test_tq_l2 and test_tq_l1 with real test functions annotated with #[test] and
#[ignore] (or #[should_panic(expected = "not implemented")] if you prefer), so
they continue to compile and exercise EncodedVectorsTQ::encode,
EncodedVectorsTQ::encode_query, score_point, and DistanceType variants; keep the
current TODO about error_dot as an inline comment in each test and optionally
extract the shared setup into a helper to shrink the bodies as suggested so
these tests remain discoverable via cargo test -- --ignored without running in
normal CI.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 65f4fdab-cc4c-4e07-a145-50a961a850f9
📒 Files selected for processing (2)
lib/quantization/tests/integration/main.rslib/quantization/tests/integration/test_tq.rs
Adds e2e tests for TurboQuant on quantization-crate level.
Segment level e2e tests fill follow in a separate PR.