Skip to content

feat(index)!: select IVF_HNSW_RQ graph scoring per query, default to full multi-bit - #10910

Merged
Xuanwo merged 7 commits into
lance-format:mainfrom
jzheng106:jason/hnsw-rq-combined-scoring
Nov 17, 2026
Merged

Xuanwo merged 7 commits into
lance-format:mainfrom
jzheng106:jason/hnsw-rq-combined-scoring

Conversation

@jzheng106

@jzheng106 jzheng106 commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

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.

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 feat(index)!: add IVF_HNSW_RQ vector index #10522. In OneBitRerank mode it uses graph_dist_calculator and keeps ef candidates for rerank, as feat(index)!: add IVF_HNSW_RQ vector index #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.

image

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 feat(index)!: add IVF_HNSW_RQ vector index #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

…ull multi-bit

IVF_HNSW_RQ search walked the graph with 1-bit sign codes and reranked
the ef finalists with the full codes. Add RqGraphScoring so a query can
pick that path (OneBitRerank) or score every visited node with the full
multi-bit RQ estimator (MultiBit, the new default), which recalls more at
a given ef.

The option is carried on Query, Scanner::rq_graph_scoring, the ANN exec
proto (field 17) and the Python nearest dict. Other index types ignore it.

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-python Python bindings A-index Vector index, linalg, tokenizer A-java Java bindings + JNI enhancement New feature or request labels Nov 10, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 10, 2026
@jzheng106 jzheng106 changed the title feat(index): select IVF_HNSW_RQ graph scoring per query, default to full multi-bit feat(index)!: select IVF_HNSW_RQ graph scoring per query, default to full multi-bit Nov 10, 2026
@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. and removed K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 10, 2026

Copy link
Copy Markdown
Contributor

Could we reuse IVF_RQ's 1-bit lower-bound pruning here instead of exposing separate one-bit and multi-bit scoring modes?

Once the ef result heap is full, its worst distance gives us a pruning threshold. We could compute the 1-bit score and error bound first, skip extra-bit computation when the lower bound exceeds that threshold, and compute the full multi-bit distance only for survivors. Heap ordering and traversal would still use full multi-bit scores.

This might get us close to one-bit scoring performance while retaining multi-bit accuracy, without another query setting. Could we benchmark that approach and check that the bound remains valid for the multi-bit scores, including filtered/ACORN searches?

@lance-gatekeeper lance-gatekeeper Bot removed K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 12, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 12, 2026
@lance-gatekeeper lance-gatekeeper Bot removed K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 13, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 13, 2026
@jzheng106

Copy link
Copy Markdown
Collaborator Author

Thanks, I prototyped this. Once the ef heap is full, the search gets the heap's worst distance as a threshold. A node whose 1-bit lower bound is above it returns the bound and skips the extra-bit computation. Heap order and traversal use full multi-bit scores. The prototype is in a third mode, PrunedMultiBit, so it can be compared side by side.

Setup: SIFT, 100k rows, one partition, 1000 queries, k=10. Recall is against exact L2 with no refine, so the quantizer caps it near 0.41. Each figure is the best of 3 runs on an Apple M5 Pro, single-threaded, release-with-debug.

Is the bound valid for multi-bit scores? Not as IVF_RQ uses it. Over 1.4M (query, row) pairs:

bound % of pairs where bound > multi-bit score
IVF_RQ bound (1x error) 6.4%
2x error (what in_range uses for the walk) 0.10%
walk popcount ip + walk error, 1x 0.11%

With the 1x bound, 0–8.6% of queries return different results than MultiBit, depending on ef. With the 2x bound or the walk bound, results match MultiBit in all but a few queries, in plain, filtered (1/2 of rows) and ACORN (1/5) searches.

Speed: it doesn't help. The search reaches nodes through the graph, so most nodes it scores are already close to the threshold. The safe bounds reject only 6–8% of thresholded nodes in plain and filtered searches, and about 25% with ACORN. Every node pays for the bound check, so the pruned mode is slower than MultiBit everywhere:

4 bits, plain search (µs/query, recall@10):

ef MultiBit Pruned (2x table) Pruned (walk) OneBitRerank
10 14.7, 0.382 14.9, 0.382 18.4, 0.380 10.0, 0.126
40 35.8, 0.406 37.5, 0.406 48.6, 0.406 25.7, 0.264
160 105.3, 0.409 111.0, 0.409 146.0, 0.409 78.4, 0.357
320 185.4, 0.409 196.1, 0.409 260.1, 0.409 145.5, 0.380

The walk column comes from a separate run, where MultiBit measured 15.8 / 41.8 / 125.1 / 221.0 µs at these ef values.

At 8 bits, where the extra bits cost more, the pruned mode is still 1–19% slower. Going from 4 to 8 bits only moves MultiBit from about 61 to 65 µs at ef=80. So the extra-bit work isn't the bottleneck, and skipping it can't get close to the 1-bit walk's speed.

At matched recall, MultiBit wins over the walk anyway. MultiBit reaches 0.38 recall at ef=10 in about 15 µs. OneBitRerank needs ef=320 (about 145 µs) to reach the same recall. And MultiBit at ef≥40 already matches brute-force multi-bit RQ recall, which OneBitRerank never reaches in this sweep.

So I'd rather not replace the two modes with this hybrid. The prototype and benchmark harness (an ignored test, bench_hnsw_rq_pruning) are on a local branch; I can push them if you want to reproduce. These numbers also make a case for dropping OneBitRerank and keeping only multi-bit scoring, which removes the extra setting. Happy to do that if you agree, or to keep the option for workloads I haven't measured.

@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Nov 13, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 13, 2026
@jzheng106
jzheng106 requested a review from Xuanwo November 16, 2026 20:21
…fault-performance-20261117

# Conflicts:
#	python/python/lance/_dataset/scanner.py
The option is appended after warp_imputation_rank, so the tail of
ScannerBuilder.nearest now ends with it. Existing positional arguments keep
binding, which is what the assertion protects.
@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels 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 with a non-blocking risk.

The newer 5-bit SIFT comparison in the PR description supports keeping MultiBit as the default: at ef=256 it reports 0.9343 recall@10 in 695.5 µs, versus 0.9280 in 744.9 µs for OneBitRerank at ef=512. Those points do not establish a matched-recall crossover. Your pruning experiment reports added latency and possible result changes, supporting leaving the hybrid out of this PR.

I recommend retaining OneBitRerank as a fallback. The remaining non-blocking risk is latency at existing ef settings: MultiBit takes about 12% longer at the same ef in the newer 5-bit sample, and 27–47% longer in the earlier 4-bit sample, with higher recall. Rust/Python callers can tune ef or select the previous mode; Java currently exposes only the default. These author-reported measurements cover single-partition SIFT setups, so performance across other workloads remains unestablished.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 17, 2026
@Xuanwo
Xuanwo merged commit c63e915 into lance-format:main Nov 17, 2026
52 of 54 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.
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 A-java Java bindings + JNI A-python Python bindings breaking-change enhancement New feature or request K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants