Skip to content

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

Merged
tae898 merged 1 commit into
ArcadeData:mainfrom
shaunpatterson:fix/vector-empty-allowed-rids
Nov 22, 2026
Merged

tae898 merged 1 commit into
ArcadeData:mainfrom
shaunpatterson:fix/vector-empty-allowed-rids

Conversation

@shaunpatterson

Copy link
Copy Markdown
Contributor

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.
@tae898
tae898 merged commit 7ad2e13 into ArcadeData:main Nov 22, 2026
45 checks passed
@tae898

tae898 commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Thank you, merged. I reproduced the bug on the published arcadedb 26.11.1.post4 before reading the fix (3 hits with allowed_rids=[]). One note for the release notes: an empty list used to mean "no filter" and now means "no record", so a caller that passed [] for "no filter" has to pass None.

@tae898 tae898 added bug Something isn't working vector Vector indexes and find_nearest labels Nov 22, 2026
@tae898 tae898 added this to the 26.12.1 milestone Nov 22, 2026
tae898 added a commit that referenced this pull request Nov 22, 2026
…ch too, None is the no-filter case (refs #388, #398, #423)

test_an_empty_filter_is_no_filter was written before PR #425 (issue #423) landed on main. Since that PR an empty allowed_rids returns an empty
answer before any library entry is called, so the test read an empty list of calls (IndexError on via_bin.binary[0]) in the parity job against
the installed wheel. It is not an engine-version difference: the answer never reaches the engine.

The no-filter case is now allowed_rids=None (the binary entry gets no pairs, same hits as the JSON route), and a separate test asserts that a
list, a tuple and an empty numpy array give no hits and call no library entry on either route. Run against the CI-built linux-x86_64 wheel
(engine 26.11.1): 22 passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working vector Vector indexes and find_nearest

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