Skip to content

docs(cpp): build the C++ examples and docs on the index classes - #245

Merged
gouyt13 merged 2 commits into
dev/0.9from
feat/index-api-docs
Nov 16, 2026
Merged

gouyt13 merged 2 commits into
dev/0.9from
feat/index-api-docs

Conversation

@gouyt13

@gouyt13 gouyt13 commented Nov 16, 2026

Copy link
Copy Markdown
Member

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, HnswIndex and SymqgIndex are the supported C++ index API from 0.9, but the examples and docs still used ivf::IVF, hnsw::HierarchicalNSW, symqg::QuantizedGraph and QGBuilder. This moves them to the new classes. No library code changes.

Code (first commit)

  • The six C++ examples in sample/cpp, tests/integration/cpp_example_index_check.cpp and benchmarks/hotpaths/ivf_add.cpp use the new classes. 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, and its optional thread count 0 now selects every available CPU instead of failing. 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 (total_threads() and IVF::construct's SIZE_MAX).
    • ivf_rabitq_querying calibrates nprobe with one batch search per value instead of single-query searches.
  • The IVF add benchmark fixes the rotation seed at 42. The point-count IVF constructor drew a random rotation in each process: two runs of the old binary printed different hashes (for example 295386913892750176 and 2753571698455311038), so compare.py could not pair its runs. The new one prints the same hash every run. Its hashes differ from the old binary's, so compare.py cannot pair it with a build before this change.
  • hnsw_rabitq_indexing calls reserve before its timer, as the old constructor allocated the graph before it.

Docs (second commit)

  • The C++ sections of docs/docs/index/{ivf,hnsw,qg}.md describe the new classes; the old-class sections are gone. usage.md, cpp_integration.md, python_migration.md and development.md (index API and naming rules) follow.
  • The release notes replace the note that C++ IDs stay 32-bit and add a table from the 0.8 classes to the new ones, with the four differences that are not renames and the features only the old classes offer.
  • The IVF and SymphonyQG pages said a loaded index has no 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:

  • ctest with 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 and test_cpp_clustering_examples.py and the Hotpath tests rerun.
  • tests/python/test_cpp_clustering_examples.py with RABITQ_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.
  • Every new C++ snippet in the index pages compiles with -Wall -Wextra without warnings and runs on synthetic data.
  • No Python code or binding changes, so the package was not reinstalled and the type checks were not run.

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) and rabitqkmeans (16):

  • Each querying example searched the index files of both builds. On the same file, old and new give identical recall in every row, and the same nprobe list for IVF.
  • Each build loads the other's IVF, HNSW and SymphonyQG files.
  • With OMP_NUM_THREADS=1, hnsw_rabitq_indexing writes byte-identical files in both builds. IVF and SymphonyQG files differ, because their rotation seeds are drawn.
  • symqg_indexing accepts 0, 4 with random and an explicit thread count; 5 fails with nbits must be 4, 8, or 32.

The new ivf_rabitq_querying reported 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. Timing IvfIndex::search and IVF::search_batch alternately in one binary on that file gave median time ratios (new/old) of 0.97, 0.95 and 1.03 at nprobe 5, 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

  • The old symqg_indexing released its input before refinement. SymqgIndex::add has 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.
  • Files written by ivf_rabitq_indexing now record the rotation seed, which the point-count constructor left out, so Python's seed and cp.seed report it after load instead of None and the k-means default.
  • The IVF add benchmark hashes only the top 10 neighbours of base row 0, so single and routed can print the same hash. This predates the change.
  • cpp_integration.md still pins v0.8.5; the release updates it.

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.
@github-actions github-actions Bot added the release:documentation Release category managed from the PR title label Nov 16, 2026
@gouyt13

gouyt13 commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Follow-up on the ivf_rabitq_querying QPS gap in the description (3–14% lower, cause not determined): rerun on a quieter host, it does not reproduce.

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

nprobe Old median QPS New median QPS New/old Per-pair ratio range Pairs with new lower
5 32832 32291 0.984 0.933–1.065 8/12
20 20456 20220 0.988 0.949–1.052 7/12
50 14415 14050 0.975 0.942–1.064 5/12
100 10271 10139 0.987 0.942–1.029 7/12
110 9954 9869 0.991 0.923–1.066 9/12
  • Over all 12 nprobe values, the 144 per-pair new/old ratios have median 0.996 (range 0.921–1.072); the new binary was lower in 82 of 144. Recall is identical in every pair.
  • Old-first and new-first pairs do not differ systematically: per-pair medians range from 0.949 to 1.022.
  • In one binary, 15 alternating calls of IvfIndex::search and IVF::search_batch gave median time ratios (new/old) of 1.020, 1.009 and 1.036 at nprobe 5, 20 and 50, with per-call ratios from 0.889 to 1.164 and identical IDs. The first measurement gave 0.97, 0.95 and 1.03, so this comparison itself varies by a few percent.

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.

@gouyt13
gouyt13 merged commit 16e8f01 into dev/0.9 Nov 16, 2026
26 checks passed
@gouyt13
gouyt13 deleted the feat/index-api-docs branch November 16, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:documentation Release category managed from the PR title

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant