perf(knn): share candidate reads for batched refinement - #9353
Open
TheR1sing3un wants to merge 1 commit into
Open
TheR1sing3un wants to merge 1 commit into
TheR1sing3un wants to merge 1 commit into
Conversation
TheR1sing3un
marked this pull request as ready for review
September 17, 2026 15:29
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The dedicated refinement stage keeps each query's candidate set isolated while sharing original-vector reads, and it preserves the established batch-IVF fallbacks for adaptive probes, HNSW, incomplete coverage, stale overlays, and external masks. Keeping refinement above the index layer avoids coupling dataset reads into the IVF implementation while retaining repeated-single-query semantics.
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.
Batched ANN queries with
refine_factorcurrently execute a separate search and vector take for each query. This shares the IVF search, deduplicates candidate vector reads, and computes a separate top-k over each query's original candidates. The existing query API and file format are unchanged.The fast path uses fixed positive
nprobeswith supported flat-style IVF indices. Adaptive probes, HNSW, incomplete index coverage, stale vector overlays, and external row masks retain per-query execution. Vector reads and scoring gathers target 32 MiB chunks; candidate metadata and top-k heaps use additional memory. Metrics expose vectors read, read batches, and peak vector buffer bytes.Performance
Apple M5 Pro, local disk,
release-with-debug; 32,768 synthetic 1,024-dimensional Float32 vectors across eight fragments, IVF_SQ/L2, 64 partitions, nprobes=16, k=10, refine_factor=10. Warm index cache and OS cache, 21 randomized/interleaved repetitions. Median complete-batch latency:At B=64, nearby queries read 136 distinct vectors for 6,400 candidate references; independent queries read 5,813. The nearby workload is 2.02x faster than eight concurrent singles; independent queries show little benefit and B=8 is about 18% slower. An initial 11-repeat run reproduced the same pattern (1.89x nearby, approximately equal independent at B=64). These compare query execution modes on the same build, not before/after native batch implementations. They are not remote-storage or cold-device measurements.
Validation
uv run --no-sync python python/benchmarks/batch_refinement.py --directory /tmp/native-batch-refinement --output /tmp/native-batch-refinement/results.json --repeats 21after building withrelease-with-debug.