Skip to content

fix: relax test_query_delta_indices assertion for approximate index#7622

Open
XuQianJin-Stars wants to merge 1 commit into
lance-format:mainfrom
XuQianJin-Stars:fix/flaky-test-query-delta-indices-hnsw
Open

fix: relax test_query_delta_indices assertion for approximate index#7622
XuQianJin-Stars wants to merge 1 commit into
lance-format:mainfrom
XuQianJin-Stars:fix/flaky-test-query-delta-indices-hnsw

Conversation

@XuQianJin-Stars

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.

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!

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.

1 participant