Skip to content

fix: relax test_query_delta_indices assertion for approximate index#7622

Merged
yanghua merged 2 commits into
lance-format:mainfrom
XuQianJin-Stars:fix/flaky-test-query-delta-indices-hnsw
Jul 9, 2026
Merged

fix: relax test_query_delta_indices assertion for approximate index#7622
yanghua merged 2 commits into
lance-format:mainfrom
XuQianJin-Stars:fix/flaky-test-query-delta-indices-hnsw

Conversation

@XuQianJin-Stars

@XuQianJin-Stars XuQianJin-Stars commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix a flaky assertion in test_query_delta_indices that fails on Windows CI when the underlying index type is approximate (e.g. IvfHnswSq).

Background

test_query_delta_indices asserts that the top-2 nearest neighbors of the query vector are exactly [0, 1000]. This assumption only holds for exact indexes such as IvfPq / IvfFlat.

For approximate indexes such as IvfHnswSq, scalar quantization (SQ) introduces small numerical differences that can cause the returned row ids to diverge from the exact ground truth. This has been observed on Windows CI, where the test returned [1000, 1486] instead of [0, 1000], producing a flaky failure unrelated to the delta-index logic being tested.

Reference failure log:

  • test index::append::tests::test_query_delta_indices<IvfHnswSq> on Windows CI
  • Expected: [0, 1000]
  • Actual: [1000, 1486]

What this PR does

The core intent of the test is to verify that both delta index segments are queried — i.e. one result comes from the first delta segment (row ids < 1000) and the other from the second delta segment (row ids >= 1000).

This PR relaxes the assertion so that:

  • Exact indexes (IvfPq, IvfFlat, ...): keep the strict assertion row_ids == [0, 1000].
  • Approximate indexes (IvfHnswSq, ...): assert only the structural invariant — one result comes from each delta segment — instead of asserting the exact row ids.

This preserves the original intent of the test while eliminating the false positive caused by SQ quantization error.

Changes

  • rust/lance/src/index/append.rs: relax the assertion in test_query_delta_indices for approximate index types.

Testing

  • cargo fmt --check
  • cargo clippy -p lance --lib --tests --all-features -- -D warnings
  • cargo test -p lance index::append::tests::test_query_delta_indices ✅ (all variants pass)

Risk

Minimal — this is a test-only change that does not alter any production code path. It relaxes an over-strict assertion to match the actual guarantees provided by approximate indexes.

Summary by CodeRabbit

  • Tests
    • Updated query verification to handle both exact and approximate index results appropriately.
    • Exact indexes still expect deterministic matches, while approximate indexes now allow valid nearest-neighbor results from each data range.

The test_query_delta_indices test asserts that the top-2 nearest
neighbors of a query vector are exactly [0, 1000], but this only holds
for exact indexes (e.g. IvfPq / IvfFlat). For approximate indexes such
as IvfHnswSq, scalar quantization can cause the returned ids to differ
from the ground truth (observed on Windows CI: got [1000, 1486]).

The core intent of the test is to verify that both delta indices are
queried (i.e. one result comes from each delta segment). Relax the
assertion accordingly for approximate indexes while keeping the exact
assertion for exact indexes.
@github-actions github-actions Bot added the bug Something isn't working label Jul 4, 2026
@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@yanghua yanghua left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Left two comments.

Comment thread rust/lance/src/index/append.rs Outdated
Comment on lines +1216 to +1222
// For exact indexes (e.g. IvfPq) the top-2 nearest neighbors of the
// query vector are deterministic (id 0 in the first delta and id 1000
// in the second delta, since the same vector is duplicated across
// the two fragments). For approximate indexes (e.g. IvfHnswSq) the
// returned ids are not guaranteed to be exactly [0, 1000]; the key
// property this test verifies is that both delta indices are queried
// (i.e. one result comes from each delta), so we only assert that.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

IvfPq is not exact index?

Comment thread rust/lance/src/index/append.rs Outdated
Comment on lines +1223 to +1226
let is_approximate = !matches!(
index_params.index_type(),
IndexType::IvfFlat | IndexType::IvfPq
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ditto

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The test test_query_delta_indices in append.rs was updated to make its id result assertion index-type aware: exact vector indexes still require deterministic ids [0, 1000], while approximate indexes now only verify one result from each delta range.

Changes

Delta Query Test Update

Layer / File(s) Summary
Index-type aware id assertions
rust/lance/src/index/append.rs
Test assertion now checks exact [0, 1000] ids for exact indexes, and range-based membership (one id below and one at/above TOTAL) for approximate indexes.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the test-only change to relax the assertion for approximate indexes.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
rust/lance/src/index/append.rs (1)

1216-1233: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Approximate-index classification is inverted rather than positive-listed, and the "exact" branch is untested here.

is_approximate is derived as !matches!(index_params.index_type(), IndexType::IvfFlat), i.e. anything that isn't IvfFlat is treated as approximate. This correctly resolves the earlier review feedback that IvfPq should not be classified as exact (per the past comments and follow-up commit noted in the PR description). However, since the #[values(...)] list for this test only supplies ivf_pq and with_ivf_hnsw_sq_params, the else branch (Line 1231, exact [0, 1000] assertion) is currently dead code within this test — it's never exercised. Consider positive-listing the exact type(s) explicitly (e.g. matches!(index_params.index_type(), IndexType::Vector) or whatever type the flat/brute-force build actually reports) instead of the negation, so that adding a new approximate index type to the values list doesn't silently default to the "exact" branch.

🤖 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 `@rust/lance/src/index/append.rs` around lines 1216 - 1233, The test in
append.rs is classifying approximate indexes by negating a single exact type
check, which makes the exact branch effectively unreachable with the current
parameter values. Update the `is_approximate` logic in the test near
`IndexType::IvfFlat` to use a positive allowlist of the exact index type(s)
actually produced by the flat/brute-force path, and keep the approximate
assertion for the remaining types. This should be located via the
`is_approximate` variable and the `index_params.index_type()` match in the test
that asserts on `id_arr`.
🤖 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 `@rust/lance/src/index/append.rs`:
- Around line 1216-1233: The test in append.rs is classifying approximate
indexes by negating a single exact type check, which makes the exact branch
effectively unreachable with the current parameter values. Update the
`is_approximate` logic in the test near `IndexType::IvfFlat` to use a positive
allowlist of the exact index type(s) actually produced by the flat/brute-force
path, and keep the approximate assertion for the remaining types. This should be
located via the `is_approximate` variable and the `index_params.index_type()`
match in the test that asserts on `id_arr`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 46ef85e2-da52-4608-a69e-4b21ae8ffe49

📥 Commits

Reviewing files that changed from the base of the PR and between f24e42c and 507a8a5.

📒 Files selected for processing (1)
  • rust/lance/src/index/append.rs

@yanghua yanghua left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1

@yanghua yanghua merged commit a9f84dd into lance-format:main Jul 9, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants