Skip to content

TQ E2E test - #8788

Merged
JojiiOfficial merged 1 commit into
devfrom
tq-e2e-tests
Apr 27, 2026
Merged

JojiiOfficial merged 1 commit into
devfrom
tq-e2e-tests

Conversation

@JojiiOfficial

@JojiiOfficial JojiiOfficial commented Apr 24, 2026 •

Copy link
Copy Markdown
Member

Adds e2e tests for TurboQuant on quantization-crate level.

Segment level e2e tests fill follow in a separate PR.

@JojiiOfficial JojiiOfficial added this to the TurboQuant milestone Apr 24, 2026
@JojiiOfficial
JojiiOfficial marked this pull request as ready for review April 27, 2026 06:59
@JojiiOfficial JojiiOfficial changed the title [WIP] TQ E2E test [TQ E2E test Apr 27, 2026
@JojiiOfficial JojiiOfficial changed the title [TQ E2E test TQ E2E test Apr 27, 2026
@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The pull request adds integration tests for TurboQuant (TQ) vector quantization functionality. It introduces a new test module in lib/quantization/tests/integration/test_tq.rs containing test cases that validate TurboQuant encoding and scoring accuracy across multiple bit configurations (Bits4, Bits2, Bits1) and dimensions. The tests compare approximate scores generated by score_point and score_internal against reference similarity functions with empirically calibrated error tolerances. Edge cases such as zero vectors and single-dimension scoring are also covered. A module declaration is added to main.rs to include the new test module.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • TQ Scoring #8753: Implements TurboQuant scoring and query-precomputation APIs (encode_query, score_point, score_internal) that are directly tested by the integration test suite.
  • Refactor TQ before SIMD integration #8783: Refactors TurboQuant data structures and scoring paths (padded_dim changes, EncodedQueryTQ refactoring) that are exercised by the new tests.
  • Сreate and load TQ #8701: Implements EncodedVectorsTQ creation, loading, and type wiring that form the core data structures validated by these integration tests.

Suggested reviewers

  • IvanPleshkov
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'TQ E2E test' directly summarizes the main change: adding end-to-end tests for TurboQuant (TQ) at the quantization-crate level.
Description check ✅ Passed The description clearly explains that the PR adds e2e tests for TurboQuant on quantization-crate level and mentions segment-level tests will follow separately.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tq-e2e-tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
lib/quantization/tests/integration/test_tq.rs (3)

80-289: Consider extracting an encode_dataset helper 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 → optional encode_query block. With L1/L2 tests planned to land later, the duplication will only grow. A small helper (parameterized by distance_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 the dim=1 upper bound or document the < 10.0 choice.

For dim=1 with inputs in U[-1, 1], the true dot product is in [-1, 1]. A bound of 10.0 is 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, or DistanceType. Marking them #[ignore] (or using #[should_panic(expected = "not implemented")] if you want to actively pin the current panic) keeps them compiling and discoverable via cargo test -- --ignored, while still skipping them in normal CI runs. The error_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

📥 Commits

Reviewing files that changed from the base of the PR and between d436351 and 59dbea6.

📒 Files selected for processing (2)
  • lib/quantization/tests/integration/main.rs
  • lib/quantization/tests/integration/test_tq.rs

@JojiiOfficial
JojiiOfficial merged commit f821735 into dev Apr 27, 2026
15 checks passed
@JojiiOfficial
JojiiOfficial deleted the tq-e2e-tests branch April 27, 2026 07:20
@JojiiOfficial JojiiOfficial mentioned this pull request Apr 27, 2026
63 of 69 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Apr 27, 2026
timvisee pushed a commit that referenced this pull request May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants