Repository navigation
Description
Summary
VectorIndex.find_nearest(..., allowed_rids=[]) returns the nearest records of the whole index, on both wheels. An empty allow-list is read as "no filter", so a caller that narrows candidates down to nothing and passes the result gets unrestricted hits. The native wheel also disagrees with itself: an empty iterator takes the filter path and returns nothing.
Cause
- JVM (
src/arcadedb/vector.py,_build_allowed_rids_set):if not allowed_rids: return None.Nonemeans no filter. - Native (
src/arcadedb/_native/schema_objects.py,_run_search,_run_search_without_vector,_run_approximate):if allowed_rids:guards thefilteroption. A list is falsy when empty and dropped, while an iterator is always truthy, soiter([])reaches the statement asfilter: [], which the engine answers with no rows. - A numpy array hits the same truth test. An array of two or more RIDs, and an empty one, raise
ValueError: The truth value of an array with more than one element is ambiguous(... of an empty array ...), wrapped inArcadeDBError("Vector search failed: ..."), on both wheels. Theallowed_ridsdocumentation does not exclude arrays, andfind_nearestsays it takes a NumPy array for the query vector.
Reproduction
import tempfile
import arcadedb
print(arcadedb.__backend__, arcadedb.__version__)
with arcadedb.create_database(tempfile.mkdtemp() + "/db") as db:
db.command("sql", "CREATE VERTEX TYPE Doc")
db.command("sql", "CREATE PROPERTY Doc.embedding ARRAY_OF_FLOATS")
index = db.create_vector_index("Doc", "embedding", dimensions=3)
with db.transaction():
for vec in ([1.0, 0.0, 0.0], [0.9, 0.1, 0.0], [0.0, 1.0, 0.0]):
db.command("sql", "INSERT INTO Doc SET embedding = ?", [vec])
query = [1.0, 0.0, 0.0]
print("allowed_rids=None :", len(index.find_nearest(query, k=3)))
print("allowed_rids=[] :", len(index.find_nearest(query, k=3, allowed_rids=[])))
print("allowed_rids=iter :", len(index.find_nearest(query, k=3, allowed_rids=iter([]))))Output (macOS arm64, Python 3.12):
jvm 26.12.1.dev0 (built from main at 0c3c7ec)
allowed_rids=None : 3
allowed_rids=[] : 3
allowed_rids=iter : 3
native 26.11.1.post4
allowed_rids=None : 3
allowed_rids=[] : 3
allowed_rids=iter : 0
Expected
allowed_rids=None is no filter. An empty collection of any kind (list, tuple, iterator, numpy array) allows no record, so the search returns [], a numpy array of RIDs works as a list of them does, and a non-empty list restricts the search to its members (test_lsm_vector_search_with_filter). The same holds for find_nearest_by_key, find_nearest_approximate and include_vector=False, which share the code above.
Activity
shaunpatterson commentedon Nov 21, 2026
One detail of the JVM side, measured on the unfixed code: passing an empty iterator reaches the engine as an empty Java set (
_build_allowed_rids_setonly tests truth, and an iterator is truthy), and the engine'sfindNeighborsFromVectorreturns the whole index for it (3 of 3 above). The native statement answers an emptyfilterwith no rows. So on the JVM wheel the fix has to answer[]in Python and cannot rely on passing the empty set down, which is what the PR does.fix(#423): find_nearest(allowed_rids=[]) returns nothing, and a numpy…
Tests: an empty allowed_rids allows no record on the approximate sear…