Repository navigation
feat(python): let IvfIndex.set_centroids take num_threads - #231
Merged
Merged
Conversation
IvfIndex.set_centroids takes a keyword-only num_threads for rotating the centroids and building the routing, as train and add do. Only the HNSW routing graph varies with it; one thread and a fixed seed build a reproducible graph. The 0.7 build passed its thread count through, but the 0.8 split into set_centroids and add lost it. Without the argument, set_centroids used the C++ default, which runs on every CPU and ignores OMP_NUM_THREADS, for every initializer. None and 0 now select the available CPUs capped by OMP_NUM_THREADS, like every other default. That is what processes sharing OpenMP runtimes on macOS rely on. Tests check that a single-thread set_centroids gives identical files and that OMP_NUM_THREADS=1 caps the default. The routing tests that #230 loosened build with explicit thread counts again: the 128-centroid test is seeded and exact once more, and the parallel test's thread count applies to the routing build. The migration guide notes that IVF HNSW routing is no longer single-threaded by default.
This was referenced Nov 13, 2026
Open
TamimEhsan
pushed a commit
to TamimEhsan/khorgosh
that referenced
this pull request
Nov 20, 2026
0.9 gives the three index classes one name for each concept (VectorDB-NTU#232). This release accepts both spellings and raises a DeprecationWarning, at the caller's line, for the 0.8 one: - HnswIndex.capacity and reserve(num_points) for max_elements and resize; max_elements is deprecated on IvfIndex and SymqgIndex. - IvfIndex.reserve_cluster for reserve. - IvfIndex(routing=...) and the routing property for initializer. - search(queries, k, ef_search=...) for ef= on HnswIndex and SymqgIndex. - Search options after the breadth are keyword-only; positions warn. - nprobe=0 and ef_search=0 for the default warn; None selects it. - HnswIndex seeds above 2**32 - 1 warn. The extension keeps the 0.8 names, so the new ones are added in the Python layer, which 0.9 deletes when the extension itself is renamed. No 0.8 call changes its result or its exception type. The HnswIndex default seed and repr() are unchanged here; the 0.9 changes to them are announced in the new 0.8.5 release notes page, which also records VectorDB-NTU#231.
TamimEhsan
pushed a commit
to TamimEhsan/khorgosh
that referenced
this pull request
Nov 20, 2026
Bump the version to 0.8.5 in pyproject.toml and CMakeLists.txt, and update the install pins, clone commands and version text in the README, home page, installation, quick start and C++ integration pages. Turn docs/docs/releases/0.8.5.md into the release page: drop "(unreleased)" from the title and the navigation, add the Upgrading section, and correct three statements (search options become keyword-only in 0.9, not now; set_centroids used every CPU for every routing type before VectorDB-NTU#231; the stubs cannot mark the deprecations that depend on a value or the two old statistics names). The Python samples need 0.8.5 since VectorDB-NTU#235 and VectorDB-NTU#236, so their README asks for it. README news gains v0.8.5 and keeps the three most recent entries.
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.
IvfIndex.set_centroidsnow takes a keyword-onlynum_threads, astrainandadddo. The C++IVF::set_centroidsalready took it; the binding did not pass it through. The 0.7buildpassed its thread count to the routing build, and the 0.8 split intoset_centroidsplusaddlost it. #230 loosened two routing tests because of that, and this PR restores them.Changes
num_threadsonIvfIndex.set_centroids. It sets the workers that rotate the centroids and build the routing. Only the HNSW routing graph varies with it: one thread and a fixedseedgive the same graph on every run.HnswIndex.set_centroidsis unchanged; it rotates serially.OMP_NUM_THREADS. Without the argument, the binding used the C++ default (SIZE_MAX), which starts an OpenMP team of every CPU and ignoresOMP_NUM_THREADS. That happened for every initializer, not just HNSW.Noneand0now select the available CPUs capped byOMP_NUM_THREADS, like every other Python default. Processes that share OpenMP runtimes on macOS rely on that cap (v0.8.0 causing segfault 11 on macOS #207). The C++ default is unchanged.__init__.pyi,index/ivf.mdandindex/usage.mddescribe the argument. The migration guide notes that 0.7buildbuilt IVF HNSW routing with one thread by default, and that it is multithreaded now unlessnum_threads=1is passed (marked as 0.8.5).Tests
set_centroidscalls with the same seed give identical saved files, including the.hnswsidecar.OMP_NUM_THREADS=1, two defaultset_centroidscalls over 1,024 centroids give identical files. Before this change, every 2-, 4-thread or unlimited build differed (10 of 10 trials each), so the test guards the cap on any runner with at least 2 CPUs.test_hnsw_centroid_routing_roundtrip(128 centroids) is seeded, builds the routing with one thread, and checks exact matches again instead of aggregate self-recall.test_hnsw_parallel_build_routes_and_reloadspasses itsthreadstoset_centroids, so the parallel routing build is what it tests.Checks
On Linux x86-64, Xeon Gold 6418H, GCC 14.3, Release, native optimization off; the package was built from this branch.
check-tidy.shis clean.test_ivf.py,test_ivf_initializers.pyandtest_thread_counts.pyunder-W error::DeprecationWarning: 185 passed;check-python.sh,check-format.sh,mkdocs build --strictandgit diff --checkpass.Release notes
Main has no unreleased notes page, so for the next release:
IvfIndex.set_centroids(..., num_threads=None).IvfIndex.set_centroidswithoutnum_threadsused every CPU and ignoredOMP_NUM_THREADS; it now follows the same default astrainandadd.