Repository navigation
Conversation
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.
Summary
Addresses #218. Flat IVF batch search currently rereads every centroid for each query. This change shares centroid reads across query blocks using GEMM screening and a bounded top-nprobe heap, then recomputes retained candidates with the existing float distance kernels.
Adds C++ and Python regressions for centroid/query-block boundaries, duplicated centroids, L2/IP/cosine, zero-valued queries, 1/5/32-bit storage, both FastScan accuracy modes, removed points, oversized k/nprobe, optional distances, thread-setting preservation and save/load. Adds an IVF search benchmark driver and its usage documentation.
This PR contains only the batch-routing change; no FastScan kernel optimization is included.
Testing
Based on main
9121a79ae0f5e23d3c5f5aef2431e872b89afd92(0.9.0). Native Apple M5 Pro ARM64, AppleClang 17.0.0.17000604, Release-O3, NEON,RABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF, OpenMP enabled../scripts/check-format.sh: clang-format 23.1.5 passed../scripts/check-python.sh: Ruff 0.16.1 passed.git diff --checkpassed../scripts/check-tidy.sh build-wheel: clang-tidy 23.1.4 passed across all 40 configured production/binding translation units, with matching LLVM 23 resource headers for analysis. A separate focused run on the new C++ routing test also passed.Build and test commands
pythonbelow is the existing project virtual-environment interpreter. GoogleTest 1.14.0 was reused from the existing local source cache; unused GoogleMock was disabled because a system-installed GoogleTest header interfered with its build.Performance
GIST1M, 1,000,000 points × 960 dimensions; 4,096 Flat centroids; 5 bits; L2; k=10; default high-accuracy scanning. Both executables load the same prebuilt index and rotation, created with baseline
2122ab2: a 262,144-point training sample drawn without replacement using NumPydefault_rng(42), seed 42, 10 iterations, construction with 8 threads. This isolates search changes from training/version differences; the current main and candidate both read this legacy index.Compare current main against this PR using the same driver/compiler/options. Normally 1,000 queries, three alternating before/after process pairs, three timed repetitions per process after warmup; report median per-query time and its reciprocal QPS. The 4095/4096-probe cases use the first 64 queries and two pairs × two repetitions. Loading, warmup, hashing and recall calculation are outside timing. IDs and distance bytes have matching fingerprints in every comparison, and Recall@10 is unchanged (zero allowed quality loss).
Shared-host limitation: no CPU affinity on macOS; an unrelated VM was using approximately four CPU cores and the observed 1-minute load average was about 9.8. Small timing changes are not reliable evidence of a gain or regression.
The first sweep showed slower single/small-batch medians, so those cases were repeated with five alternating pairs × five repetitions, using the same binaries and data:
The single-query recheck is 1.2% slower by the aggregate median; per-pair speedups range from 0.971× to 1.088× (median 0.996×). The batch-8 aggregate changes direction between sweeps. These measurements do not establish a stable single-query regression or prove zero regression. Keeping this as a draft for review and an idle-host/x86 performance confirmation before merging; batch gains should also be remeasured on the target CPU.
Benchmark reproduction
Build the new benchmark driver against both revisions without changing the baseline search implementation. Use the same
gist.index, query file and ground truth for both:Sweep the batch/probe/thread combinations in the table. For near-all-cluster searches use
64 4095 1 2 64and64 4096 1 2 64with--pairs 2. For the longer recheck use batch 1 or 8, nprobe 64, one thread, five repetitions and--pairs 5.