Skip to content

fix(index): reject out-of-range partition ids when computing residuals - #9004

Open
LuciferYang wants to merge 1 commit into
lance-format:mainfrom
LuciferYang:fix/ivf-rq-residual-partition-id
Open

fix(index): reject out-of-range partition ids when computing residuals#9004
LuciferYang wants to merge 1 commit into
lance-format:mainfrom
LuciferYang:fix/ivf-rq-residual-partition-id

Conversation

@LuciferYang

Copy link
Copy Markdown
Contributor

Problem

do_compute_residual indexes the centroid buffer with the partition id straight from the batch. Ids assigned by the transformer are in range by construction, but a precomputed_partition_dataset supplies them as user data and nothing range-checks it before the slice, so an id beyond the centroid count panicked.

Fixes #9003.

What this changes

Return invalid_input naming the id and the centroid count instead of slicing.

The shuffler already does this for its own per-partition buffers (v3/shuffler.rs:600-606), but the transform chain runs before the shuffle, so for IVF_PQ the residual slice is what the id reaches first.

Test plan

test_compute_residual_rejects_out_of_range_partition passes id 5 against two centroids and asserts the variant and both numbers in the message. Without the check it panics with range start index 10 out of range for slice of length 4.

test_create_ivf_pq_rejects_out_of_range_precomputed_partition builds a real IVF_PQ index from a partitions dataset that assigns one row to partition 7 out of 2, and asserts the error rather than a panic.

  • cargo test -p lance-index --lib 1231 passed, 3 ignored
  • cargo test -p lance --lib index::vector::ivf::tests:: passed
  • cargo clippy --all --tests --benches -- -D warnings clean
  • cargo fmt --all --check clean

Not in this change

IvfShuffler, the legacy shuffler behind LANCE_LEGACY_SHUFFLER=1, indexes its partition buffers without a range check (v3/shuffler.rs:261) and would still panic on the same input. The default TwoFileShuffler path is the one that checks.

compute_residual indexes the centroid buffer with the partition id straight from the batch. Partition ids normally come from the transformer that just assigned them, but a precomputed_partition_dataset supplies them as user data and nothing range-checks it, so an id beyond the centroid count panicked on the slice.

Return invalid_input naming the id and the centroid count instead.
@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer bug Something isn't working labels Sep 4, 2026

@lance-gatekeeper lance-gatekeeper 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.

Gate recommendation: approve.

The guard is at the centroid slice boundary that previously panicked, uses the actual centroid count, and preserves valid residual computation. Regression coverage exercises both the direct residual path and a full IVF_PQ build with a precomputed partition dataset.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-index Vector index, linalg, tokenizer bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: an out-of-range precomputed partition id panics the IVF_PQ build

1 participant