Skip to content

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

Closed

Description

@shaunpatterson

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. None means no filter.
  • Native (src/arcadedb/_native/schema_objects.py, _run_search, _run_search_without_vector, _run_approximate): if allowed_rids: guards the filter option. A list is falsy when empty and dropped, while an iterator is always truthy, so iter([]) reaches the statement as filter: [], 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 in ArcadeDBError("Vector search failed: ..."), on both wheels. The allowed_rids documentation does not exclude arrays, and find_nearest says 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

  1. added
    native
    python
    vector
    on Nov 21, 2026
  2. added this to the 26.12.1 milestone on Nov 21, 2026
  3. added
    in progress
    on Nov 21, 2026
  4. shaunpatterson commented on Nov 21, 2026

    @shaunpatterson
    ContributorAuthor

    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_set only tests truth, and an iterator is truthy), and the engine's findNeighborsFromVector returns the whole index for it (3 of 3 above). The native statement answers an empty filter with 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.

  5. added a commit that references this issue on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in progressnativepythonvector

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions