Repository navigation
docs(cpp): build the C++ examples and docs on the index classes - #245
Conversation
The C++ examples, the example index checker and the IVF add hot-path benchmark use IvfIndex, HnswIndex and SymqgIndex instead of ivf::IVF, hnsw::HierarchicalNSW, symqg::QuantizedGraph and QGBuilder, as step 4 of #234. Command lines and output keep their formats, except: - symqg_indexing takes nbits (32 for raw vectors, 4 or 8, default 32) and still reads 0 as raw vectors. It no longer prints stage times or the average degree, which SymqgIndex does not expose. - The default thread counts of symqg_indexing and ivf_rabitq_indexing are capped by OMP_NUM_THREADS, which they ignored. - ivf_rabitq_querying calibrates nprobe with one batch search per value instead of single-query searches; the results are the same. The IVF add benchmark fixes the rotation seed at 42. The point-count IVF constructor drew a random rotation in every process, so its hashes never matched between processes and compare.py could not pair runs. hnsw_rabitq_indexing reserves the capacity before its timer, as the old constructor allocated it.
The C++ sections of the IVF-RaBitQ, HNSW-RaBitQ and SymphonyQG pages describe IvfIndex, HnswIndex and SymqgIndex, which follow the Python classes, instead of ivf::IVF, hnsw::HierarchicalNSW, symqg::QuantizedGraph and QGBuilder. usage.md, cpp_integration.md, python_migration.md and development.md follow. The release notes add a table from the 0.8 classes to the new ones, the differences that are not renames and the features only the old classes offer, and replace the note that C++ IDs stay 32-bit: the new classes use rabitqlib::Id with kNoId, and the old classes keep PID. A loaded index has no seed only when its file records none, as for files from releases up to 0.8; the pages said every loaded index.
|
Follow-up on the Setup: the same two example binaries (2ea3b22 and this branch) and the same IVF index file, 50,000 SIFT1M base vectors and 1,000 queries; single thread, pinned to core 7 with its SMT sibling idle and memory on node 0; host load average 1.5–2.8 (about 10 in the first measurement). 12 pairs in ABBA order (old-new, new-old, ...), 24 runs; each run reports the mean of 5 rounds per
The medians lean about 1% towards the old binary, inside the per-pair spread; the extra work of the class, a 32-bit ID buffer and the widening pass, is about 0.1–0.3% of a query by estimate. I read the first measurement's gap as host load during its first run, which I did not measure directly. Still no performance claim. |
Part of #234 (step 4 of 4: the examples, docs and release notes for the C++ index classes; steps 1–3 were #240, #243 and #244).
Summary
IvfIndex,HnswIndexandSymqgIndexare the supported C++ index API from 0.9, but the examples and docs still usedivf::IVF,hnsw::HierarchicalNSW,symqg::QuantizedGraphandQGBuilder. This moves them to the new classes. No library code changes.Code (first commit)
sample/cpp,tests/integration/cpp_example_index_check.cppandbenchmarks/hotpaths/ivf_add.cppuse the new classes. Command lines and output keep their formats, except:symqg_indexingtakesnbits(32 for raw vectors, 4 or 8, default 32) and still reads 0 as raw vectors, and its optional thread count 0 now selects every available CPU instead of failing. It no longer prints stage times or the average degree, whichSymqgIndexdoes not expose.symqg_indexingandivf_rabitq_indexingare capped byOMP_NUM_THREADS, which they ignored (total_threads()andIVF::construct'sSIZE_MAX).ivf_rabitq_queryingcalibratesnprobewith one batch search per value instead of single-query searches.IVFconstructor drew a random rotation in each process: two runs of the old binary printed different hashes (for example 295386913892750176 and 2753571698455311038), socompare.pycould not pair its runs. The new one prints the same hash every run. Its hashes differ from the old binary's, socompare.pycannot pair it with a build before this change.hnsw_rabitq_indexingcallsreservebefore its timer, as the old constructor allocated the graph before it.Docs (second commit)
docs/docs/index/{ivf,hnsw,qg}.mddescribe the new classes; the old-class sections are gone.usage.md,cpp_integration.md,python_migration.mdanddevelopment.md(index API and naming rules) follow.seed; that is true only when the file records none, as for files up to 0.8.Verification
Local, Linux x86-64, GCC 14, Release,
RABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF:ctestwith tests, samples and benchmarks: 621 tests, 620 passed, 1 skipped (ThreadCount.BoundParallelForUsesRuntimePlacementAndPropagatesErrors, which needs OpenMP thread binding). Run before the review fixes, which touched only examples, the benchmark README and docs; after them the examples were rebuilt andtest_cpp_clustering_examples.pyand theHotpathtests rerun.tests/python/test_cpp_clustering_examples.pywithRABITQ_REQUIRE_CPP_EXAMPLES=1: 18 passed. Making the checker expect the wrong ID fails 4 of them.check-format.sh,mkdocs build --strict,git diff --check.-Wall -Wextrawithout warnings and runs on synthetic data.Examples, old and new
Both builds at 2ea3b22 and this branch, on the first 50,000 SIFT1M base vectors with 1,000 queries and exact top-100 ground truth, clustered once with the unchanged
qgkmeans(256) andrabitqkmeans(16):nprobelist for IVF.OMP_NUM_THREADS=1,hnsw_rabitq_indexingwrites byte-identical files in both builds. IVF and SymphonyQG files differ, because their rotation seeds are drawn.symqg_indexingaccepts0,4withrandomand an explicit thread count;5fails withnbits must be 4, 8, or 32.The new
ivf_rabitq_queryingreported 3–14% lower median QPS than the old one on the same file (single thread, pinned to one core with memory on node 0, 3 interleaved runs each, load average about 10). Most of the gap comes from one run: the per-run new/old ratios were 0.81–0.89 in the first run and 0.92–1.08 in the other two. TimingIvfIndex::searchandIVF::search_batchalternately in one binary on that file gave median time ratios (new/old) of 0.97, 0.95 and 1.03 atnprobe5, 20 and 50, with identical IDs, so the class adds no measurable cost; I did not determine the cause of the cross-executable difference. The IVF add benchmark (128 dimensions, 64 clusters, 20,000 + 1,000 points, 3 interleaved runs of 5 repetitions) gave new/old median time ratios of 0.99 (single cluster) and 0.94 (routed), with overlapping ranges. I make no performance claim.Notes for review
symqg_indexingreleased its input before refinement.SymqgIndex::addhas no such step. Peak RSS at 50,000 points was the same (about 137 MB); at larger sizes the input may stay resident during refinement, which I did not measure.ivf_rabitq_indexingnow record the rotation seed, which the point-count constructor left out, so Python'sseedandcp.seedreport it afterloadinstead ofNoneand the k-means default.singleandroutedcan print the same hash. This predates the change.cpp_integration.mdstill pinsv0.8.5; the release updates it.