File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed
Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -618,21 +618,20 @@ def _search_and_filter(
618618
619619 index = self ._hnsw_indices [search_field ]
620620
621- def accept_all (id ):
622- """Accepts all IDs."""
623- return True
624-
625621 def accept_hashed_ids (id ):
626622 """Accepts IDs that are in hashed_ids."""
627623 return id in hashed_ids # type: ignore[operator]
628624
629625 # Choose the appropriate filter function based on whether hashed_ids was provided
630- filter_function = accept_hashed_ids if hashed_ids else accept_all
626+ extra_kwargs = { 'filter' : accept_hashed_ids } if hashed_ids else {}
631627
632628 # If hashed_ids is provided, k is the minimum of limit and the length of hashed_ids; else it is limit
633629 k = min (limit , len (hashed_ids )) if hashed_ids else limit
634-
635- labels , distances = index .knn_query (queries , k = k , filter = filter_function )
630+ try :
631+ labels , distances = index .knn_query (queries , k = k , ** extra_kwargs )
632+ except RuntimeError :
633+ k = min (k , self .num_docs ())
634+ labels , distances = index .knn_query (queries , k = k , ** extra_kwargs )
636635
637636 result_das = [
638637 self ._get_docs_sqlite_hashed_id (
You can’t perform that action at this time.
0 commit comments