Skip to content

fix(#423): find_nearest(allowed_rids=[]) returns nothing, and a numpy array of RIDs works - #425

Open
shaunpatterson wants to merge 1 commit into
ArcadeData:mainfrom
shaunpatterson:fix/vector-empty-allowed-rids
Open

shaunpatterson wants to merge 1 commit into
ArcadeData:mainfrom
shaunpatterson:fix/vector-empty-allowed-rids

Conversation

@shaunpatterson

Copy link
Copy Markdown

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 empty filter, 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 None means no filter. Any other collection is read as a list, and an empty one returns [] without a search:

  • JVM wheel: _build_allowed_rids_set tests for None, and _run_search returns [] for an empty set.
  • Native wheel: _run_search reads the collection into a list first and returns [] when it is empty; the three helpers below it keep their if allowed_rids: test, which is now always on a list.

how-to/vectors.adoc states the rule.

Related issues

Closes #423

Performance changes

None claimed. A search with a non-empty allowed_rids takes the same path as before.

Docs

how-to/vectors.adoc, "Filtered search": allowed_rids=None is no filter and an empty list returns an empty list.

Checklist

  • A regression test fails on the old code and passes on the new (test_an_empty_allowed_rids_returns_nothing for 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)
  • The test suite that the change can affect passes (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 allowed on the native package)
  • uvx pre-commit run --files <changed files> passes

…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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VectorIndex.find_nearest(allowed_rids=[]) ignores the filter and returns the whole index

2 participants