Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions docarray/array/mixins/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def find(

:return: a list of DocumentArrays containing the closest Document objects for each of the queries in `query`.
"""

index_da = self._get_index(subindex_name=on)
if index_da is not self:
return index_da.find(
Expand All @@ -145,7 +144,6 @@ def find(
index,
on=None,
)

from docarray import Document, DocumentArray

if isinstance(query, dict):
Expand Down
2 changes: 1 addition & 1 deletion docarray/array/storage/elastic/backend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import copy
import uuid
from dataclasses import dataclass, field, asdict
from dataclasses import dataclass, field
import warnings

from typing import (
Expand Down
2 changes: 0 additions & 2 deletions docarray/array/storage/elastic/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def _find_similar_vectors(
:return: DocumentArray containing the closest documents to the query if it is a single query, otherwise a list of DocumentArrays containing
the closest Document objects for each of the queries in `query`.
"""

query = to_numpy_array(query)
is_all_zero = np.all(query == 0)
if is_all_zero:
Expand Down Expand Up @@ -151,7 +150,6 @@ def _find_with_filter(self, query: Dict, limit: Optional[Union[int, float]] = 20
query=query,
size=limit,
)

list_of_hits = resp['hits']['hits']

da = DocumentArray()
Expand Down
71 changes: 71 additions & 0 deletions tests/unit/array/storage/elastic/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,74 @@ def _mock_knn_search(**kwargs):
np_query = np.array([2, 1, 3])

elastic_doc.find(np_query, limit=10, num_candidates=num_candidates)


def test_filter(start_storage):
import random
import string

elastic_da = DocumentArray(
storage='elasticsearch',
config={
'n_dim': 2,
'columns': {
'A': 'str',
'B': 'str',
'V': 'str',
'D': 'str',
'E': 'str',
'F': 'str',
'G': 'str',
},
},
)

def ran():
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))

def ran_size():
sizes = ['S', 'M', 'L', 'XL']
return sizes[random.randint(0, len(sizes) - 1)]

def ran_type():
types = ['A', 'B', 'C', 'D']
return types[random.randint(0, len(types) - 1)]

def ran_stype():
stypes = ['SA', 'SB', 'SC', 'SD']
return stypes[random.randint(0, len(stypes) - 1)]

docs = DocumentArray(
[
Document(
id=f'r{i}',
embedding=np.random.rand(2),
tags={
'A': ran(),
'B': ran_stype(),
'C': ran_size(),
'D': ran_type(),
'E': ran(),
'F': ran_type(),
'G': f'G{i}',
},
)
for i in range(50)
]
)

with elastic_da:
elastic_da.extend(docs)

res = elastic_da.find(query=Document(embedding=docs[0].embedding))
assert len(res) > 0
assert res[0][0].tags['G'] == 'G0'
filter_ = {'match': {'G': 'G3'}}

res = elastic_da.find(filter=filter_)
assert len(res) > 0
assert res[0].tags['G'] == 'G3'

res = elastic_da.find(query=Document(embedding=docs[0].embedding), filter=filter_)
assert len(res) > 0
assert res[0][0].tags['G'] == 'G3'