Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update executor parameter #180

Merged
merged 6 commits into from
Sep 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions annlite/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AnnLiteIndexer(Executor):
:param n_dim: Dimensionality of vectors to index
:param metric: Distance metric type. Can be 'euclidean', 'inner_product', or 'cosine'
:param limit: Number of results to get for each query document in search
:param match_args: the arguments to `DocumentArray`'s match function
:param data_path: the workspace of the AnnLiteIndexer.
:param ef_construction: The construction time/accuracy trade-off
:param ef_search: The query time accuracy/speed trade-off
Expand All @@ -37,6 +38,7 @@ def __init__(
n_dim: int = 0,
metric: str = 'cosine',
limit: int = 10,
match_args: Optional[Dict] = None,
data_path: Optional[str] = None,
ef_construction: Optional[int] = None,
ef_search: Optional[int] = None,
Expand All @@ -58,8 +60,10 @@ def __init__(
raise ValueError('Please specify the dimension of the vectors to index!')

self.metric = metric
self.limit = limit
self.match_args = match_args or {}
self.include_metadata = include_metadata
if limit:
self.match_args.update({'limit': limit})

self.index_access_paths = index_access_paths
if 'index_traversal_paths' in kwargs:
Expand Down Expand Up @@ -250,10 +254,13 @@ def search(
if not docs:
return

limit = int(parameters.get('limit', self.limit))
search_filter = parameters.get('filter', None)
access_paths = parameters.get('access_paths', self.search_access_paths)
flat_docs = docs[access_paths]
match_args = (
{**self.match_args, **parameters}
if parameters is not None
else self.match_args
)

with self._index_lock:
if len(self._data_buffer) > 0:
Expand All @@ -262,7 +269,7 @@ def search(
'Please wait for the pending documents to be indexed.'
)

flat_docs.match(self._index, filter=search_filter, limit=limit)
flat_docs.match(self._index, **match_args)
numb3r3 marked this conversation as resolved.
Show resolved Hide resolved

@requests(on='/filter')
def filter(self, parameters: Dict, **kwargs):
Expand Down