Repository navigation
feat(index)!: select IVF_HNSW_RQ graph scoring per query, default to full multi-bit - #10910
Conversation
…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]>
|
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 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? |
…-combined-scoring
|
Thanks, I prototyped this. Once the 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, Is the bound valid for multi-bit scores? Not as IVF_RQ uses it. Over 1.4M (query, row) pairs:
With the 1x bound, 0–8.6% of queries return different results than MultiBit, depending on 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):
The walk column comes from a separate run, where MultiBit measured 15.8 / 41.8 / 125.1 / 221.0 µs at these 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, |
…fault-performance-20261117 # Conflicts: # python/python/lance/_dataset/scanner.py
…fault-performance-20261117
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.
There was a problem hiding this comment.
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.
## 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.
Summary
IVF_HNSW_RQlanded in #10522 with one way to score HNSW nodes: walk the graph with the 1-bit sign codes, then rerank theeffinalists 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 feat(index)!: add IVF-HNSW-RQ (build and search) #10648.RqGraphScoring::OneBitRerank: the 1-bit walk plus multi-bit rerank from feat(index)!: add IVF_HNSW_RQ vector index #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
efto reach the same recall. Scoring with the full codes gets more recall out of eachef. Users who want the faster walk can opt in for each query.API
lance_index::vector::RqGraphScoring, aQuery::rq_graph_scoringfield, andScanner::rq_graph_scoring(...).nearest={..., "rq_graph_scoring": "multi_bit" | "one_bit_rerank"}. It is also a keyword argument onScannerBuilder.nearestandVectorSearchQuery. Rust validates the value; an unknown value raisesValueError.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.Implementation
HnswQueryParamscarriesrq_graph_scoring. InMultiBitmode the HNSW search usesVectorStore::dist_calculator, searches withk, and skipsVectorStore::rerank, which is the search path from before feat(index)!: add IVF_HNSW_RQ vector index #10522. InOneBitRerankmode it usesgraph_dist_calculatorand keepsefcandidates forrerank, as feat(index)!: add IVF_HNSW_RQ vector index #10522 does.in_rangefalls back to the plain bound check on the exact multi-bit score.mainneeded only mechanical propagation: the new field is set to the default at theQueryandHnswQueryParamsliterals thatmainadded, andQuantizedRefinementKeynow bindsrq_graph_scoringso 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_RQbuilt once with one partition, 5-bit RQ,k=10,release-with-debug,single-threaded, aggregating 3 paired repeats at
ef=256and 2 atef=512on4b65729c. Later commits only mergemainand adjust atest expectation.
efMultiBit(default)OneBitRerankMultiBitOneBitRerankAt
ef=256the 1-bit walk is about 10% faster and 2.6 points lower in recall. Raising it toef=512does not reach
MultiBitatef=256(0.9280 vs 0.9343) and is slower (744.9 vs 695.5 µs), so thesetwo 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.
Breaking changes
lance_index::vector::Query,lance_index::vector::hnsw::builder::HnswQueryParams, andlance::pb::VectorQueryProtogain arq_graph_scoringfield. Rust callers that build these with struct literals must set it (Default::default()keeps the new default).IVF_HNSW_RQqueries 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 withrq_graph_scoring="one_bit_rerank". Java only gets the default for now.Trade-offs / follow-ups
dim / 8bytes/row) at load time, as onmain, so either mode can be picked per query. A follow-up could skip that work for deployments that never useOneBitRerank.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_distancenow 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.rq_graph_scoringvalue. Scanner setter test.test_ivf_hnsw_rq_graph_scoring(recall >= 0.5 in both modes) andtest_vector_index_invalid_rq_graph_scoring.test_nearest_preserves_existing_positional_argumentsexpects the new option at the end of theScannerBuilder.nearestsignature, which keeps the existing positional arguments binding.cargo fmt, workspace clippy (alsolance --features substraitandlance-jni), anduv run make lintpass. Locally, clippy 1.96 flags anonminimal_boolinlance-encoding/src/compression.rs, which this PR does not touch, so I allowed that lint for the local runs.🤖 Generated with Claude Code