Skip to content

Commit

Permalink
fix: update executor parameter (jina-ai#180)
Browse files Browse the repository at this point in the history
* fix: update parameter

* fix: fix import

* fix: fix error

* fix: fix limit

* fix: fix match_args
  • Loading branch information
OrangeSodahub authored and gusye1234 committed Sep 27, 2022
1 parent 0a6254f commit 051171a
Showing 1 changed file with 11 additions and 4 deletions.
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)

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

0 comments on commit 051171a

Please sign in to comment.