Skip to content

feat(python): accept the 0.9 k-means names and deprecate the 0.8 spellings - #236

Merged
gouyt13 merged 1 commit into
mainfrom
feat/kmeans-09-names
Nov 14, 2026
Merged

gouyt13 merged 1 commit into
mainfrom
feat/kmeans-09-names

Conversation

@gouyt13

@gouyt13 gouyt13 commented Nov 14, 2026

Copy link
Copy Markdown
Member

Summary

0.9 names the k-means parameters like the index parameters. This PR makes the next 0.8 release accept the 0.9 names next to the 0.8 spellings, and raise a DeprecationWarning for each 0.8 spelling at the caller's line, so code can move before 0.9 removes the old forms.

0.8 form (now warns) Name to use
QGKMeans(quantization_bits=0 | 4 | 8), cp.quantization_bits nbits=32 | 4 | 8, cp.nbits (32, not 0, keeps raw vectors)
graph_degree max_degree
ef_build ef_construction
final_assignment=FinalAssignmentMode.Approximate | .Exact final_assignment='approximate' | 'exact', also on index.cp of IvfIndex and HnswIndex
QGKMeansIterationStats, RaBitQKMeansIterationStats KMeansIterationStats

Changes

  • Python layer only. The extension keeps the 0.8 names; the new ones are added in the "0.9 names" section of python_bindings/__init__.py that feat(python): accept the 0.9 names and deprecate the 0.8 spellings #235 introduced, which 0.9 deletes when the extension itself is renamed. No C++ file changes.
  • No 0.8 call changes its result, its exception type or its error message. Passing an old and a new name together raises TypeError.
  • final_assignment. A string is accepted everywhere a member was. Until 0.9 the attribute still reads back as the FinalAssignmentMode member, and a member is still accepted as a value, without a warning of its own.
  • Names that leave the package. FinalAssignmentMode, QGKMeansIterationStats and RaBitQKMeansIterationStats are served by a module-level __getattr__, which warns where the name is imported or read. They stay in __all__, so from rabitqlib import * still provides them and warns three times. They no longer appear in dir(rabitqlib).
  • One visible rename. The statistics class reports its name as KMeansIterationStats; it still pickles by reference, and pickles that name the old class still load.
  • Train-time message. The extension's QGKMeans ef_build and ef_search must be positive names ef_construction only when the caller passed that keyword to the constructor; every other call keeps the message.
  • Stubs. __init__.pyi declares the new names and marks each 0.8 form @deprecated. mypy 2.4 reports assignments to a deprecated settable attribute but not reads of it (pyright reports both), and PEP 702 cannot mark the two old statistics names, which are plain aliases.
  • Docs. clustering.md, the "From 0.8 to 0.9" section of the migration guide, the 0.8.5 release notes and the naming contract in docs/development.md use the new names; the samples and benchmark scripts do too.

Coming in 0.9 without a warning, and listed in the release notes: cp.final_assignment reads back as a string.

Tests

  • 22 new tests in tests/python/test_compat_09.py for the k-means names. The helper that checks a warning now also checks its line number, for the index tests of feat(python): accept the 0.9 names and deprecate the 0.8 spellings #235 as well.
  • The tests were checked by mutation: dropping an old keyword, not mapping nbits=32 to raw storage, mapping 'exact' to the wrong member, not warning for an old name, a warning one frame too deep, the old attribute using the new encoding, a hard-coded class name, a failing read with no Python caller, a class pickle cannot find, and re-raising an unrelated error each fail at least one test.
  • tests/test_mypy.py checks that mypy flags the deprecated forms and, in a new test, that it flags none of the forms 0.9 keeps.

The other k-means test files still use the 0.8 names. They pass and only warn; moving them belongs with the follow-up that #235 mentioned.

Checks

On Linux x86-64, Xeon Gold 6418H, GCC 14.3, Release, native optimization off; the package was built from this branch and installed, CPython 3.13.

  • Full Python suite with the mypy and Pyright tests: 1,190 passed, 18 skipped (16 need the C++ example targets, which were not built; 2 are wheel tests for other platforms).
  • test_compat_09.py, test_train_api.py, test_symqg_api.py and test_examples.py under -W error::DeprecationWarning: 178 passed.
  • check-python.sh, mkdocs build --strict and git diff --check pass. No C++ source changes, so the C++ checks were not run locally.
  • Version-dependent pieces (the module __getattr__ and its single warning for from rabitqlib import name, property naming, a read with no Python caller, the line-number check) were run as standalone snippets on CPython 3.11, 3.12 and 3.13 with identical results. 3.14, Windows, macOS and ARM are left to CI.
  • Independent reviews compared about 150 call forms before and after the change. They found, and this PR fixes, a read that failed without a Python caller, a class that no longer pickled by reference, a changed message for unknown keywords, a train error that changed type for a subclass that does not call __init__, and several tests that could not fail.

…lings

0.9 names the k-means parameters like the index parameters (#233). This
release accepts both spellings and raises a DeprecationWarning, at the
caller's line, for the 0.8 one:

- QGKMeans and QGKMeansParameters take nbits (32, 4 or 8), max_degree and
  ef_construction for quantization_bits (0, 4 or 8), graph_degree and
  ef_build, as keywords and as attributes of cp.
- final_assignment takes 'approximate' or 'exact', also on the cp of
  IvfIndex and HnswIndex. FinalAssignmentMode members are still accepted,
  and the attribute still reads back as a member until 0.9.
- KMeansIterationStats is the one name of the statistics class.
  FinalAssignmentMode, QGKMeansIterationStats and
  RaBitQKMeansIterationStats warn when imported or read from the package,
  through a module-level __getattr__.

The extension keeps the 0.8 names; the new ones live in the Python layer,
which 0.9 deletes when the extension is renamed. No 0.8 call changes its
result, its exception type or its error message. The statistics class now
reports its name as KMeansIterationStats.
@github-actions github-actions Bot added the release:added Release category managed from the PR title label Nov 14, 2026
@gouyt13
gouyt13 merged commit 02aeda3 into main Nov 14, 2026
39 checks passed
@gouyt13
gouyt13 deleted the feat/kmeans-09-names branch November 14, 2026 05:49
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.
TamimEhsan pushed a commit to TamimEhsan/khorgosh that referenced this pull request Nov 28, 2026
main is at v0.8.5 (cf2764f): the 0.9 names with deprecation warnings for
the 0.8 spellings (VectorDB-NTU#235, VectorDB-NTU#236) and the 0.8.5 release preparation (VectorDB-NTU#237).

Conflicts, resolved by keeping both sides:
- docs/docs/index/{hnsw,ivf,qg}.md: the cosine metric and the -1
  missing-result ID from dev/0.9, the new names from main.
- python_bindings/__init__.py: the FormatError import from dev/0.9 in
  main's import layout.
- python_bindings/__init__.pyi: cosine in the metric lists, routing for
  initializer.
- tests/python/typing/public_api.py: routing= with the cosine metric type.

Changes git could not make, because the two sides did not touch the same
lines:
- The deprecated search overloads from main return int64 IDs, as every
  search does on dev/0.9; a typing fixture checks it.
- The migration guide said three changes come without a warning in 0.9;
  with int64 IDs, the -1 marker and format 2 that count was wrong.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant