Repository navigation
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
NEON-only validation leaves native x86 correctness/performance and idle-host single-query latency unconfirmed, requiring human review against issue VectorDB-NTU#218’s no-regression requirement.
No open issues 🎉
What changed in this PR
This PR optimizes flat IVF batch routing with blocked matrix multiplication and top-nprobe selection, while retaining existing float-distance kernels and scalar fallbacks.
Changes:
- Adds blocked centroid screening with reusable worker buffers and per-worker thread limits.
- Shares search logic between routing paths and makes distance ties deterministic by centroid ID.
- Adds C++ and Python regression coverage plus an external-data search benchmark.
| File | Description |
|---|---|
tests/unit/rabitqlib/index/flat_routing_test.cpp |
Tests routing equivalence, rounded ties, block boundaries, threading, and removed-result padding. |
tests/python/test_ivf.py |
Tests batch equivalence across metrics, storage widths, persistence, and thread counts. |
src/index/ivf.cpp |
Integrates blocked batch routing and extracts shared preassigned search logic. |
include/rabitqlib/index/ivf/ivf.hpp |
Declares the preassigned search helper. |
include/rabitqlib/index/ivf/initializer.hpp |
Applies deterministic distance-then-ID ordering to scalar routing. |
include/rabitqlib/index/detail/candidate.hpp |
Defines the shared candidate comparator. |
include/rabitqlib/clustering/detail/kmeans.hpp |
Adds blocked top-nprobe screening with float-distance recomputation. |
benchmarks/hotpaths/README.md |
Documents the search benchmark and comparison protocol. |
benchmarks/hotpaths/ivf_search.cpp |
Adds batched-search timing, result fingerprints, and Recall@10 reporting. |
benchmarks/hotpaths/CMakeLists.txt |
Registers the IVF search benchmark target. |
Review effort: Balanced
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
Review mirror of VectorDB-NTU#265, which addresses upstream issue VectorDB-NTU#218. This PR is for independent Copilot review; the implementation is proposed for merging upstream.
The review uses exactly the upstream PR's base and head:
9121a79ae0f5e23d3c5f5aef2431e872b89afd92a41d52dd5791414fa450ce361efd99d2517863caFlat IVF batch routing uses blocked GEMM screening and a top-nprobe heap, then recomputes retained candidates with the existing float kernels. It computes centroid norms once per call, streams reusable worker scratch, limits GEMM to one thread per worker, and orders both paths by returned float distance then centroid ID. Small batches and large nprobe retain scalar routing. Cosine normalization and raw-vector reranking inputs are preserved.
Please pay particular attention to numerical screening bounds and rounded L2 ties, nested OpenMP/thread-setting behavior, cosine normalization, query/centroid block boundaries, removed-point padding, and size/overflow handling.
Testing
The upstream PR contains the full protocol, commands and performance tables. For this same commit on Apple M5 Pro / AppleClang 17 / Release / NEON / native optimization OFF:
Relevant review findings will be checked against the implementation and summarized with links on upstream PR VectorDB-NTU#265.
Native x86 correctness follow-up (2026-11-24)
Verified the completed jobs in fork CI run 45357507822 on the exact PR commit
a41d52dd5791414fa450ce361efd99d2517863ca:All three jobs executed and passed the new
IvfFlatRoutingTestcases for tiled top-nprobe parity, float-distance ties, and streamed batch search with removed-ID padding. Skips are explicit platform/runtime/ISA limitations; they are not counted as passes. ASan/UBSan, the Clang OpenMP OFF core/FastScan checks, and benchmark smoke also passed. OpenMP OFF does not build the IVF index.The GCC host reports an AMD EPYC 7763 (x86-64). Its separate Intel SDE checks passed for AVX2-only and AVX-512 dispatch; those emulation checks are correctness evidence, not native performance measurements. These CI results address the native x86 runtime-validation gap raised by Copilot. Native x86 before/after GIST measurements are now reported in the performance follow-up. The single-query repeat is 1.5% slower, so the no-regression criterion remains unresolved and the PR remains a draft.
Native x86-64 measurements (2026-11-24)
Measured base
9121a79ae0f5e23d3c5f5aef2431e872b89afd92against PR heada41d52dd5791414fa450ce361efd99d2517863caon an AMD EPYC 9J14 KVM guest, Ubuntu 24.04.4, 32 vCPUs, approximately 62 GiB RAM, GCC 13.3.0, CMake 3.28.3, Release-O3 -DNDEBUG, C++17, OpenMP ON, native optimization OFF. The guest exposes AVX2 and AVX-512; the library retains its runtime-dispatched kernels. The baseline receives only this PR's identical standalone search benchmark driver and its CMake target, with no changes to its search implementation.Before timing, the candidate's complete CTest run finished with 644 passed, 1 skipped, 0 failed (645 registered). The sole skip was
ThreadCount.BoundParallelForUsesRuntimePlacementAndPropagatesErrors. The ISA symbol check also passed for 49 translation units. No build or other CPU-heavy guest workload ran concurrently with the benchmark.Workload: GIST1M, 1,000,000 × 960, L2, 4096 Flat centroids, 5 bits, k=10, default high-accuracy scanning. Both revisions read the exact same prebuilt index used by the earlier ARM64 measurements (built at
2122ab2, sample 262144 without replacement using NumPydefault_rng(42), seed 42, 10 iterations, 8 construction threads). The transferred index, query file and ground truth were SHA-256 verified. Index SHA-256:897a89a212b75ff7db681cb55e632bc3568ee9022d7000955e7faf05e0784037.Pin each process before loading with
numactl --physcpubind=0 --membind=0for one thread, or CPUs0-3for four threads; setOMP_PROC_BIND=close,OMP_PLACES=cores,OMP_DYNAMIC=FALSEand the matchingOMP_NUM_THREADS. Use 1000 queries, alternating process order, one untimed warmup per process. Batch 1 and 8 use 7 pairs × 7 timed repetitions; other cases use 3 pairs × 3 repetitions. The 4095/4096-probe cases use the first 64 queries. Loading, warmup, hashing and recall are excluded from timing. Report the median over all timed repetitions and its reciprocal QPS. Every before/after comparison has identical ID/distance fingerprints and unchanged Recall@10.The batch-8 control was 2.5% slower in the first sweep, including one unusually slow candidate process. Both controls were therefore repeated, retaining all original results, with the same CPU binding, binaries, data, and 7 pairs × 7 repetitions:
The single-query no-regression requirement is not yet established. Its first sweep was essentially flat (1.003×), but the repeat was 1.5% slower, with all seven paired medians slower (speedups 0.959×–0.993×, median 0.987×). Batch 8 was 2.5% slower initially and 1.1% slower on repeat. These control results need investigation; the batch throughput gains do not resolve them. At batch 1000 / nprobe 64, the measured throughput gain is 13.0% with one thread and 17.8% with four threads; nprobe 16 gains 24.3% at its separately reported recall.
Environment limit: this is native x86 instruction execution in a KVM guest, not a dedicated bare-metal result. Bound-vCPU steal time was at most 0.058% over the recorded comparison windows, but guest measurements cannot exclude physical-host cache/frequency or scheduling interference. CPU affinity and an otherwise idle guest improve repeatability without proving zero noise. The PR remains Draft for the control-latency investigation and human review.
x86 reproduction commands
Build both source snapshots with the same compiler/options; install the identical
ivf_search.cppbenchmark driver and its target into the baseline only. SetBUILD_TESTS=OFFfor the baseline andBUILD_TESTS=ONfor the candidate. No Python binding or package installation is required for this C++ benchmark.Use batch 8 with the same control settings; for other rows use three pairs and three repetitions. Four-thread rows use
OMP_NUM_THREADS=4and--physcpubind=0-3. Near-all-cluster rows use 64 queries. Repeat controls into a fresh output directory. Raw CSV/stdout/stderr, paired medians, CPU counters, exact compile commands, build/CTest/ISA logs and scripts have been retained.