Skip to content

Commit 24143a1

Browse files
author
Joan Fontanals
authored
chore: refactor filter in hnswlib (#1728)
Signed-off-by: Joan Fontanals Martinez <joan.martinez@jina.ai>
1 parent efeab90 commit 24143a1

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

docarray/index/backends/hnswlib.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,21 +619,17 @@ def _search_and_filter(
619619

620620
index = self._hnsw_indices[search_field]
621621

622-
def accept_all(id):
623-
"""Accepts all IDs."""
624-
return True
625-
626622
def accept_hashed_ids(id):
627623
"""Accepts IDs that are in hashed_ids."""
628624
return id in hashed_ids # type: ignore[operator]
629625

630626
# Choose the appropriate filter function based on whether hashed_ids was provided
631-
filter_function = accept_hashed_ids if hashed_ids else accept_all
627+
extra_kwargs = {'filter': accept_hashed_ids} if hashed_ids else {}
632628

633629
# If hashed_ids is provided, k is the minimum of limit and the length of hashed_ids; else it is limit
634630
k = min(limit, len(hashed_ids)) if hashed_ids else limit
635631

636-
labels, distances = index.knn_query(queries, k=k, filter=filter_function)
632+
labels, distances = index.knn_query(queries, k=k, **extra_kwargs)
637633

638634
result_das = [
639635
self._get_docs_sqlite_hashed_id(

0 commit comments

Comments
 (0)