Skip to content

IVF-RaBitQ: route batched queries with a blocked top-nprobe assignment #218

Done

Description

@gouyt13

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 add in
    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,
    nprobe and 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

  1. added this to the 0.8.x milestone on Nov 2, 2026
  2. added
    enhancement
    help wanted
    on Nov 2, 2026
  3. jay23606 commented on Nov 11, 2026

    @jay23606

    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 search in 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?

  4. jay23606 commented on Nov 12, 2026

    @jay23606

    I'd like to take this one. My plan is to add a blocked top-nprobe variant next to exact_assign in kmeans.hpp and use it in the batched Flat-routing path of search in src/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?

  5. gouyt13 commented on Nov 13, 2026

    @gouyt13
    MemberAuthor

    @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.

  6. gouyt13 commented on Nov 14, 2026

    @gouyt13
    MemberAuthor

    Unassigned: #229 was closed after its only update merged main without 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.

  7. gouyt13 commented on Nov 18, 2026

    @gouyt13
    MemberAuthor

    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.

  8. removed this from the 0.8.x milestone on Nov 24, 2026
  9. gouyt13 commented on Nov 25, 2026

    @gouyt13
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions