Repository navigation
fix(samples): accept cosine and reject unknown metrics in the indexing examples - #250
Merged
Merged
Conversation
…g examples ivf_rabitq_indexing, hnsw_rabitq_indexing and symqg_indexing built an L2 index for every metric argument other than "ip", including "cosine". They now accept l2, ip and cosine (also uppercase) and reject anything else before reading any file. The index check helper learns "cosine", and the example tests build and check cosine indexes and cover the rejection.
Mention cosine where pages listed only L2 and inner product, replace statements that updates keep the file format (every save writes index format 2), note that HNSW set_centroids takes no num_threads, add the OMP_NUM_THREADS cap to SymphonyQG search threads and the 1..2^31 range of k to the parameter tables. In the README, HNSW lists reserve instead of the removed resize, and the migration links point to the 0.9 guide.
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
Examples.
ivf_rabitq_indexing,hnsw_rabitq_indexingandsymqg_indexingbuilt an L2 index for every metric argument other thanip/IP, includingcosine, although the index options acceptMETRIC_COSINE. They now acceptl2,ipandcosine(also uppercase) and throwMetric type must be l2, ip or cosinefor anything else, before reading any file. The printed label addsCosine;L2andIPare unchanged.tests/integration/cpp_example_index_check.cpplearnscosine.Docs on
dev/0.9, corrected against the code:index.md, the IVF routing paragraph,rabitq/rabitq.md). Every IVF routing choice works with cosine, which the index stores as inner product.savealways writes index format 2". The HNSW removal-compatibility paragraph is limited to the pre-0.9 layout and names 0.5.2, the release that added removal.set_centroidstakes nonum_threads. SymphonyQG search withnum_threads=0is capped byOMP_NUM_THREADSand the number of queries.kas 1 to 2^31, the range the Python bindings and the C++ classes enforce.reserveinstead of the removedresize. The quick-start migration pointer goes to "From 0.8 to 0.9", and "Further reading" adds the Python migration guide.modular_migration.md: themax_elementssentence is in the past tense.Found during a pre-release check of
dev/0.9.Testing
Local, Linux x86-64, GCC 14, Release,
RABITQ_BUILD_SAMPLES=ON,RABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF:RABITQ_REQUIRE_CPP_EXAMPLES=1 python -m pytest tests/python/test_cpp_clustering_examples.py: 23 passed. New cases: IVF and HNSW examples build cosine indexes that the check helper verifies (metric, counts, self-retrieval), and all three indexing examples rejectdotwithout creating the index file.dev/0.9examples, with the new helper and tests, the 5 new cases fail and the other 18 pass../scripts/check-format.sh,./scripts/check-python.sh,mkdocs build --strict,git diff --check.k = 2**31is accepted and 0 or2**31 + 1raiseValueErroron all three Python classes; a cosineIvfIndexfinds each point itself withauto,flat,flat_rabitqandhnswrouting.clang-tidy was not run: CI excludes examples and tests from it, and no library or binding code changes.