FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

chore: refactor filter in hnswlib by JoanFM · Pull Request #1728 · docarray/docarray · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 2 additions & 6 deletions docarray/index/backends/hnswlib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -619,21 +619,17 @@ def _search_and_filter(

index = self._hnsw_indices[search_field]

def accept_all(id):
"""Accepts all IDs."""
return True

def accept_hashed_ids(id):
"""Accepts IDs that are in hashed_ids."""
return id in hashed_ids # type: ignore[operator]

# Choose the appropriate filter function based on whether hashed_ids was provided
filter_function = accept_hashed_ids if hashed_ids else accept_all
extra_kwargs = {'filter': accept_hashed_ids} if hashed_ids else {}

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

labels, distances = index.knn_query(queries, k=k, filter=filter_function)
labels, distances = index.knn_query(queries, k=k, **extra_kwargs)

result_das = [
self._get_docs_sqlite_hashed_id(
Expand Down

Back | FazBrowse Home | New Git URL