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
12 changes: 6 additions & 6 deletions docarray/array/storage/qdrant/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,21 @@ def _find_similar_vectors(self, q: 'QdrantArrayType', limit=10):

return DocumentArray(docs)

def find(
self, query: 'QdrantArrayType', limit: int = 10
) -> Union['DocumentArray', List['DocumentArray']]:
def _find(
self, query: 'QdrantArrayType', limit: int = 10, **kwargs
) -> List['DocumentArray']:
"""Returns approximate nearest neighbors given a batch of input queries.
:param query: input supported to be used in Qdrant.
:param limit: number of retrieved items

: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`.

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

num_rows, _ = ndarray.get_array_rows(query)

if num_rows == 1:
return self._find_similar_vectors(query, limit=limit)
return [self._find_similar_vectors(query, limit=limit)]
else:
closest_docs = []
for q in query:
Expand Down
3 changes: 2 additions & 1 deletion docarray/array/storage/weaviate/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .... import Document, DocumentArray
from ....math import ndarray
from ....math.helper import EPSILON
from ....math.ndarray import to_numpy_array
from ....score import NamedScore

if TYPE_CHECKING:
Expand All @@ -27,7 +28,7 @@

class FindMixin:
def _find_similar_vectors(self, query: 'WeaviateArrayType', limit=10):

query = to_numpy_array(query)
is_all_zero = np.all(query == 0)
if is_all_zero:
query = query + EPSILON
Expand Down
13 changes: 11 additions & 2 deletions tests/unit/array/mixins/test_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,21 @@ def doc_lists_to_doc_arrays(doc_lists, *args, **kwargs):

@pytest.mark.parametrize(
'storage, config',
[('weaviate', WeaviateConfig(3)), ('pqlite', {'n_dim': 3})],
[('weaviate', {'n_dim': 3}), ('pqlite', {'n_dim': 3}), ('qdrant', {'n_dim': 3})],
)
@pytest.mark.parametrize('limit', [1, 2, 3])
@pytest.mark.parametrize('exclude_self', [True, False])
def test_match(storage, config, doc_lists, limit, exclude_self, start_storage):
@pytest.mark.parametrize('as_tensor', [True, False])
def test_match(
storage, config, doc_lists, limit, exclude_self, start_storage, as_tensor
):
D1, D2 = doc_lists_to_doc_arrays(doc_lists)
if as_tensor:
for d in D1:
d.embedding = torch.from_numpy(d.embedding)

for d in D2:
d.embedding = torch.from_numpy(d.embedding)

if config:
da = DocumentArray(D2, storage=storage, config=config)
Expand Down