test(index): fix flaky IVF_RQ recall test with multi-bit RaBitQ#7679
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
BubbleCal
left a comment
There was a problem hiding this comment.
Maybe just modifying the test to use more bits (3~5 bits should work well for high recall)
| /// `random_orthogonal` (private to `lance-index`); we reproduce an equivalent | ||
| /// deterministically in-crate. The value type must match the dataset because | ||
| /// the quantize path downcasts `rotate_mat` to the dataset's primitive type. | ||
| fn deterministic_orthogonal_fsl(value_type: &DataType, seed: u64) -> FixedSizeListArray { |
There was a problem hiding this comment.
we are not longer using dense matrix for rotating.
There was a problem hiding this comment.
Done 6fde16e. The helper is gone along with the rest of the determinization scaffolding; the test now builds with num_bits = 5 instead of pinning a rotation.
📝 WalkthroughWalkthroughTest expectations in ChangesIVF_RQ Test Threshold Update
Estimated code review effort: 1 (Trivial) | ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
Done 6fde16e. Measured over 336 samples (3 runs x 6 rstest cases x both rotation types x the f32/f64/remap/multivec recall sites):
At 1 bit the old 12 permutations over 10 consecutive runs, all green. |
What
test_build_ivf_rq(rust/lance/src/index/vector/ivf/v2.rs) is flaky: it builds an IVF_RQ index over seeded random vectors and assertsrecall >= 0.5, but recall sits close enough to the bar that it occasionally dips below. It surfaced in CI on #7371 asrecall: 0.49for thecase_2::rotation_type_1_RQRotationType__Fastpermutation (nlist=1, Cosine, Fast rotation) - see the failedlinux-buildjob: https://github.com/lance-format/lance/actions/runs/28875488220/job/85649319644. It is a pre-existing flake, not caused by any recent change to the search path.Root cause
test_recallissues its queries withnprobes == nlist, so every partition is scanned and the measured recall reflects RaBitQ quantization error alone. The test builds withnum_bits = 1, which meansex_bits = 0: only the sign of each rotated coordinate survives. Over 512 uniformly random, L2-normalized 32-dim vectors the top-100 neighbours are barely distinguishable at that resolution, so recall lands near the bar rather than far above it.Measured across 336 samples (3 runs x 6 rstest cases x both rotation types x the f32/f64/remap/multivec recall sites):
num_bitsex_bitsAt
num_bits = 1the0.5bar sits atmean - 4.1 * stdev. The dataset itself is already deterministic (generate_random_array_with_rangeseedsStdRng::from_seed([13; 32])), but the build draws a fresh random rotation every run from an unseeded entropy RNG, and the IVF k-means init is unseeded too, so that tail is reachable. Seeding those would only fix one draw of a distribution whose mean is 0.667; it would not make the assertion mean anything.For comparison, the sibling tests in the same file assert IVF_FLAT
1.0, IVF_PQ0.9 / 0.9 / 0.85, IVF_SQ0.85 / 0.85 / 0.75.Fix
Build with
num_bits = 5instead of1and raise the assertion from0.5to0.9, which lands atmean - 6.9 * stdev. No production change; the diff is confined to#[cfg(test)] mod tests.ex_bits = 4also exercises a FastScan ex-code kernel thattest_build_ivf_rq_multi_bit_persists_split_codes_and_searchesnever reaches: itsnum_bits4 and 6 cases haveex_bits3 and 5, which take the bit-plane repack path, and itsnum_bits = 9case hasex_bits = 8.supports_ex_fastscanaccepts2 | 4 | 8.Both rotation types stay in the matrix. The commented-out
#[ignore = "Temporarily skipping flaky 4-bit IVF_RQ tests"]line is removed: it was dead, and it referred to 4-bit tests when the test was 1-bit.Verification
All 12
test_build_ivf_rqpermutations pass over 10 consecutive runs (120 invocations), including the previously-failingcase_2::rotation_type_1_RQRotationType__Fast. The rest ofindex::vector::ivf::v2::testspasses, which covers the sharedtest_index/test_remap/test_index_multivechelpers used by the SQ, PQ, flat and HNSW tests.cargo fmt --allis clean in all three workspaces andcargo clippy -p lance --tests -- -D warningsis clean.