Skip to content

feat(python)!: remove the 0.7 and 0.8 forms and expose the 0.9 names natively - #239

Merged
gouyt13 merged 4 commits into
dev/0.9from
feat/python-09-api
Nov 14, 2026
Merged

gouyt13 merged 4 commits into
dev/0.9from
feat/python-09-api

Conversation

@gouyt13

@gouyt13 gouyt13 commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Summary

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 plain TypeError, AttributeError or ValueError (ImportError for 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.

Removed Use
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_bits train() or set_centroids(), then add() (for SymqgIndex, ef_construction= and init= on the constructor, then add()); is_trained or len(); search(); nbits
add options by position keywords
max_elements HnswIndex.capacity; num_stored_points on IvfIndex and SymqgIndex
HnswIndex.resize(n), IvfIndex.reserve(cluster_id, n) HnswIndex.reserve(n), which only grows; IvfIndex.reserve_cluster(cluster_id, n)
IvfIndex(initializer=...), index.initializer routing
search(..., ef=...), high_accuracy and num_threads by position ef_search=; keywords
nprobe=0, ef_search=0 for the default None; 0 raises ValueError
QGKMeans(quantization_bits=, graph_degree=, ef_build=) nbits= (32, 4 or 8), max_degree=, ef_construction=
FinalAssignmentMode, QGKMeansIterationStats, RaBitQKMeansIterationStats final_assignment='approximate' | 'exact'; KMeansIterationStats

Every replacement already works in 0.8.5, where the old form warns.

Changes

Three commits, plus a fourth that corrects one docstring:

  1. C++ k-means names (Align k-means parameter names with the index API #233). QGKMeansParameters takes max_degree, ef_construction and nbits (32 for raw float32) for graph_degree, ef_build and quantization_bits (0 for raw); the fields keep their order and types, and QGAssigner keeps its constructor. FinalAssignmentMode::SymphonyQG and the aliases QGKMeansIterationStats and RaBitQKMeansIterationStats are removed. Four messages name the new parameters. The Python bindings do not build at this commit alone; the next one renames them.
  2. Python API. python_bindings/__init__.py loses 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 in docs/development.md.
  3. Tests. See below.

Behaviour that changes besides the removals; the first four items are in the unreleased notes:

  • HnswIndex() without seed= draws a 32-bit seed instead of using 100, and seeds above 2**32 - 1 raise ValueError. A reproducible HNSW build now needs seed= as well as num_threads=1; the four pages that gave the old recipe, the class docstring and the add docstring say so.
  • The index classes are the extension's own again. A wrong argument raises pybind11's TypeError with the supported signature, and inspect.signature() no longer works on them; help() and the stubs describe them.
  • cp.final_assignment reads back as a string. An invalid k-means nbits is reported by train, like the other parameters; 0.8.5 rejected it when it was set.
  • repr() prints capacity= for HnswIndex and routing= for IvfIndex, and no longer prints max_elements= for IvfIndex.
  • Not in the notes, for invalid or unusual arguments only: SymqgIndex.search reports a wrong query dimension before an invalid k or breadth, as the other two classes do; and arguments follow pybind11's conversions where the Python layer had its own, so final_assignment=b'exact' and HnswIndex.reserve(np.float32(10)) are accepted and reserve(2**63) raises TypeError, not ValueError.

Kept from 0.8.5: HnswIndex.reserve within 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

  • Every Python test file uses the 0.9 names; the suite no longer emits a deprecation warning. Tests that compared two separately built HnswIndex objects, or asserted something that depends on the graph, pass a seed.
  • test_compat_08.py and test_compat_09.py are replaced by test_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.py follows the calls a 0.9-compatible txtai backend makes; the same test passes without warnings on the released 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, SymphonyQG construction settings and a failed add, the k-means graph-parameter messages, negative search options, and pickling the KMeansIterationStats class by name.
  • HnswIndex.reserve cannot shrink, so the shrinking leg of the allocation-threshold test moves to a new C++ test of HierarchicalNSW::resize.
  • The new assertions were checked by mutation: disabling the zero-breadth checks, the keyword-only markers, the grow-only rule and read guard of reserve, the drawn seed, the final_assignment validation, the use of ef_construction, two k-means checks, the SymphonyQG check order, and taking the save guard 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.

  • Full Python suite with the mypy and Pyright tests: 1,197 passed, 2 skipped (wheel tests for other platforms), both with the package built by 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.
  • C++: 571 tests, 570 passed and 1 skipped (ThreadCount.BoundParallelForUsesRuntimePlacementAndPropagatesErrors), with tests, samples and benchmarks built; the installed consumer in tests/consumer builds and passes its 3 tests.
  • check-tidy.sh on the full first-party set (clang 23), check-format.sh, check-python.sh, mkdocs build --strict and git diff --check pass.
  • Not run locally: CPython 3.11, 3.12 and 3.14, Windows, macOS and ARM, the sanitizer build, and 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.
  • Two independent reviews and a final audit compared the build with 0.8.5 over several hundred calls. No defect they found remains: this PR includes the fixes for a reserve that 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.

…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.
… 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.
@gouyt13
gouyt13 merged commit 3685e81 into dev/0.9 Nov 14, 2026
26 checks passed
@gouyt13
gouyt13 deleted the feat/python-09-api branch November 14, 2026 12:01
@gouyt13 gouyt13 mentioned this pull request Nov 14, 2026
6 of 8 tasks
@gouyt13 gouyt13 added the release:breaking Breaking change; listed first in release notes (set by hand) label Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:added Release category managed from the PR title release:breaking Breaking change; listed first in release notes (set by hand)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant