[python] Share raw vector scans across batch queries - #9753
Merged
JingsongLi merged 3 commits intoSep 13, 2026
Conversation
TheR1sing3un
marked this pull request as ready for review
September 12, 2026 06:48
JingsongLi
requested changes
Sep 12, 2026
JingsongLi
left a comment
Contributor
There was a problem hiding this comment.
Reviewed c718d0b. Requirement fit: supported; one performance regression needs attention.
Sharing the raw scan across queries removes real repeated work, and the focused tests passed (82 tests). The new streaming path, however, serializes split I/O that the previous path ran concurrently; the existing benchmark fixes read.parallelism to 1 and therefore cannot reveal this regression.
TheR1sing3un
force-pushed
the
codex/batch-vector-shared-raw-scan
branch
from
September 13, 2026 01:15
c718d0b to
9a23e2d
Compare
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.
Purpose
Batch vector search reads and converts the same uncovered rows once per query. Share a snapshot-pinned raw scan across the query batch, consume Arrow batches incrementally, and maintain a separate Top-K heap for each query.
Preserve the existing split-read parallelism, including the
read.parallelismtable option and automatic worker count. Each worker streams its assigned splits, scores all queries, and retains bounded Top-K state. Merge the worker results with the same score and row-ID tie-breaking rules. Close source iterators on success or failure and wait for running workers before propagating an error.Scoring buffers scale with the worker count: at most one Arrow batch and its converted vectors plus Q Top-K heaps per worker. There is no full-shard table or Q-by-N score matrix in this fallback. Storage decoder buffers and scan metadata remain separate costs.
Tests
python -m pytest pypaimon/tests/batch_vector_raw_scan_test.py pypaimon/tests/vector_search_filter_test.py -q: 85 passed.execute_batch_local(): one/two queries, L2/cosine/inner product, parallelism 1/2/4/automatic, identical scores and IDs versus individual searches, and one scan of every split. Synchronization barriers verify concurrency without timing thresholds.git diff --checkpassed.Benchmark and ablation
The experiment calls the public
execute_batch_local()API on real local Paimon/Parquet tables with no vector index andvector-index.search-mode=full.repeated: reproduces the previous per-query raw scan loop.shared-table: scans once but materializes the full table/Python lists, isolating the shared-scan benefit.shared-stream: this change, sharing the scan and consuming one batch at a time.All three use identical scalar distance and top-k helpers. Float32 vectors, 128 dimensions, L2, top-k 10, batch size 1,024, read parallelism 1. Each configuration runs three times in fresh processes, sequentially with shuffled configuration order. Timing includes planning, reading, conversion, scoring and merging; excludes data generation/process startup. RSS is total process peak including imports and Arrow buffers. Environment: macOS 26.4.1 arm64, Python 3.9.6, PyArrow 19.0.1, NumPy 2.0.2; OMP/OPENBLAS thread counts 1. Filesystem cache is not flushed.
The 8-query cases improve 2.35–2.36x; 32 queries improve 2.71x. The shared-table ablation shows that shared scanning accounts for the timing improvement, while streaming lowers peak RSS. For 65,536 rows and 8 queries, peak RSS falls from 581.0 to 192.9 MiB (66.8%). Single-query timing is similar.
Batch-size sensitivity at 16,384 rows / 8 queries:
All 42 runs produce exactly matching row IDs and floating-point scores within each dataset/query-count group, including across batch sizes. Instrumentation verifies Q raw plans/reader passes and N×Q delivered rows for
repeated, versus one plan/pass and N delivered rows for both shared modes. These are logical reader counters, not physical disk reads.These measurements fix read parallelism to 1, isolating scan sharing and streaming memory. The revised implementation also preserves split concurrency; that validation is reported separately below.
Split concurrency experiment
A local four-partition Parquet table with 20 two-dimensional rows, L2, Top-K 2 and batch size 2. Inject 150 ms at each split-reader open. Timing covers the public batch API after data preparation and a warm-up query. Each configuration runs three times in fresh Python 3.9 processes on macOS arm64; values below are medians. This isolates split-open latency and is not a live object-store throughput measurement.
All 24 runs return exactly identical IDs and scores for the same query set. Single-query latency returns to the original parallel-read level; two queries reuse the same four split reads.