Commit 27b1c2b
authored
feat(vector): add partition search parallelism (#6475)
## Feature
This PR adds query-time `query_parallelism` for vector search partition
execution and wires it through Rust, Python, and Java.
Callers can control how many IVF partitions a single query may search
concurrently:
- `0`: auto policy. The current implementation maps auto to the
single-worker sequential path.
- `1`: single-worker sequential partition search.
- `-1`: use the CPU pool size.
- `>= 2`: partition-parallel search, clamped to the CPU pool size.
The default is `0`, which currently preserves the optimized sequential
execution path.
## Performance Improvement
The performance issue is per-query worker fan-out. With many concurrent
queries, spawning a CPU task for every partition of every query
increases contention on the CPU worker pool and lengthens queueing time.
This is especially visible for fixed-`nprobes` IVF workloads where every
query searches the same number of partitions.
This PR improves that path by making query partition scheduling
configurable while keeping the optimized sequential model as the default
auto behavior. Sequential fixed-`nprobes` search prepares partitions
asynchronously, then searches prepared partitions on one CPU worker
using a query-level global top-k heap. Parallel execution remains
available for workloads that benefit from intra-query partition
parallelism.
## Implementation
- Rust, Python, and Java expose `query_parallelism` on vector search
APIs.
- `ANNIvfSubIndexExec` converts the configured value into an effective
partition concurrency.
- Effective partition concurrency is clamped to the CPU pool size.
- IVF v2 splits partition search into async prepare and sync execute
phases.
- Sequential fixed-`nprobes` search uses a query-level global top-k
heap.
- Sequential late-search keeps the existing per-partition output shape
so early-stop behavior is preserved.
- Parallel execution uses direct per-partition search tasks, matching
the original execution model.
- IVF_RQ/Flat sub-index search reuses caller-owned scratch buffers for
RQ distance-table quantization and top-k accumulation to reduce
allocation overhead.
## Developer Impact
- Rust callers can call `Scanner::query_parallelism(...)`.
- Python callers can pass `query_parallelism` in vector search APIs.
- Java callers can use `Query.Builder#setQueryParallelism(...)`.
- `parallel_mode` / `ParallelMode` have been replaced by the
concurrency-based API.
## Benchmark
GCP VM benchmark using the same index for all modes. All rows had
matching result checksums.
Configuration: `gist / IVF_RQ / target_partition_size=8192 / k=100 /
nprobes=20 / columns=[] / prewarm / max_queries=1000`. Percentages are
relative to `main`.
| Threads | Mode | Avg | P50 | P90 | P95 | P99 | QPS |
|---:|---|---:|---:|---:|---:|---:|---:|
| 8 | main | 4.98 ms | 4.92 ms | 6.28 ms | 6.86 ms | 7.56 ms | 1584.6 |
| 8 | sequential | 4.27 ms (-14.2%) | 4.21 ms (-14.5%) | 5.03 ms
(-19.9%) | 5.27 ms (-23.1%) | 5.97 ms (-21.0%) | 1838.9 (+16.1%) |
| 8 | parallel | 5.02 ms (+0.7%) | 4.97 ms (+0.9%) | 6.27 ms (-0.2%) |
6.60 ms (-3.7%) | 7.36 ms (-2.7%) | 1575.4 (-0.6%) |
| 16 | main | 9.95 ms | 9.74 ms | 13.12 ms | 14.11 ms | 16.83 ms |
1583.1 |
| 16 | sequential | 8.09 ms (-18.6%) | 7.98 ms (-18.0%) | 9.84 ms
(-25.0%) | 10.47 ms (-25.8%) | 11.67 ms (-30.6%) | 1936.8 (+22.3%) |
| 16 | parallel | 9.95 ms (+0.0%) | 9.68 ms (-0.6%) | 13.37 ms (+1.9%) |
14.42 ms (+2.2%) | 16.83 ms (+0.0%) | 1583.6 (+0.0%) |
| 32 | main | 18.68 ms | 18.16 ms | 26.66 ms | 28.77 ms | 33.12 ms |
1652.7 |
| 32 | sequential | 15.50 ms (-17.0%) | 15.15 ms (-16.6%) | 20.57 ms
(-22.9%) | 22.16 ms (-23.0%) | 25.32 ms (-23.6%) | 2000.6 (+21.1%) |
| 32 | parallel | 19.13 ms (+2.4%) | 18.58 ms (+2.3%) | 26.49 ms (-0.6%)
| 29.12 ms (+1.2%) | 33.92 ms (+2.4%) | 1625.9 (-1.6%) |
| 64 | main | 33.98 ms | 33.01 ms | 49.65 ms | 53.87 ms | 63.58 ms |
1718.4 |
| 64 | sequential | 29.95 ms (-11.8%) | 29.67 ms (-10.1%) | 42.44 ms
(-14.5%) | 46.81 ms (-13.1%) | 54.42 ms (-14.4%) | 1949.4 (+13.4%) |
| 64 | parallel | 35.17 ms (+3.5%) | 34.37 ms (+4.1%) | 50.70 ms (+2.1%)
| 55.04 ms (+2.2%) | 69.09 ms (+8.7%) | 1650.7 (-3.9%) |
| 128 | main | 38.73 ms | 36.07 ms | 68.28 ms | 76.78 ms | 96.81 ms |
1663.3 |
| 128 | sequential | 37.48 ms (-3.2%) | 35.90 ms (-0.5%) | 65.26 ms
(-4.4%) | 71.82 ms (-6.5%) | 87.48 ms (-9.6%) | 1915.3 (+15.2%) |
| 128 | parallel | 41.29 ms (+6.6%) | 39.38 ms (+9.2%) | 71.68 ms
(+5.0%) | 80.70 ms (+5.1%) | 96.20 ms (-0.6%) | 1577.2 (-5.2%) |
## Validation
- `cargo fmt --all --check`
- `cargo check -p lance --tests`
- `cd python && cargo check`
- `cd java && cargo check --manifest-path ./lance-jni/Cargo.toml`
- `uv run --with maturin maturin develop`
- `uv run pytest
python/tests/test_vector_index.py::test_vector_index_with_query_parallelism
python/tests/test_vector_index.py::test_vector_index_invalid_query_parallelism`
- Python ruff check / format check for touched Python files1 parent 8962655 commit 27b1c2b
22 files changed
Lines changed: 1989 additions & 168 deletions
File tree
- java
- lance-jni/src
- src
- main/java/org/lance/ipc
- test/java/org/lance
- protos
- python
- python
- lance
- tests
- src
- rust
- lance-index/src
- vector
- bq
- flat
- v3
- lance/src
- dataset
- tests
- index/vector
- ivf
- io/exec
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
323 | 328 | | |
324 | 329 | | |
325 | 330 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
210 | 213 | | |
211 | 214 | | |
212 | 215 | | |
| |||
221 | 224 | | |
222 | 225 | | |
223 | 226 | | |
| 227 | + | |
224 | 228 | | |
225 | 229 | | |
226 | 230 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| 54 | + | |
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| |||
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
95 | 101 | | |
96 | 102 | | |
97 | 103 | | |
| |||
104 | 110 | | |
105 | 111 | | |
106 | 112 | | |
| 113 | + | |
107 | 114 | | |
108 | 115 | | |
109 | 116 | | |
| |||
117 | 124 | | |
118 | 125 | | |
119 | 126 | | |
| 127 | + | |
120 | 128 | | |
121 | 129 | | |
122 | 130 | | |
| |||
245 | 253 | | |
246 | 254 | | |
247 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
248 | 274 | | |
249 | 275 | | |
250 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
5631 | 5632 | | |
5632 | 5633 | | |
5633 | 5634 | | |
| 5635 | + | |
5634 | 5636 | | |
5635 | 5637 | | |
| 5638 | + | |
| 5639 | + | |
| 5640 | + | |
| 5641 | + | |
| 5642 | + | |
| 5643 | + | |
| 5644 | + | |
| 5645 | + | |
| 5646 | + | |
| 5647 | + | |
| 5648 | + | |
| 5649 | + | |
5636 | 5650 | | |
5637 | 5651 | | |
5638 | 5652 | | |
| |||
5645 | 5659 | | |
5646 | 5660 | | |
5647 | 5661 | | |
| 5662 | + | |
5648 | 5663 | | |
5649 | 5664 | | |
5650 | 5665 | | |
| |||
6760 | 6775 | | |
6761 | 6776 | | |
6762 | 6777 | | |
| 6778 | + | |
6763 | 6779 | | |
6764 | 6780 | | |
6765 | 6781 | | |
| |||
6787 | 6803 | | |
6788 | 6804 | | |
6789 | 6805 | | |
| 6806 | + | |
| 6807 | + | |
| 6808 | + | |
| 6809 | + | |
| 6810 | + | |
| 6811 | + | |
6790 | 6812 | | |
6791 | 6813 | | |
6792 | 6814 | | |
| |||
6854 | 6876 | | |
6855 | 6877 | | |
6856 | 6878 | | |
| 6879 | + | |
| 6880 | + | |
| 6881 | + | |
| 6882 | + | |
| 6883 | + | |
6857 | 6884 | | |
6858 | 6885 | | |
6859 | 6886 | | |
| |||
6871 | 6898 | | |
6872 | 6899 | | |
6873 | 6900 | | |
| 6901 | + | |
6874 | 6902 | | |
6875 | 6903 | | |
6876 | 6904 | | |
| |||
7043 | 7071 | | |
7044 | 7072 | | |
7045 | 7073 | | |
| 7074 | + | |
7046 | 7075 | | |
7047 | 7076 | | |
7048 | 7077 | | |
| |||
7055 | 7084 | | |
7056 | 7085 | | |
7057 | 7086 | | |
| 7087 | + | |
7058 | 7088 | | |
7059 | 7089 | | |
7060 | 7090 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1864 | 1864 | | |
1865 | 1865 | | |
1866 | 1866 | | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
1867 | 1902 | | |
1868 | 1903 | | |
1869 | 1904 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
| 80 | + | |
| 81 | + | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| |||
1251 | 1251 | | |
1252 | 1252 | | |
1253 | 1253 | | |
| 1254 | + | |
1254 | 1255 | | |
1255 | 1256 | | |
1256 | 1257 | | |
| |||
1311 | 1312 | | |
1312 | 1313 | | |
1313 | 1314 | | |
| 1315 | + | |
1314 | 1316 | | |
1315 | 1317 | | |
1316 | 1318 | | |
| |||
4309 | 4311 | | |
4310 | 4312 | | |
4311 | 4313 | | |
| 4314 | + | |
4312 | 4315 | | |
4313 | 4316 | | |
| 4317 | + | |
| 4318 | + | |
| 4319 | + | |
| 4320 | + | |
| 4321 | + | |
| 4322 | + | |
| 4323 | + | |
| 4324 | + | |
| 4325 | + | |
| 4326 | + | |
| 4327 | + | |
| 4328 | + | |
| 4329 | + | |
| 4330 | + | |
| 4331 | + | |
| 4332 | + | |
| 4333 | + | |
| 4334 | + | |
| 4335 | + | |
4314 | 4336 | | |
4315 | 4337 | | |
4316 | 4338 | | |
| |||
4416 | 4438 | | |
4417 | 4439 | | |
4418 | 4440 | | |
| 4441 | + | |
| 4442 | + | |
4419 | 4443 | | |
4420 | 4444 | | |
4421 | 4445 | | |
| |||
4426 | 4450 | | |
4427 | 4451 | | |
4428 | 4452 | | |
| 4453 | + | |
4429 | 4454 | | |
4430 | 4455 | | |
4431 | 4456 | | |
| |||
4461 | 4486 | | |
4462 | 4487 | | |
4463 | 4488 | | |
| 4489 | + | |
4464 | 4490 | | |
4465 | 4491 | | |
4466 | 4492 | | |
| |||
4477 | 4503 | | |
4478 | 4504 | | |
4479 | 4505 | | |
| 4506 | + | |
4480 | 4507 | | |
4481 | 4508 | | |
4482 | 4509 | | |
| |||
0 commit comments