Repository navigation
Conversation
Register IVF_HNSW_RQ as a recognized vector IndexType (enum value 108, parsing, display, is_vector, version, details matching) and add VectorIndexParams::with_ivf_hnsw_rq_params so [Ivf, Hnsw, RQ] stages map to IndexType::IvfHnswRq. Building such an index is not implemented yet. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Accept IVF_HNSW_RQ in create_index dispatch and build_vector_index_impl, building IvfIndexBuilder::<HNSW, RabitQuantizer>. HNSW graph construction still hits RabitQuantizationStorage::dist_calculator_from_id, which is unimplemented. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Implement RabitQuantizationStorage::dist_calculator_from_id by staging the partition's rows once and scoring a stored row against the others with the existing RQ pairwise kernel, so HNSW graph construction over RQ codes works for l2 and cosine. Dot is rejected up front. Expose IVF_HNSW_RQ through the Python bindings. Searching the index and append_batch are not implemented yet. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Open IVF_HNSW_RQ as IVFIndex<HNSW, RabitQuantizer> and map the (Hnsw, Rabit) sub-index and quantization pair to IndexType::IvfHnswRq. Add a recall test against brute-force search. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Look up staged RQ columns without cloning the schema Arc, which made multi-threaded HNSW builds contend on one refcount, and override dist_between and prefers_candidate on RabitQuantizationStorage so the kernel is bound once per call instead of once per candidate. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Give IVF_HNSW_RQ index version 3 so readers released before the type, which accept vector versions up to 2, skip it and fall back to a flat scan instead of failing nearest-neighbor queries. Stage RQ rows inside OnceLock::get_or_init so concurrent first callers during parallel HNSW insertion wait for one staging pass instead of each staging the whole partition. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Looking at the benchmark numbers here, scoring the full multi-bit RQ code on every hop along the graph walk gives throughput pretty close to plain Since every multi-bit RQ code already embeds 1-bit sign bits, we can walk the HNSW graph on a fast 1-bit estimate ( I implemented this 1-bit walk + multi-bit rerank search in #10522 (also using |
This was referenced Nov 5, 2026
Collaborator
Author
Xuanwo
added a commit
that referenced
this pull request
Nov 17, 2026
…full multi-bit (#10910) ## Summary `IVF_HNSW_RQ` landed in #10522 with one way to score HNSW nodes: walk the graph with the 1-bit sign codes, then rerank the `ef` finalists with the full multi-bit codes. #10648 implemented the same index but scored every visited node with the full multi-bit RQ estimator. This PR combines the two: both scoring paths are kept, behind a new query-time option, and the full multi-bit path is the default. - `RqGraphScoring::MultiBit` (default): every visited node is scored with the full multi-bit RQ estimator. No rerank step. This is the scoring from #10648. - `RqGraphScoring::OneBitRerank`: the 1-bit walk plus multi-bit rerank from #10522. Graph build is unchanged. Both PRs build the graph with the existing `RQPairScorer`, and this PR keeps the build path from #10522. ## Why multi-bit is the default The 1-bit walk is faster per node, but its coarser scores can steer the beam away from true neighbors, so it needs a larger `ef` to reach the same recall. Scoring with the full codes gets more recall out of each `ef`. Users who want the faster walk can opt in for each query. ## API - Rust: `lance_index::vector::RqGraphScoring`, a `Query::rq_graph_scoring` field, and `Scanner::rq_graph_scoring(...)`. - Python: `nearest={..., "rq_graph_scoring": "multi_bit" | "one_bit_rerank"}`. It is also a keyword argument on `ScannerBuilder.nearest` and `VectorSearchQuery`. Rust validates the value; an unknown value raises `ValueError`. - `ann.proto`: `VectorQueryProto.rq_graph_scoring = 17`, so distributed plans carry the setting. `MultiBit = 0`, so a producer that doesn't set the field gets the default. This is an execution wire schema, not a persisted format. - Other index types ignore the option. ## Implementation - `HnswQueryParams` carries `rq_graph_scoring`. In `MultiBit` mode the HNSW search uses `VectorStore::dist_calculator`, searches with `k`, and skips `VectorStore::rerank`, which is the search path from before #10522. In `OneBitRerank` mode it uses `graph_dist_calculator` and keeps `ef` candidates for `rerank`, as #10522 does. - Range bounds stay correct in both modes. With no walk, `in_range` falls back to the plain bound check on the exact multi-bit score. - Merging current `main` needed only mechanical propagation: the new field is set to the default at the `Query` and `HnswQueryParams` literals that `main` added, and `QuantizedRefinementKey` now binds `rq_graph_scoring` so a cached quantized refinement is not shared across scoring modes. ## Benchmarks IVF vs. IVF-HNSW, from #10648. This chart does not isolate the two graph-scoring modes, so it doesn't measure the latency cost of changing the default from the 1-bit walk to multi-bit scoring. The two modes were also measured against each other on one index: the first 100,000 base vectors and 1,000 queries of SIFT1M (128-d, L2, recall against an exact oracle on the same subset), one `IVF_HNSW_RQ` built once with one partition, 5-bit RQ, `k=10`, `release-with-debug`, single-threaded, aggregating 3 paired repeats at `ef=256` and 2 at `ef=512` on `4b65729c`. Later commits only merge `main` and adjust a test expectation. | Scoring | `ef` | recall@10 | mean µs | p95 µs | |---|---:|---:|---:|---:| | `MultiBit` (default) | 256 | 0.9343 | 695.5 | 796.0 | | `OneBitRerank` | 256 | 0.9087 | 622.6 | 678.1 | | `MultiBit` | 512 | 0.9343 | 831.8 | 935.2 | | `OneBitRerank` | 512 | 0.9280 | 744.9 | 811.3 | At `ef=256` the 1-bit walk is about 10% faster and 2.6 points lower in recall. Raising it to `ef=512` does not reach `MultiBit` at `ef=256` (0.9280 vs 0.9343) and is slower (744.9 vs 695.5 µs), so these two points support keeping the multi-bit default; they do not establish a recall ceiling or a matched-recall crossover. The single partition isolates the graph-scoring path and is not a claim about multi-partition production workloads. <img width="3900" height="780" alt="image" src="https://github.com/user-attachments/assets/29461b95-f9e1-416a-bad2-ea3ce7b7e25f" /> ## Breaking changes - `lance_index::vector::Query`, `lance_index::vector::hnsw::builder::HnswQueryParams`, and `lance::pb::VectorQueryProto` gain a `rq_graph_scoring` field. Rust callers that build these with struct literals must set it (`Default::default()` keeps the new default). - Existing `IVF_HNSW_RQ` queries now default to multi-bit scoring on every visited node, which may be slower than the 1-bit walk released in #10522. Rust and Python callers can keep the old behavior with `rq_graph_scoring="one_bit_rerank"`. Java only gets the default for now. ## Trade-offs / follow-ups - Loaded HNSW-RQ partitions still unpack the sign words (`dim / 8` bytes/row) at load time, as on `main`, so either mode can be picked per query. A follow-up could skip that work for deployments that never use `OneBitRerank`. - The Java binding does not expose the option yet. Java callers get the default. ## Testing - `test_rq_graph_scoring_selects_search_calculator`: each mode scores nodes with the expected calculator, and the two calculators disagree. - `test_hnsw_range_bounds_apply_to_reranked_distance` now runs in both modes. - `assert_ivf_hnsw_rq_search` (used by the stable-row-id lifecycle test) checks index use and recall >= 0.8 in both modes, before and after append/optimize/reopen. - ANN proto round trip, including rejection of an unknown `rq_graph_scoring` value. Scanner setter test. - Python: `test_ivf_hnsw_rq_graph_scoring` (recall >= 0.5 in both modes) and `test_vector_index_invalid_rq_graph_scoring`. - `test_nearest_preserves_existing_positional_arguments` expects the new option at the end of the `ScannerBuilder.nearest` signature, which keeps the existing positional arguments binding. - Local lint: `cargo fmt`, workspace clippy (also `lance --features substrait` and `lance-jni`), and `uv run make lint` pass. Locally, clippy 1.96 flags a `nonminimal_bool` in `lance-encoding/src/compression.rs`, which this PR does not touch, so I allowed that lint for the local runs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Xuanwo <[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.
Summary
Adds
IVF_HNSW_RQ: an IVF index whose partitions are HNSW graphs built over RabitQ (RQ) codes.It covers index build and search. Dynamic maintenance (append, optimize, remap) is not in this
PR and will follow.
What changed
IndexType::IvfHnswRq(value 108,"IVF_HNSW_RQ").VectorIndexParams::with_ivf_hnsw_rq_params;[Ivf, Hnsw, RQ]stages map to the type.create_indexdispatch buildsIvfIndexBuilder::<HNSW, RabitQuantizer>.IVF_HNSW_RQ.RQ storage could not do (
dist_calculator_from_idwasunimplemented!).RabitQuantizationStoragenow stages its rows once, on first use, and scores a stored rowagainst the others with the existing
RQPairScorerkernel inbq/pairwise.rs(exact integer code products, popcount for 1 bit, integer dots for 2-9 bits). No new math.
RabitDistCalculatorgets an "anchored on a stored row" mode instead of a new calculatortype, so the existing query-path callers are untouched.
dist_betweenandprefers_candidateare overridden to bind the kernel once per call.IVF_HNSW_RQarm inindex/loading.rsand mapped(Hnsw, Rabit) to
IvfHnswRqinvector_index_typeandIVFIndex::index_type.RecordBatch::column_by_name, which clonesthe schema
Arc. With ~16 threads sharing one storage, that refcount contention dominatedthe build (about 66% of busy samples). It now uses
schema_ref().index_of; this also helpsthe duplicate-pair scorer, which shares the helper.
Scope and limitations
creation with an error, because the pairwise scorer needs the partition centroid for dot.
append_batch(stillunimplemented!), optimize/remap of existingIVF_HNSW_RQ segments, distributed builds, and the Java and namespace bindings.
memory cost during HNSW build for large partitions.
dist_calculator_from_idand the other trait methods cannot return errors, so stagingfailures
expect. Staging fails only for non-L2 or old-format storage, which creationrejects first.
Testing
dist_calculator_from_id,distance_all,dist_betweenandprefers_candidateagainst an independent decode of the codes, for 1, 2, 5 and 9 bits.test_create_ivf_hnsw_rq_index: builds for L2 and cosine, rejects dot.test_ivf_hnsw_rq_search_recall: top-10 recall vs brute force on an L2 index, asserted atleast 0.5 (0.925 locally).
IndexTypeconversion tests.(no
uvat the time); CI will be the first run. Clippy was not run locally because of anexisting lint in
lance-encoding.Benchmarks
Review pointers
rust/lance-index/src/vector/bq/storage.rs: staging, anchored calculator, the two overrides.rust/lance-index/src/vector/pairwise.rs: the column-lookup change.rust/lance/src/index/vector.rs: dispatch, the dot guard and the new tests.BREAKING CHANGE