Repository navigation
feat(index): auto-remap IVF_HNSW partitions through the fragment reuse index - #11141
Conversation
Deferred compaction with deletions drops deleted rows from the IVF partition storage as it loads through the fragment-reuse index, which shifts every later storage position. The HNSW graph addresses storage positionally, so it pointed at the wrong vectors and failed to load. Partition loads (including prewarm) now detect when a positional sub-index addresses more rows than the loaded storage holds, compute where each stored row landed, and drop the removed nodes from the graph with `remap_graph_batch` before loading it. Merge-only compaction and non-HNSW sub-indices are unaffected. Adds deferred-compaction tests with deletions for IVF_HNSW_SQ/PQ, with and without prewarm, and an end-to-end benchmark comparing the auto-remapped, physically remapped, and rebuilt index. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ions A physical remap opens the index through the fragment-reuse index, so the partition storage it reads has already dropped the rows that deferred compaction deleted, while the graph read from disk still holds every node. The node count never matched the remap, so every partition fell back to a full graph rebuild. Compose the load-time positions with the remap's own removals, so the graph is repaired once with `remap_graph_repair`. Adds a regression test asserting that nodes with no deleted neighbor keep their edges, and fixes the benchmark's detection of a reusable base dataset. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Load-time realignment dropped removed nodes and their edges, which can strand survivors whose every path from the entry point crossed a deleted node; heavy deferred deletions lost most top-k results. Realign with remap_graph_repair instead, staged from the partition centroid as a build is. Detect dropped rows by comparing the loaded storage with the stored partition size rather than the graph's node count, since HNSW graphs may cover only a prefix of their storage. Such graphs load unchanged without a row-ID remapping, and physical remap still reaches its rebuild fallback. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…anded Repairing every realigned partition at load raised cold prewarm on a 1M-row index from about 0.15 s to 4-6 s. Drop removed nodes first and run the repair only when a level-0 walk from the entry point misses a survivor, which keeps light deletions on the cheap path while heavy ones stay connected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ment remap_graph_batch returns an empty batch without graph metadata when no node survives, which the connectivity check rejected; return it before the check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
westonpace
left a comment
There was a problem hiding this comment.
This looks well thought out. It looks like we have a fast path (when there are no deletions) and a slower path (when there are deletions) that has to do edge repair and we try and minimize that edge repair when we can.
I have two suggestions, both of which can be tackled in follow-ups.
First, we should open a new PR to describe the remapping behavior added here in the index specs (the markdown files). The remapping behavior is pretty complex and otherwise there is a lot that must be inferred from code.
Second, we should add tracing events when remapping. Reampped queries are both potentially slower (because we have to do extra remapping work) and potentially less accurate (if there are deletions whether or not we need to repair). If we can emit these as a metric (via tracing) then that can help us to identify in production when a slowdown or poor recall is potentially triggered by remapping.
## Summary `HnswQueryParams` gained `rq_graph_scoring` in #10910. The prefix-graph test added in #11141 constructs the struct without that field, so every Rust test build of `main` fails: ``` error[E0063]: missing field `rq_graph_scoring` in initializer of `HnswQueryParams` --> rust/lance/src/index/vector/ivf/v2/tests.rs:6553:18 ``` Add it with `Default::default()`, as the other fixtures do. The fixture is an `IVF_HNSW_SQ` partition, so the default (`MultiBit`) scoring is the normal path; the test only asserts that a graph covering a prefix of its storage loads and is searchable. Test-only change, no production behavior. ## Test - `cargo test --profile ci -p lance --lib -- index::vector::ivf::v2::tests::test_hnsw_prefix_graph_loads_without_dropped_rows --exact`: 1 passed. - `cargo fmt --all -- --check`: clean.
# feat(index): support SQ8 quantized refinement `quantized_refine_factor` supports current-format `IVF_SQ` and `IVF_HNSW_SQ` alongside flat `IVF_RQ`. Flat SQ8 uses its native bounded scan. HNSW expands the graph candidate pool and reuses distances computed during graph search at the native eight-bit precision. An explicit `ef` must cover `k * refine_factor * quantized_refine_factor`. The default grows with the candidate budget. Flat RQ uses Fast discovery and Accurate scoring for unbounded queries, and searches directly in Accurate mode for bounded queries. HNSW loads compact, realigned partitions through the existing IVF loader from [#11141](#11141). Deferred compaction, explicit remapping, and prewarming use that same storage and graph alignment. Candidate discovery and final selection apply segment ownership and distance bounds. Fully indexed row-ID and distance queries can run from stored index data. Optional exact refinement, unindexed fragments, and stale overlays can read original vectors. Completed partition results use the existing snapshot identity and session cache budget. Batch queries use the existing per-query path. Python and Java use the same options and Rust validation. ## Validation The cache-disabled regression searches two SQ8 partitions with `ef=64` and compares native `k=32` with `k=8, quantized_refine_factor=4`. It checks the first eight ordered row IDs and distance bits, recall against exact search, partition loads, and comparison counts. The bounded case also verifies an inclusive lower bound and exclusive upper bound against native SQ8 search with the same candidate budget. On the reviewed head (`da48673e9`), the results matched before the regression failed on partition loads. Native search loaded two partitions and recorded 147 comparisons. Quantized refinement loaded four and recorded 211 comparisons. On `9ef9f9cd9`, both queries loaded two partitions and recorded equal comparison counts. The bounded and unbounded results matched native search bit for bit, and recall@8 against exact search met the 0.5 threshold. The persisted-remap regression inspects the replacement files directly after deleting one row from a 400-row fixture, compacting with deferred remapping, and explicitly remapping the index. It checks for 399 physical rows, zero tombstones, exact live membership, and matching graph coverage. Lifecycle cases exercise cold and prewarmed loads after compaction. Rust validation passed on `9ef9f9cd9` with the pinned toolchain and the `ci` profile. The focused score-reuse regression passed, along with 183 refinement tests (including the focused regression), 60 segment tests, four batch segment-ownership tests, and two persisted-remap tests. `cargo fmt --all -- --check` and workspace Clippy with `--all --tests --benches -- -D warnings` passed. The rebuilt Python extension passed all 32 focused vector-index tests. `uv run make lint` passed with 18 Pyright warnings and zero errors. The Java Maven run passed Spotless, all 19 `VectorSearchTest` cases, and all 39 JNI Rust tests. JNI formatting and Clippy passed.
Summary
Deferred compaction (
defer_index_remap) with deletions is currently unusable for IVF_HNSW_* indices. When a partition loads through the fragment-reuse index (FRI), its storage drops the deleted rows and every later storage position shifts. The HNSW graph addresses storage by position, so the partition fails to load ("HNSW graph has N nodes but its vector storage has M rows"). Because of this, deferred remap is gated off for HNSW tables.This PR makes FRI auto-remap work for HNSW and fixes the physical remap that follows.
remap_graph_batch. If a level-0 walk from the entry point then misses any survivor, the graph is repaired withremap_graph_repairinstead. This covers both the normal partition load and prewarm. Merge-only compaction and non-HNSW sub-indices are unaffected: the check compares counts from the partition metadata and does no extra I/O when nothing was dropped.IvfSubIndexhooks:positional_rowsandremap_positions, which are no-ops by default.IvfQuantizationStorage::partition_row_positionsmaps each stored row to its loaded position.remap_hnsw_partitionreads storage that FRI has already shrunk, alongside the full graph from disk. The node counts never matched, so every partition silently fell back to a full graph rebuild. The fix composes the load-time positions with the remap's own removals and callsremap_graph_repaironce.Relation to #10846
#10846 (draft) addresses the same load-time misalignment differently. It keeps deleted rows as tombstone slots, so graph positions never shift, and filters them out at query time. Its explicit remap still falls back to a rebuild. This PR is offered as an alternative for the load-time part. The physical-remap repair fix (2) is independent and could apply on top of either approach.
Benchmark
The new
rust/lance/benches/hnsw_auto_remap.rsrestores a base IVF_HNSW_SQ dataset, deletes rows, and compares four states:pre: deletions applied, no compaction yet.auto: after deferred compaction, auto-remap in effect.phys: after the physical remap.rebuild: after a full rebuild.The results below were measured before fix (2), so
phys≈rebuildin them.5M rows × 128-d, 1024 partitions, S3 from c7i.4xlarge (us-west-2):
Local 1M rows × 128-d, 256 partitions, after fix (2): physical remap logs zero rebuild fallbacks.
phys)Local 1M rows, cold prewarm of the
autostate as load-time realignment evolved (pre≈ 20 ms):Repair cost scales with the share of nodes that lost a neighbor. That share is about 1 − (1 − p)^30, so the gain is large at low deletion rates and small at high ones.
Tests
test_ivf_hnsw_defer_compaction_with_deletionscovers SQ/PQ × {load, prewarm} × {33%, 95% deleted}. The 95% cases strand survivors when edges are only dropped.test_hnsw_prefix_graph_loads_without_dropped_rowsloads a graph covering half its storage with no FRI.remap.rsunit tests check that a connected graph keeps the cheap remap and a stranded one is repaired.test_ivf_hnsw_physical_remap_after_deferred_deletions_repairs_graphasserts that edges of undamaged nodes survive the remap. Retention is 0.94 with fix (2) and 0.69 without.cargo test -p lance --lib -- dataset::optimize index::vector hnsw: 1460 passed.cargo test -p lance-index --lib hnsw: 82 passed.Lint
cargo fmt --allis clean. Clippy (-p lance-index -p lance --no-deps --tests --benches -D warnings) reports nothing in the touched files. Blocker: I could only run it with a local Rust 1.96 toolchain rather than the pinned 1.98.1. That toolchain flags pre-existingnonminimal_boolandunreachable_codelints in untouched files (scanner/fts.rs,io/exec/knn.rs,byte_stream_split.rs), so CI clippy is the authoritative check.Not in this PR
🤖 Generated with Claude Code