Repository navigation
feat(python)!: remove the 0.7 and 0.8 forms and expose the 0.9 names natively - #239
Merged
Merged
Conversation
…parameters QGKMeans configures the same SymphonyQG graph as the index under other names (#233). In C++: - QGKMeansParameters: graph_degree becomes max_degree, ef_build becomes ef_construction, and quantization_bits (0, 4 or 8) becomes nbits (32, 4 or 8, with 32 for raw float32). The fields keep their order and types. QGAssigner keeps its constructor, including quantization_bits with 0 for raw storage; the parameters are converted for it. - The messages follow the names: "QGKMeans nbits must be 4, 8, or 32", "QGKMeans max_degree must be a positive multiple of 32", "QGKMeans requires more centroids than max_degree" and "QGKMeans ef_construction and ef_search must be positive". - FinalAssignmentMode::SymphonyQG, an alias of Approximate, is removed. - qgkmeans::QGKMeansIterationStats and rabitqkmeans::RaBitQKMeansIterationStats are removed; use clustering::KMeansIterationStats. The C++ tests, the qgkmeans sample and the installed consumer use the new names. The Python bindings still name the old fields and build again with the next commit, which renames them.
…natively 0.8 kept the 0.7 call forms, and 0.8.5 the 0.8 spellings, in a Python layer that replaced members of the extension classes and raised DeprecationWarning. 0.9 deletes that layer and gives the extension the 0.9 API itself (#213, #232, #233): - Removed 0.7 forms: the point-count constructors and random_seed=, SymqgIndex(dim, max_degree, metric, quantization_bits), build(), is_built, SymqgIndex.search_batch() and quantization_bits, add options by position, and the private hooks behind them (_build, _max_elements, _quantization_bits). - Index names: IvfIndex(routing=...) and routing for initializer, IvfIndex.reserve_cluster for reserve, HnswIndex.capacity and reserve(num_points) for max_elements and resize, ef_search for ef. max_elements is gone from IvfIndex and SymqgIndex. reserve only grows the capacity, and within the capacity it only reads, so it may run alongside searches. - search: only nprobe or ef_search stays positional; high_accuracy and num_threads are keyword-only. nprobe=0 and ef_search=0 raise ValueError; None selects the default. - HnswIndex draws a 32-bit seed when none is given, as the other two classes do, instead of using 100, and rejects seeds above 2**32 - 1. - k-means: QGKMeansParameters has nbits, max_degree and ef_construction; final_assignment is 'approximate' or 'exact', also on index.cp, and reads back as that string; KMeansIterationStats is the only name of the statistics class. FinalAssignmentMode and the two old statistics names leave the package. A removed form raises a plain TypeError, AttributeError or ValueError and is never read as another call: IvfIndex(dim, 1000, 64) is an error, not an index with 1000 clusters. The index classes are now the extension's own, so a wrong argument raises pybind11's TypeError with the supported signature, and inspect.signature() no longer works on them. An invalid k-means nbits is reported by train, like the other parameters. repr() prints capacity= and routing=. The stubs lose their 37 deprecated declarations. The migration guide, the unreleased notes, the index and clustering pages and the naming contract in docs/development.md describe the 0.9 forms, including the C++ renames of the previous commit. Reproducible HNSW builds now need seed= as well as num_threads=1, and the pages that gave the recipe say so.
…ed ones fail Much of the Python suite still used the 0.8 spellings and passed only through the deleted compatibility layer, with deprecation warnings. - Every test file uses the 0.9 names. Tests that built two HnswIndex objects without a seed and compared them, or asserted something that depends on the graph, now pass a seed. - test_compat_08.py and test_compat_09.py are replaced by test_removed_forms.py: each 0.7 form and 0.8 spelling raises TypeError, AttributeError or ValueError, the private hooks are gone, and the renamed members behave as documented. - test_txtai_compat.py follows the calls a 0.9-compatible txtai backend makes (set_centroids and add(cluster_ids=...), np.isfinite for missing results, None for an unset ef); they also run without warnings on 0.8.5. - The typing fixture rejects the removed forms under mypy and Pyright instead of accepting them as deprecated. - Behaviour that only the deleted files covered keeps a test: reserve within the capacity during a search, the drawn HNSW seed, SymqgIndex construction settings and a failed add, the k-means graph-parameter messages, negative search options, and pickling KMeansIterationStats. - HnswIndex.reserve cannot shrink, so the shrinking leg of the allocation-threshold test moves to a C++ test of HierarchicalNSW::resize.
This was referenced Nov 14, 2026
… graphs HnswIndex draws a seed when none is given, so one thread alone no longer reproduces a graph. The num_threads entry of the add docstring still gave the 0.8 recipe; the class docstring and the documentation pages already name the seed.
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
ef_search#232 and Align k-means parameter names with the index API #233: the removal step that their transition releases (0.8.0 and 0.8.5) prepared. Targetsdev/0.9, so no issue closes on merge.0.8 kept the 0.7 call forms, and 0.8.5 the 0.8 spellings, in a Python layer that replaced members of the extension classes and raised
DeprecationWarning. This PR deletes that layer and gives the extension the 0.9 API itself. A removed form raises a plainTypeError,AttributeErrororValueError(ImportErrorfor a name imported from the package) and is never read as another call:IvfIndex(dim, 1000, 64)is an error, not an index with 1000 clusters.IvfIndex(dim, max_elements, num_clusters, nbits, ...),HnswIndex(dim, max_elements, ...),random_seed=IvfIndex(dim, num_clusters, nbits=...),HnswIndex(dim, nbits=...),seed=SymqgIndex(dim, max_degree, metric, quantization_bits),quantization_bits=SymqgIndex(dim, max_degree=..., metric=..., nbits=...)build(),is_built,SymqgIndex.search_batch(),SymqgIndex.quantization_bitstrain()orset_centroids(), thenadd()(forSymqgIndex,ef_construction=andinit=on the constructor, thenadd());is_trainedorlen();search();nbitsaddoptions by positionmax_elementsHnswIndex.capacity;num_stored_pointsonIvfIndexandSymqgIndexHnswIndex.resize(n),IvfIndex.reserve(cluster_id, n)HnswIndex.reserve(n), which only grows;IvfIndex.reserve_cluster(cluster_id, n)IvfIndex(initializer=...),index.initializerroutingsearch(..., ef=...),high_accuracyandnum_threadsby positionef_search=; keywordsnprobe=0,ef_search=0for the defaultNone; 0 raisesValueErrorQGKMeans(quantization_bits=, graph_degree=, ef_build=)nbits=(32, 4 or 8),max_degree=,ef_construction=FinalAssignmentMode,QGKMeansIterationStats,RaBitQKMeansIterationStatsfinal_assignment='approximate' | 'exact';KMeansIterationStatsEvery replacement already works in 0.8.5, where the old form warns.
Changes
Three commits, plus a fourth that corrects one docstring:
QGKMeansParameterstakesmax_degree,ef_constructionandnbits(32 for raw float32) forgraph_degree,ef_buildandquantization_bits(0 for raw); the fields keep their order and types, andQGAssignerkeeps its constructor.FinalAssignmentMode::SymphonyQGand the aliasesQGKMeansIterationStatsandRaBitQKMeansIterationStatsare removed. Four messages name the new parameters. The Python bindings do not build at this commit alone; the next one renames them.python_bindings/__init__.pyloses both layers (about 940 lines) and keeps only the k-means wrappers. The bindings lose the private hooks (_build,_max_elements,_quantization_bits,random_seed) and take the 0.9 names. The stubs lose their 37 deprecated declarations. Docs: migration guide, unreleased notes, the index and clustering pages, and the naming contract indocs/development.md.Behaviour that changes besides the removals; the first four items are in the unreleased notes:
HnswIndex()withoutseed=draws a 32-bit seed instead of using 100, and seeds above2**32 - 1raiseValueError. A reproducible HNSW build now needsseed=as well asnum_threads=1; the four pages that gave the old recipe, the class docstring and theadddocstring say so.TypeErrorwith the supported signature, andinspect.signature()no longer works on them;help()and the stubs describe them.cp.final_assignmentreads back as a string. An invalid k-meansnbitsis reported bytrain, like the other parameters; 0.8.5 rejected it when it was set.repr()printscapacity=forHnswIndexandrouting=forIvfIndex, and no longer printsmax_elements=forIvfIndex.SymqgIndex.searchreports a wrong query dimension before an invalidkor breadth, as the other two classes do; and arguments follow pybind11's conversions where the Python layer had its own, sofinal_assignment=b'exact'andHnswIndex.reserve(np.float32(10))are accepted andreserve(2**63)raisesTypeError, notValueError.Kept from 0.8.5:
HnswIndex.reservewithin the current capacity only reads, so it may run alongside searches (documented on the usage page).Not in this PR: the version strings that still say 0.8.5, and naming the first compatible txtai release in the notes and on the txtai integration page (the #213 gate). Both belong to the 0.9 release preparation.
Tests
HnswIndexobjects, or asserted something that depends on the graph, pass a seed.test_compat_08.pyandtest_compat_09.pyare replaced bytest_removed_forms.py(14 tests, parametrized): each removed form fails with the expected exception, the private hooks are gone, and the renamed members behave as documented.test_txtai_compat.pyfollows the calls a 0.9-compatible txtai backend makes; the same test passes without warnings on the released 0.8.5.reservewithin the capacity during a search, the drawn HNSW seed, SymphonyQG construction settings and a failedadd, the k-means graph-parameter messages, negative search options, and pickling theKMeansIterationStatsclass by name.HnswIndex.reservecannot shrink, so the shrinking leg of the allocation-threshold test moves to a new C++ test ofHierarchicalNSW::resize.reserve, the drawn seed, thefinal_assignmentvalidation, the use ofef_construction, two k-means checks, the SymphonyQG check order, and taking thesaveguard before resolving the path each fail at least one test.Checks
On Linux x86-64, Xeon Gold 6418H, GCC 14.3, Release, CPython 3.13. The C++ builds and the clang-tidy build have native optimization off.
pip install .from this branch and installed (default native tuning) and with an extension built with native optimization off. The C++ example targets were built, so their 16 tests ran.ThreadCount.BoundParallelForUsesRuntimePlacementAndPropagatesErrors), with tests, samples and benchmarks built; the installed consumer intests/consumerbuilds and passes its 3 tests.check-tidy.shon the full first-party set (clang 23),check-format.sh,check-python.sh,mkdocs build --strictandgit diff --checkpass.tests/core_consumer(no public header was added or removed). The ISA symbol check does not apply; no ISA-flagged source or header it includes changed.reservethat reported "Index is busy" during a search (a regression against 0.8.5 in the first version of this change), documentation that gave a reproducible-build recipe without the seed, lost coverage and several assertions that could not fail.