Skip to content

Python index API consistency: capacity, seed, search arguments, routing, ef_search #232

Closed

Description

@gouyt13

Problem

Since 0.8.2 the three index classes share one workflow (construct, add, search), but some
names and defaults still differ between them, and two search conventions hide mistakes:

  • max_elements is documented as one "logical record capacity" on all three classes (the
    unified count properties of 0.7.0), but it is an allocated capacity only on HnswIndex. On
    IvfIndex and SymqgIndex it always equals num_stored_points.
  • Preallocation is HnswIndex.resize(max_elements) on one class and
    IvfIndex.reserve(cluster_id, num_points) on another.
  • seed defaults to None (draw one) on IvfIndex and SymqgIndex and to 100 on
    HnswIndex, which also accepts 64-bit seeds where the other two accept 32-bit seeds.
  • The fourth positional argument of search is high_accuracy on IvfIndex and
    num_threads on the graph indexes, so search(queries, k, 64, 8) means different things.
  • nprobe=0 and ef=0 select the default, so a computed 0 silently becomes
    num_clusters / 16 or max(k, 64).
  • IvfIndex(initializer=...) selects what the documentation calls the centroid routing
    strategy, while SymqgIndex(init=...) is an unrelated graph initialization.
  • The graph indexes call their search breadth ef. Its construction counterpart is
    ef_construction, and the C++ library and the k-means classes call the same setting
    ef_search.

0.9 already breaks the Python API (#211, #213), so these are fixed in the same release
instead of in a second breaking release.

Proposal

# 0.8 0.9 Spelling valid in both
1a IvfIndex.max_elements, SymqgIndex.max_elements Removed num_stored_points
1b HnswIndex.max_elements HnswIndex.capacity From the transition release
1c HnswIndex.resize(max_elements) HnswIndex.reserve(num_points): room for at least that many stored points; it only grows From the transition release
1d IvfIndex.reserve(cluster_id, num_points) IvfIndex.reserve_cluster(cluster_id, num_points), with the same meaning (the total the cluster can hold) From the transition release
2a HnswIndex(seed=100) by default seed=None draws one, as on the other two classes Pass seed=
2b HnswIndex accepts a seed in [0, 2**64 - 1] [0, 2**32 - 1], as on the other two classes A 32-bit seed
3 nprobe=0 and ef=0 select the default ValueError; None selects the default None, or omit the argument
4 search(queries, k, nprobe, high_accuracy, num_threads) and search(queries, k, ef, num_threads) accept every option by position Only the breadth stays positional: search(queries, k, nprobe=None, *, high_accuracy=None, num_threads=None) and search(queries, k, ef_search=None, *, num_threads=None) Keywords
5 IvfIndex(initializer=...) and the initializer property IvfIndex(routing=...) and a routing property, with the same values; the property keeps reporting the resolved strategy, never 'auto' From the transition release
6 search(queries, k, ef=...) on HnswIndex and SymqgIndex search(queries, k, ef_search=...), the name C++ and the k-means classes already use By position; ef_search= from the transition release

Details:

  • Row 1 retires max_elements from the count properties. num_points <= num_stored_points
    stays on all three classes, and num_stored_points <= capacity on HnswIndex.
  • Row 2a changes results for code that relied on the fixed default: the rotation, the graph
    levels and the trained centroids (cp.seed follows the index seed). Pass seed=, with
    num_threads=1, for a reproducible build as today.
  • Row 3 leaves num_threads=0 meaning "every available CPU", and a breadth below k is
    still raised to k.
  • Row 6 amends the naming contract in docs/development.md, which lists Python's ef among
    the spellings to retain.
  • repr() prints capacity= and routing= where it prints max_elements= and
    initializer= today.

Transition

The next 0.8.x release accepts both spellings: it adds capacity, HnswIndex.reserve,
reserve_cluster, routing and ef_search, and raises DeprecationWarning for the 0.8
forms of rows 1, 2b, 3, 4, 5 and 6. 0.9 removes those forms, and each then fails with a plain TypeError,
AttributeError or ValueError, not a silent reinterpretation. Row 2a gets no warning: one
on every HnswIndex() without a seed would reach mostly users who need no change, so it is
announced in the release notes only.

The migration guide gets a
"0.8 to 0.9" section with these rows, and its 0.7-to-0.8 table stops recommending
initializer= and resize.

Compatibility

Checked against txtai master (5dddded, 2026-11-13):

  • Row 3 needs a backend change: self.backend.search(queries, k, self.setting("efsearch", None) or 0) (src/python/txtai/ann/dense/rabitq.py:133) passes 0 for "no setting" and
    must pass None.
  • Row 1 needs a test change: test/python/testann/testdense/testrabitq.py:145 asserts
    native.max_elements == 100 on a loaded IvfIndex and a loaded HnswIndex;
    num_stored_points works before and after.
  • Rows 2, 4, 5 and 6 need none: txtai passes its HNSW seed explicitly (100 by default),
    passes nprobe and ef by position with nothing after them, does not pass initializer,
    and does not call resize or reserve.

Both changes belong in the txtai release that #213 waits for, and join its gate.

In this repository the renames touch the Python tests, benchmarks/run.py, the samples and
the index documentation: 29 reads of max_elements, 20 resize calls, 10 reserve calls
and 59 ef= keyword arguments outside the 0.7 compatibility tests that #213 deletes.

Open questions

  • Does anyone rely on HnswIndex.resize shrinking the capacity? reserve does not shrink.
  • Should metric drop the 'innerproduct' spelling, on the index classes and in
    rabitqlib.quant, and keep 'l2', 'ip' and 'cosine'?

Activity

  1. added this to the 0.9 milestone on Nov 13, 2026
  2. added
    enhancement
    python
    on Nov 13, 2026
  3. gouyt13 commented on Nov 14, 2026

    @gouyt13
    MemberAuthor

    Progress: #239 (open, targets dev/0.9) implements every row of the proposal in the extension itself and removes the 0.8 forms: capacity and reserve on HnswIndex, reserve_cluster and routing on IvfIndex, ef_search, keyword-only high_accuracy and num_threads, ValueError for nprobe=0 and ef_search=0, and a drawn 32-bit seed for HnswIndex(). The migration guide has the "From 0.8 to 0.9" section.

    On the open questions:

    The renames need no further contribution. This issue stays open until 0.9 is released.

  4. gouyt13 commented on Nov 19, 2026

    @gouyt13
    MemberAuthor

    Update: #239, listed as open in the progress comment above, was merged into dev/0.9 on 2026-11-14 (3685e81). This issue stays open until 0.9 is released.

  5. gouyt13 commented on Nov 23, 2026

    @gouyt13
    MemberAuthor

    Released in 0.9.0: the 0.8 spellings that 0.8.5 deprecated are removed, so capacity, seed, routing and ef_search are the only names. The migration guide lists each change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpython

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions