Repository navigation
Description
Problem
IVF-RaBitQ with Flat routing chooses the clusters to probe one query at a time: each query
reads every centroid. On GIST1M with 4,096 clusters this read takes about half or more of the
search time, also for batched calls (many queries per call), where a block of centroids could
be reused across many queries. In 0.8.2, add switched to a blocked matrix-product
assignment for the same problem and became about four times faster for large batches (GIST1M,
4,096 clusters: 24–26 s → 6.4–6.7 s).
Measurements
GIST1M (960 dims), 4,096 clusters, Flat routing, nbits=5, k=10; a local 0.8.2 build; Xeon Gold 6418H pinned to cores 0–15; shared host
(load average 3–5); best of 3 runs (one run for 10,000 queries on one thread). "Routing" is
the search time of an index with the same 4,096 centroids and one point per cluster, so it
also includes query rotation and a negligible scan; it barely changes with nprobe.
| Queries per call | Threads | nprobe |
Search µs/query | Routing µs/query | Routing share |
|---|---|---|---|---|---|
| 1 | 1 | 16 | 593 | 500 | 84% |
| 1 | 1 | 128 | 1,072 | 495 | 46% |
| 10,000 | 1 | 16 | 528 | 439 | 83% |
| 10,000 | 1 | 128 | 1,038 | 486 | 47% |
| 10,000 | 16 | 16 | 41.0 | 35.7 | 87% |
| 10,000 | 16 | 64 | 57.4 | 39.8 | 69% |
| 10,000 | 16 | 128 | 76.4 | 41.4 | 54% |
For comparison, NumPy computes the same 10,000 × 4,096 inner products (Q @ C.T, float32,
16 threads) in 3.9 µs per query, about a tenth of the routing time above.
Task
For batched search with Flat routing, route a block of queries at a time with a blocked
top-nprobe selection instead of one centroid scan per query. The exact_assign kernel in
include/rabitqlib/clustering/detail/kmeans.hpp finds only the nearest centroid, so it needs a
top-nprobe variant.
- Results must be identical to the per-query path up to floating-point ties (as for
addin
0.8.2). - Single-query latency must not get worse; a single query cannot reuse centroids, so this does
not help it. - Report a before/after benchmark with the dataset, CPU, compiler, ISA, threads, batch sizes,
nprobeand Recall@10.
The code is in src/index/ivf.cpp (search for one query and for batches). See
performance and compatibility
for benchmark requirements.
Activity
jay23606 commentedon Nov 11, 2026
I'd like to take this one. My plan is to add a top-nprobe variant of the assignment kernel in kmeans.hpp and use it in the batched Flat-routing path of
searchin src/index/ivf.cpp, leaving the single-query path alone. I'd test it by checking that batched and per-query results match, and by re-running the GIST1M benchmark before and after. Could you assign this to me?jay23606 commentedon Nov 12, 2026
I'd like to take this one. My plan is to add a blocked top-nprobe variant next to
exact_assigninkmeans.hppand use it in the batched Flat-routing path ofsearchinsrc/index/ivf.cpp. I'd test it by checking that batched results match the per-query path on a small deterministic dataset, then run the existing IVF tests and a before/after benchmark. Could you assign this to me?gouyt13 commentedon Nov 13, 2026
@jay23606 This is already assigned to you, so no need to ask again. Please open a draft PR early so we can review the approach.
gouyt13 commentedon Nov 14, 2026
Unassigned: #229 was closed after its only update merged
mainwithout addressing the review.This issue is available again. The review on #229 lists what an implementation needs: limiting the GEMM to one thread per worker, ordering tied centroid distances the same way as the scalar path, handling nprobe close to the cluster count, and tests that cross centroid tiles and row blocks. To claim it, please comment with how you will verify the change locally: the IVF C++ tests,
./scripts/check-format.sh, and GIST1M throughput and Recall@10 before and after.gouyt13 commentedon Nov 18, 2026
Update: comments no longer reserve issues, so this one will not be assigned from a claim comment. To work on it, open a draft PR once you have code and include the local results the review on #229 asks for: the IVF C++ tests,
./scripts/check-format.sh, and GIST1M throughput and Recall@10 before and after. If several PRs address this issue, the first to pass review is merged.gouyt13 commentedon Nov 25, 2026
Implemented in #265 (merged as 9868b0e). Batched Flat search now screens centroids for a block of queries with a matrix product, then recomputes the retained ones with the existing distance functions, so IDs and distances match per-query search. Thanks @ColinLeeo.