Repository navigation
fix(#423): find_nearest(allowed_rids=[]) returns nothing, and a numpy array of RIDs works - #425
Open
shaunpatterson wants to merge 1 commit into
Open
shaunpatterson wants to merge 1 commit into
shaunpatterson wants to merge 1 commit into
Conversation
…nd a numpy array of RIDs works An empty allowed_rids was read as no filter: the JVM wheel dropped it, the native wheel dropped a list but sent an iterator as an empty filter. A numpy array raised on its truth value. None alone means no filter now, every other collection is read as a list, and an empty one returns an empty result.
This branch has not been deployed
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.
What does this PR do?
find_nearest(..., allowed_rids=[])returned the nearest records of the whole index. Both wheels tested the collection for truth, so an empty list meant "no filter". The native wheel also sent an empty iterator as an emptyfilter, which the engine answers with no rows, so the two outcomes depended on the type of the empty collection. A numpy array of two or more RIDs raised "truth value of an array is ambiguous".Now only
Nonemeans no filter. Any other collection is read as a list, and an empty one returns[]without a search:_build_allowed_rids_settests forNone, and_run_searchreturns[]for an empty set._run_searchreads the collection into a list first and returns[]when it is empty; the three helpers below it keep theirif allowed_rids:test, which is now always on a list.how-to/vectors.adocstates the rule.Related issues
Closes #423
Performance changes
None claimed. A search with a non-empty
allowed_ridstakes the same path as before.Docs
how-to/vectors.adoc, "Filtered search":allowed_rids=Noneis no filter and an empty list returns an empty list.Checklist
test_an_empty_allowed_rids_returns_nothingfor a list, a tuple, an iterator and an empty array,test_allowed_rids_accepts_a_numpy_array; on the published native wheel 26.11.1.post4 with the native change copied in, three of the four empty cases fail without it and all pass with it)test_vector.py,test_float_vector_bulk.py,test_vector_hit_records.py,test_find_nearest_query_forms.py, 114 tests before the numpy-array test was added, on the JVM engine;test_vector.py -k allowedon the native package)uvx pre-commit run --files <changed files>passes