Repository navigation
perf(vector): support adaptive nprobes in shared-scan batch IVF search - #10443
Conversation
7ce2bcb to
b64f875
Compare
b64f875 to
d164ae6
Compare
d164ae6 to
57179cc
Compare
The shared-scan batch IVF node (`ANNIvfBatchExec`) required fixed probe bounds; adaptive requests fell back to one indexed search per query. It now applies the single-query adaptive rules per query while sharing partition loads across the batch: - rank each query and apply `AutoProbePolicy` (including `search_effort`) on the CPU runtime; - search every query's initial budget in one shared call per delta; - after all deltas finish, run late search in rounds with one virtual query per (query, partition), consumed in rank order and cut where a sequential search would stop; - admit whole queries per round, up to max(1024, compute CPUs) probes across all queries and deltas, so a query's rows do not depend on the rest of the batch; - release a query's ranking once it holds k candidates or has no late range; - apply segment ownership to early and late results and stopping budgets. Per-query candidates stay in the bounded `TopHits` heap. Explicit parallel adaptive probing, adaptive IVF_RQ, and exact refinement with adaptive bounds keep the per-query path. For batches on the shared path, `partitions_searched` counts shared partition loads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The adaptive batch KNN tests and their fixture helpers move unchanged from dataset_scanner_knn.rs into dataset_scanner_knn_adaptive.rs, keeping the original file below the module-size limit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rules - Skip late search for a delta whose own prefilter selects nothing and count it in `segments_skipped`, as the single-query path does since lance-format#10485. - Release a query's ranking once it holds every row the prefilter allows, not only once it holds `k` rows. - Share the stop budget, the fewer-than-k shortcut condition and the segment-ownership check between the single-query and batch paths. - Report which delta and query a short late-search result came from, turn the unreachable empty-round guard into a debug assertion, and size the output builders from the rows held. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`new_knn_batch_exec` and `ANNIvfBatchExec` move unchanged from knn.rs into knn/batch.rs and are re-exported from knn, so their public paths stay the same. Only imports and three intra-doc link paths change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
58725f2 to
a3dcaf8
Compare
|
@Xuanwo @wjones127 I rebased onto current |
The adaptive batch node consumes whatever prefilter source the scanner built, and lance-format#10001 added a producer after this branch's base: a scalar-index mask over the fragments it covers plus a row-ID read for the rest. Pin that boundary with an exact scalar predicate that reaches PrefilterUnionExec both through a fragment-scoped scan and through partial scalar coverage.
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The main merge preserves the probe-budget policy, adaptive stopping, and segment ownership and contract checks. The shared adaptive scan also consumes #10001’s hybrid scalar prefilters with explicit fragment scope and partial scalar coverage intact. Adaptive searches with IVF_RQ or exact refinement retain the per-query path.
The supplied low-overlap, multi-segment, and warm ABFS measurements continue to support sharing partition I/O across the batch.
Xuanwo
left a comment
There was a problem hiding this comment.
Approving the integration head 1b660f67b1881677fffd655898ca847f516a533f on top of main cd0a2489906d3f9725cfec40ff22561a53367363. The merge commit 2f63075ad37682e78a29a358cb1c9dbb53105d48 preserves the accepted change: 10 files, +2459/-564, with the ANNIvfBatchExec extraction, the shared adaptive probe planning, and the #10001 hybrid scalar prefilter regression unchanged from the reviewed source.
Gate state at this head: 44 of 45 check runs succeeded, and Arrow ordering compatibility was skipped by its own needs.arrow-ordering-detect.outputs.run == 'true' condition because the detect job found no ordering-relevant dependency or fixture changes, so it reports no regression either way. All 13 workflow runs succeeded, format-spec-vote is green, no review threads are open, and branch protection requires only a non-author approval with linear history, which squash provides. The gatekeeper review at this head recommends approval and requests no source change.
…rges (#11467) ## What - `guide/vector_search.md`: new **Batch Queries** section with Python (2-D `q`), Rust (list-array query) and Java (`Query.Builder.setKeys`) examples. It covers the `query_index` column, how `limit`/`offset` apply, and the cases that search each query separately. The list follows `batch_index_search_supported` in `dataset/scanner/vector.rs`. - `quickstart/vector-search.md`: the batch paragraph said adaptive probes use per-query execution. Since #10443 they share partition scans, except on IVF_RQ. The paragraph now points to the guide for the remaining cases. - `guide/distributed_indexing.md`: mergeable IVF-RQ segments need one shared rotation model (`rabitq_model` from `build_rq_model`, or `RQBuildParams.Builder.setModel` in Java); the merge error has named this since #11462. The section also adds the measured query cost of unmerged segments, from the #11462 benchmark. ## Validation - Python example run against a local build: `query_index` is the first column (int32, no nulls), 10 rows per query, and `limit=5` returns 5 rows in total. - Rust example compiled and run as a temporary example: `query_index` is the first column, 20 rows for 2 queries. - The Java example uses the same calls as the batch tests in `VectorSearchTest`. - `./clean-full-website.sh && uv run mkdocs build --strict` passes, and the `#batch-queries` link resolves. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
The shared-scan batch IVF node (
ANNIvfBatchExec, #7640) required fixed probe bounds (minimum_nprobes == maximum_nprobes). Adaptive requests, including the default bounds and any explicitsearch_effort, fell back to one indexed search per query. This PR applies the single-query adaptive rules inside the batch node for IVF_FLAT, IVF_PQ, and IVF_SQ. Partition loads stay shared across queries. There are no changes to the index trait, the public API, or the index format.#10480, now merged, scores each loaded chunk's queries on separate CPU tasks. Before it,
search_partitions_batchscored each chunk on a single CPU task, so routing adaptive bounds to the shared node showed up as a 3.3x slowdown on the existingquery_ann_batchbenchmark (768-d IVF_PQ,k = 100). The scanner changes are indataset/scanner/vector.rs.ANNIvfBatchExecnow lives inio/exec/knn/batch.rsand its adaptive tests indataset/tests/dataset_scanner_knn_adaptive.rs, so no module grows past the size check.This follows up the min/max-nprobes question from the #7640 review. It builds on the segment-ownership fix in #9638. With #9618, namespace
multi_vectorrequests that use adaptive bounds can now reach the shared path.Commits
perf(vector): support adaptive nprobes in shared-scan batch IVF searchis the change itself.test(vector): move adaptive batch KNN tests into their own filemoves tests without changing them.fix(vector): align batch late search with single-query skip and stop rulesadds the selects-nothing skip, the budget-based ranking release, and the late-search helpers shared with the single-query path.refactor(vector): move ANNIvfBatchExec into its own modulemoves code without changing it. Only imports and three intra-doc link paths change.Merge origin/main into perf/batch-ivf-adaptive-nprobesmergesmainatcd0a24899; it had no conflicts.test(vector): cover hybrid scalar prefilter in adaptive batch KNNadds the feat: add scoped hybrid scalar prefilters #10001 producer regression.Execution
AutoProbePolicy, includingsearch_effort. This is the same policy call the single-query path makes for each delta.kcandidates, holds every row the prefilter allows, or has no late range. Deltas with no remaining late work, including fixed, exhausted, and empty-ownership deltas, are released before the next delta is scanned. Retained deltas are checked again at the early-search barrier.max(1024, compute CPUs)probes across all queries and deltas. The first query rotates between rounds so none starves. A query's deltas therefore advance together, and its rows do not depend on the rest of the batch. A query whose own waves exceed the cap is clipped and resumes at the first delta it could not fully admit. Admitted deltas run concurrently, and their results are consumed round-robin.segments_skipped. The fewer-than-k shortcut returns only owned, unseen rows from eligible segments.LateSearchBudget,segment_owns_rowsinknn.rs), so the two paths cannot drift on when a query stops.query_parallelism > 1or-1) and for adaptive IVF_RQ. Neither is equivalent to the shared sequential path today. Parallel late search can admit partitions past the sequential cut. Multi-bit IVF_RQ prunes with a probabilistic lower bound, so batch and single-query search can drop different rows (IVF_RQ: probabilistic lower-bound pruning makes top-k results depend on k and differ between batch and single-query search #10778). Fixed-probe IVF_RQ keeps its existing shared path and shows the same intermittent difference onmain, independent of this PR.Memory
TopHitscollector from perf(knn): bound batched ANN candidate merge across segments #9688, so retained candidates areQ * k.TopHitsgains aniter()so the fewer-than-k shortcut can skip rows it already holds.B * dimfloats, and a round returns at mostB * krows, whereBis the round cap. With the default cap, a round of 1024-d queries copies at most 4 MiB of keys.kcandidates (or every row the prefilter allows) or has no late range, so an unfiltered batch does not keepQ * num_partitionsranking entries per delta after the delta's early scan. While a delta is being ranked, all of its queries' rankings are held at once.These bound the round scratch, not total execution memory. Ranked plans for genuine adaptive work, partition storage, and output have their own costs. Measured peak memory is under Peak memory and latency.
Behavioral scope
For a single delta, shared adaptive FLAT/PQ/SQ follows the same sequential probe ranges and stopping rules as single-query search. Equal-distance ties can select different valid rows. With multiple deltas, results are consumed in a deterministic round-robin order rather than by completion timing, so identical row sets are not promised. The multi-delta tests check progression, uniqueness, counts, and recall. A query's rows do not depend on the other queries in the batch unless its own waves exceed the round cap.
Batched exact refinement (#9353) covers fixed nprobes. Exact refinement with adaptive bounds keeps the per-query path, and
test_batch_knn_indexed_refine'sadaptivecase asserts that.Metric change: for adaptive batches that take the shared path,
partitions_searchedcounts the shared scan's partition loads, as the fixed-probe batch path already does, instead of summing each query's searches. This includes late-search partitions loaded in a wave past a query's cut. Identical queries in one batch therefore count a partition once. The Pythontest_vector_search_effortbatch assertion is updated to match. Adaptive IVF_RQ still reports the per-query sum.Tests
search_effortat 0, 0.25, 0.75, and 1, with and without a filter: rows and distances match single-query search. Forcing the batch planner to ignore effort fails 18 of the 24 cases.krows, so they exercise late search to exhaustion.kcandidates are released, including when a later delta completes the query. So are rankings of queries that hold every row the prefilter allows.LANCE_CPU_THREADS=1.segments_skippedas single-query search and returns the same rows. A unit test checks that such a delta does not join late search. Reverting the skip fails both.LateSearchBudgetandsegment_owns_rows: unit tests cover allow lists below, at, and abovek, empty masks, and masks that cannot count their rows (block lists, whole fragments).query_parallelism0 and 1 take the shared path, and their rows and distances match single-query search. Explicit parallel probing keeps the per-query path.test_batch_knn_indexed_refinestill requires exact refinement with adaptive bounds to take the per-query path.Validation
The integrated head merges
mainatcd0a24899(#10753) into the branch in2f63075ad. Git merged cleanly, and the result keeps #10001's hybrid scalar prefilter producer, #10721'slance_core::utils::tokiospawn boundary, and #10727's extractedpartition_searchscoring; no old inline implementation was restored.cargo test --profile ci -p lance --lib dataset_scanner_knn_adaptive::: 74 passed.cargo test --profile ci -p lance --lib dataset_scanner_knn::: 152 passed.cargo test --profile ci -p lance --lib io::exec::knn::: 1,219 passed, covering the batch, late-search, ownership, segment-contract, and budget units.cargo test --profile ci -p lance --lib dataset_scanner_segments::test_hybrid_prefilter_consumers: 12 passed, so feat: add scoped hybrid scalar prefilters #10001's ANN, batch, and FTS consumers keep their union prefilter.cargo test --profile ci -p lance --lib io::exec::prefilter_union::and--test integration_tests prefilter_union: 2 and 16 passed.cargo test --profile ci -p lance-index --lib -- minhash: 63 passed.cargo clippy --profile ci --all --tests --benches -- -D warningsandcargo fmt --all -- --check: clean.test_vector_index.py -k "search_effort or batch"against a native build of the integrated head: 68 passed.uv run make lintfrompython/: clean.The integration adds
test_batch_knn_adaptive_hybrid_scalar_prefilter, which reaches the adaptive batch scan through #10001'sPrefilterUnionExec. An exact B-tree predicate oni(i >= 250 AND i < 1750) covers both producer shapes: a scalar index over every fragment while the scan selects the middle two (scalar_fragments=2, evaluated_fragments=2), and a scalar index over two of four fragments (scalar_fragments=2, evaluated_fragments=4). Each case asserts that the union producer andANNIvfBatchare planned andANNSubIndexis not, that per-query rows and distances equal single-query search, that every returned row satisfies the predicate and stays inside the selected fragments, and a recall floor of 0.5 against the flat oracle.Author-reported validation before integration
Recorded against
58e62bd54, which includes #10695 (search-effort calibration by metric and k) and #10761 (segment contract checks), before this branch was merged withmain:cargo test -p lance --lib: 10,075 passed, 0 failed, 9 ignored.search_effort, range-splitting, and late-search budget tests withLANCE_CPU_THREADS=1andLANCE_IVF_STREAMING_SEARCH_BATCH_SIZE=1: 1,049 passed.cargo test -p lance-index --lib -- minhash: 63 passed.test_vector_index.py -k "search_effort or batch"on a freshmake build: 68 passed.cargo clippy --all --tests --benches -- -D warnings,cargo clippy -p lance --all-features --tests -- -D warnings,cargo fmt --all -- --check, andRUSTDOCFLAGS="-D warnings" cargo doc -p lance --no-deps: clean. On aarch64 macOS, clippy also needs-A unreachable_codefor the NEON byte-stream-split code already onmain.segments_skippedtest and the late-search unit test fail. With the ranking release reverted tok, the budget retention test fails.0db573921before the rebase, the full Python suite (pytest python/tests -n auto) passed 1,902 tests.Benchmark suite
Everything in this section and the next two is author-reported: it was measured on the author's hardware against the revisions named below and was not re-run on the integrated head.
python/python/benchmarks/test_search.pygains afixed(nprobes = 10) and anadaptive(default bounds) case for the twoquery_ann_batchbenchmarks. These are pylance release builds of this branch, measured before it was rebased onto0db573921, and ofmainat65df9b7c4, run on one Apple M5 Max. The dataset has 100k x 768-d vectors on local disk, IVF_PQ with 32 partitions,k = 100, and 32 queries. Values are pytest-benchmark medians in ms.maintest_batch_ann_search[clean-adaptive]test_batch_ann_search[clean-fixed]test_batch_ann_search[with_delete_files-adaptive]test_batch_ann_search[with_delete_files-fixed]test_batch_ann_search[with_new_rows-adaptive]test_batch_ann_search[with_new_rows-fixed]test_repeated_single_ann_search[clean-adaptive]test_repeated_single_ann_search[clean-fixed]with_new_rowshas unindexed fragments, so it keeps the per-query path. The repeated single-query cases do not use the changed code and serve as a noise reference. Without #10480,clean-adaptivetook 33.67 ms.Peak memory and latency
This is a release-build measurement of this branch, taken before it was rebased onto
0db573921, and ofmainat65df9b7c4. It is not checked in. The dataset is on local SSD: 500k x 16-d Float32 vectors, IVF_FLAT with 2,048 partitions, either as one index segment or as four (an initial index plus three appended deltas indexed withoptimize_indices). Queries are uniform random vectors drawn independently of the data, withk = 10and the default adaptive bounds. A batch of 256 queries has low partition overlap; 8,192 queries puts the per-query rankings at about 134 MB per segment.Each configuration runs in a fresh process. Peak growth is the process high-water RSS (
getrusageru_maxrss) after the query minus its value just before. Values are the median of 3 runs on one Apple M5 Max. Onmain, an adaptive batch runs one indexed search per query inside the same plan.main→ this PR)main→ this PR)i % 97 = 0i % 97 = 0i % 97 = 0i % 97 = 0Both builds return the same number of rows in every configuration. On
main, the baseline already includes planning the per-query searches, so its growth is understated. Object-store latency is measured separately below.Object-store latency
This measures release builds of
mainat56963cb29and of this PR at58725f2fe, through the Java binding on a Spark cluster in Azure: 8 executors with 4 cores each, data on Azure Data Lake Storage (ABFS). The dataset has 10M x 1024-d embeddings in 10 fragments, with one IVF_PQ segment: L2, 256 partitions, and 64 sub-vectors. Queries are dataset rows with 5% Gaussian noise,k = 10, and the JavaQuerysets no nprobes, so probing is adaptive from a minimum of 1 with no maximum. Each of 32 Spark tasks sends its share of the queries as one batch call (batch) or as one call per query (per-query). Values are the median wall time of 5 runs after a warmup, with the best run in parentheses, in ms. Each build ran in its own job on a shared cluster.mainbatchmain/ this PR)rid % 20000 = 0(500 rows)rid % 20000 = 0(500 rows)main.