Skip to content

feat(index): auto-remap IVF_HNSW partitions through the fragment reuse index - #11141

Merged
westonpace merged 6 commits into
lance-format:mainfrom
jzheng106:autoRemap-hnsw
Nov 23, 2026
Merged

westonpace merged 6 commits into
lance-format:mainfrom
jzheng106:autoRemap-hnsw

Conversation

@jzheng106

@jzheng106 jzheng106 commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

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.

  1. Load-time realignment (auto-remap). When the loaded storage holds fewer rows than the partition stores, the partition load computes where each stored row landed and drops the removed nodes from the graph with remap_graph_batch. If a level-0 walk from the entry point then misses any survivor, the graph is repaired with remap_graph_repair instead. 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.
    • Drops are detected against the stored partition size, not the graph's node count. HNSW graphs may legitimately cover only a prefix of their storage, and those still load unchanged.
    • New IvfSubIndex hooks: positional_rows and remap_positions, which are no-ops by default.
    • IvfQuantizationStorage::partition_row_positions maps each stored row to its loaded position.
  2. Physical remap repairs instead of rebuilding. remap_hnsw_partition reads 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 calls remap_graph_repair once.

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.rs restores 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 ≈ rebuild in them.

5M rows × 128-d, 1024 partitions, S3 from c7i.4xlarge (us-west-2):

deleted state time to reach cold prewarm cold 1st query warm p50 recall@10
1% pre – 1.87 s 1.09 s 87 ms 0.908
1% auto 4.5 s (compaction) 4.84 s 0.92 s 58 ms 0.904
1% rebuild 131 s 2.85 s 0.72 s 54 ms 0.904
10% pre – 1.76 s 0.73 s 77 ms 0.920
10% auto 3.8 s (compaction) 4.70 s 0.69 s 43 ms 0.912
10% rebuild 118 s 2.65 s 0.66 s 51 ms 0.902
  • Auto-remap makes the index servable seconds after compaction instead of after a roughly 2-minute remap or rebuild.
  • Its cost is a one-time cold load, about 2.6× slower, plus about 0.5 points of recall from dropping edges. Warm query latency is unchanged. (These runs predate the connectivity-gated repair; see the local table below for its cost.)
  • The extra cold-load time most likely comes from two extra reads per partition: the row-id column and the full graph with its distance column. Removing them is a possible follow-up.

Local 1M rows × 128-d, 256 partitions, after fix (2): physical remap logs zero rebuild fallbacks.

deleted repair (phys) rebuild
1% 4.8 s 8.2 s
10% 7.0 s 7.2 s
30% 5.4 s 5.6 s

Local 1M rows, cold prewarm of the auto state as load-time realignment evolved (pre ≈ 20 ms):

deleted drop edges only always repair repair only if stranded (this PR) recall (this PR / pre)
1% 152 ms 4.2 s 172 ms 0.936 / 0.936
10% 130 ms 6.4 s 213 ms 0.934 / 0.935
30% 137 ms 5.0 s 901 ms 0.936 / 0.942

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_deletions covers SQ/PQ × {load, prewarm} × {33%, 95% deleted}. The 95% cases strand survivors when edges are only dropped.
  • test_hnsw_prefix_graph_loads_without_dropped_rows loads a graph covering half its storage with no FRI.
  • remap.rs unit 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_graph asserts 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 --all is 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-existing nonminimal_bool and unreachable_code lints 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

  • Removing the data-plane gate that disables deferred remap for HNSW tables.

🤖 Generated with Claude Code

jzheng106 and others added 2 commits November 14, 2026 16:46
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]>

@claude claude 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer enhancement New feature or request labels Nov 16, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Nov 16, 2026
@jzheng106
jzheng106 requested a review from Xuanwo November 17, 2026 01:05
jzheng106 and others added 2 commits November 16, 2026 17:16
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]>
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 17, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Nov 17, 2026
…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]>
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 17, 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 remaining empty-partition finding is fixed. After deferred compaction, queries still return surviving rows, and prewarm and physical remap both accept a fully deleted partition.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 17, 2026
@jzheng106
jzheng106 requested a review from westonpace November 19, 2026 19:22

@westonpace westonpace left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@westonpace
westonpace merged commit 738aa65 into lance-format:main Nov 23, 2026
43 checks passed
wkalt pushed a commit that referenced this pull request Nov 24, 2026
## 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.
Xuanwo pushed a commit that referenced this pull request Nov 30, 2026
# 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.
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 enhancement New feature or request K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants