Repository navigation
perf(index): skip the write-only distance column when loading HNSW partitions - #8136
Merged
Xuanwo merged 1 commit intoAug 1, 2026
Conversation
wombatu-kun
force-pushed
the
perf/hnsw-skip-distance-column-on-load
branch
from
August 1, 2026 13:55
ba7db9d to
2d73147
Compare
Contributor
There was a problem hiding this comment.
Gate recommendation: approve. The read projection removes unused HNSW graph I/O at the right boundary while preserving the three-column persistent format for older readers. It resolves names against the actual file schema and version, leaves other sub-indexes on full reads, and covers projected/full equality, reduced bytes, delta-merge writes, and serialized-cache restart/query behavior.
Xuanwo
pushed a commit
that referenced
this pull request
Nov 30, 2026
…m test (#11629) Closes #6745. ## Summary Most of #6745 had already been done by earlier PRs. This PR adds no new codec or serialization logic. It only extends test coverage to the two IVF+HNSW variants that weren't tested yet. The issue asked for two things. Both were already on `main`: 1. **Zero-copy Arrow IPC serde for HNSW cache entries.** HNSW partitions go through the generic IVF `PartitionEntry<S, Q>` codecs in `rust/lance/src/index/vector/ivf/partition_serde.rs`. Those write the sub-index with `write_ipc(index.to_batch())` and read it back through `HNSW::load`. Since #6798, `HNSW::load` keeps the Arrow batch and serves neighbor lists zero-copy (`LoadedHnswGraph`). `to_batch()` hands that batch back unchanged, so a loaded graph round-trips through the cache without being rebuilt. 2. **A test showing that, after prewarm, a serializing backend serves HNSW queries with no IO.** `test_prewarm_and_query_with_serializing_backend` prewarms through `SerializingCacheBackend`, restarts the backend so only serialized entries survive, queries, checks recall, and asserts `read_iops == 0`. It already covered IVF_HNSW_SQ and IVF_HNSW_RQ. Earlier PRs that did the work: - #6090: prewarm for IVF indices and the no-IO assertion - #6223: `CacheCodec` and the IVF partition codecs, which are generic over the sub-index - #6798: zero-copy HNSW loading - #8136: the IVF_HNSW_SQ case - #10522: the IVF_HNSW_RQ case ## Changes Adds `ivf_hnsw_pq` (`PartitionEntry<HNSW, ProductQuantizer>`) and `ivf_hnsw_flat` (`PartitionEntry<HNSW, FlatQuantizer>`) cases to `test_prewarm_and_query_with_serializing_backend`. Every IVF+HNSW variant is now covered by the prewarm, restart and no-IO check. ## Testing - `cargo test --profile ci -p lance --lib test_prewarm_and_query_with_serializing_backend`: all 5 cases pass (`ivf_pq`, `ivf_hnsw_sq`, `ivf_hnsw_rq`, and the new `ivf_hnsw_pq` and `ivf_hnsw_flat`) in 1.55s. - `cargo fmt --all -- --check`: clean. - `cargo clippy --profile ci -p lance --tests --benches -- -D warnings`: clean. Clippy was run on the touched crate only, not with `--all`. --- _Generated by [Claude Code](https://claude.ai/code)_ Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #8135
Summary
HNSW index partitions no longer fetch the
_distancecolumn from storage.IvfSubIndexgains an optionalread_columns()projection naming the columnsloadactually consumes;HNSWdeclares__vector_idand__neighbors, andload_partition_entryreads throughFileReader::read_stream_projectedwhen a sub-index declares one.This is the second half of #6798. That PR stopped materializing
_distancein memory but left it being fetched from storage, because changing the on-disk schema was out of scope for a load-path performance fix.Why a read projection and not a schema change
Dropping the column from
to_batch()would break forward compatibility: readers older than v8.0.0 access it asbatch[DIST_COL], a panicking indexer rather than anOption. Gating that behind an index version bump would silently disable the index for every older reader and send those queries to a full scan. A read projection has no such cost: the file still carries the column, readers of every version keep working, and no index version is bumped. Removing it from the format stays available as a separate, versioned change later.Results
All figures are bytes fetched from storage, measured with
ObjectStore::io_stats_incrementaland summed over every partition. Both projections are exercised against the same row ranges in one binary, so nothing is confounded by build layout, and the projected read is taken first so it pays any first-touch cost rather than benefiting from it.End-to-end, one cold partition load.
IVF_HNSW_SQ, 100,000 rows at dim 768,nlist = 2,m = 20. This is the number that matters in practice: it includes the auxiliary quantized storage the load also has to fetch.The graph read itself drops 16,882,542 -> 6,329,144, a 62.5% cut. It is 18.0% of the partition at this dimension, which is where the 11.2% comes from.
That 62.5% is stable across configurations: an index over 500,000 rows at dim 32 with
nlist = 4(525,902 graph rows, ~131k nodes per partition) gives 102,548,810 -> 38,706,238, or 62.3%, and 50,000 rows gives 66.7%. The saving is a property of the graph encoding, not of one benchmark: neighbor ids bitpack against the partition's node count while f32 distances do not compress, so the column nothing reads is also the one that stays wide.What does vary is how much of a partition the graph accounts for, because graph cost per vector depends on
mand the id bit-width while quantized storage scales with dimension. At dim 768 storage is 770 B/vector against 169 B/vector of graph, giving the 18.0% share above; at low dimensions the graph dominates and the end-to-end saving approaches the 62% figure. So 11.2% is the conservative end of the range, not the typical one. The same bytes also stop occupyingLanceCache.Tests
All in
rust/lance/src/index/vector/ivf/v2.rs. The first three fail without the change.test_hnsw_partition_load_reads_only_graph_columns- the written index file still declares all three columns while every loaded partition carries only two, re-checked after an append plus a delta merge.test_hnsw_projected_read_matches_full_read- the two surviving columns are identical to the same columns of a full-schema read, per partition.__neighbors.itemand_distance.itemare both 4-byteListchildren nameditem, so a mis-mapped column index would reinterpret distances as neighbor ids with no type error to catch it.test_hnsw_read_projection_moves_fewer_bytes- the declared projection moves strictly fewer bytes than the full read over a real partition range, measured withio_stats_incremental. The projected read is taken first so it pays any first-touch cost.test_prewarm_and_query_with_serializing_backend- extended with anIVF_HNSW_SQcase alongside the existing IVF_PQ one, so the narrowed batch round-trips through cache serialization, reloads, and still meets the recall bar with no extra I/O.