Repository navigation
feat(python)!: accept only "ip" as the inner-product metric name - #241
Merged
Merged
Conversation
The index classes and rabitqlib.quant accepted "innerproduct" as a second spelling of "ip"; index.metric and quant.Query.metric always report "ip". For 0.9, which spells each concept one way (#232), the shared metric parser drops the alias, so metric="innerproduct" raises ValueError with the existing messages. 0.8.5 accepted it without a warning, so the release notes and the migration guide list it with the changes that come without one. The stubs, docstrings, quick start and the clustering sample CLI drop the alias too. Tests that used it now pass "ip"; a new test checks that the three index classes and quant.Query, query_terms and code_factors reject it, and the typing fixture checks that mypy and Pyright reject it.
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.
Part of #232.
Summary
The index classes and
rabitqlib.quantaccepted"innerproduct"as a second spelling of"ip", whileindex.metricandquant.Query.metricalways report"ip". 0.9 spells each concept one way, so the shared metric parser (metric_from_stringandindex_metric_from_stringinpython_bindings/bindings_common.hpp) drops the alias.metric="innerproduct"raisesValueErrorwith the existing messages:metric must be 'l2', 'ip' or 'cosine'fromIvfIndex,HnswIndexandSymqgIndex;metric must be 'l2' or 'ip'fromquant.Query,quant.query_termsandquant.code_factors."ip","l2"and"cosine"are unchanged. Loaded files store a metric code, not the string, soindex.metricof every loaded file is unchanged.sample/python/clustering_cli/ivf.py) drop the alias.Behaviour change
0.8.5 accepted
"innerproduct"without a deprecation warning. The release notes therefore list it under the changes 0.8.5 did not announce. The migration guide adds it to the paragraph of changes that come without a warning, not to the table of 0.8.5 deprecations. txtai passesmetric="ip".rabitqlib.quantis included because it shares the parser and is provisional; #232 names both.Tests
test_innerproduct_is_no_longer_a_metric_nameintests/python/test_removed_forms.pychecks the rejection on the three index classes and onquant.Query,query_termsandcode_factors. Against the previous build each of these calls is accepted, so the test fails there.IvfIndex(64, 1, metric="innerproduct"). With the previous stubs, mypy reports thetype: ignoreon that line as unused."innerproduct"(test_index_repr.py,test_examples.py) now pass"ip".Verification
Local, Linux x86-64, Python 3.13, scratch wheel of this commit:
pytest: 1178 passed, 18 skipped. 16 of the skips aretest_cpp_clustering_examples.py, which needs the C++ example binaries inbin/; the other 2 are the macOS and Linux ARM64 wheel tests.test_editor_support.py,test_mypy.py,test_pyright.py: 18 passed.check-python.sh,check-format.sh, fullcheck-tidy.sh(clang-tidy 23),mkdocs build --strict,git diff --check.