Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
2203b0299
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
2203b0299
Commits
1f05c9ca
Unverified
Commit
1f05c9ca
authored
2 years ago
by
David Buchaca Prats
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix(array): consider singleton to return singleton (#286)
parent
d6deafdc
No related branches found
Branches containing commit
Tags
v0.12.9
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
docarray/array/mixins/find.py
+7
-6
7 additions, 6 deletions
docarray/array/mixins/find.py
tests/unit/array/mixins/test_find.py
+20
-4
20 additions, 4 deletions
tests/unit/array/mixins/test_find.py
with
27 additions
and
10 deletions
docarray/array/mixins/find.py
+
7
−
6
View file @
1f05c9ca
...
...
@@ -136,8 +136,7 @@ class FindMixin:
isinstance
(
query
,
list
)
and
isinstance
(
query
[
0
],
str
)
):
result
=
self
.
_find_by_text
(
query
,
index
=
index
,
limit
=
limit
,
**
kwargs
)
if
len
(
result
)
==
1
:
if
isinstance
(
query
,
str
):
return
result
[
0
]
else
:
return
result
...
...
@@ -206,6 +205,7 @@ class FindMixin:
if
len
(
matches
)
>=
_limit
:
break
result
.
append
(
matches
)
else
:
raise
TypeError
(
f
'
unsupported type `
{
type
(
_result
)
}
` returned from `._find()`
'
...
...
@@ -219,10 +219,11 @@ class FindMixin:
else
:
result
[
i
]
=
matches
if
len
(
result
)
==
1
:
return
result
[
0
]
else
:
return
result
# ensures query=np.array([1,2,3]) returns DocumentArray not list with 1 DocumentArray
if
n_dim
==
1
:
result
=
result
[
0
]
return
result
@abc.abstractmethod
def
_find
(
...
...
This diff is collapsed.
Click to expand it.
tests/unit/array/mixins/test_find.py
+
20
−
4
View file @
1f05c9ca
...
...
@@ -31,18 +31,23 @@ def test_find(storage, config, limit, query, start_storage):
da
.
extend
([
Document
(
embedding
=
v
)
for
v
in
embeddings
])
result
=
da
.
find
(
query
,
limit
=
limit
)
n_rows_query
,
_
=
ndarray
.
get_array_rows
(
query
)
n_rows_query
,
n_dim
=
ndarray
.
get_array_rows
(
query
)
# check for each row on the query a DocumentArray is returned
if
n_rows_query
==
1
:
if
n_rows_query
==
1
and
n_dim
==
1
:
# we expect a result to be DocumentArray
assert
len
(
result
)
==
limit
elif
n_rows_query
==
1
and
n_dim
==
2
:
# we expect a result to be a list with 1 DocumentArray
assert
len
(
result
)
==
1
assert
len
(
result
[
0
])
==
limit
else
:
# check for each row on the query a DocumentArray is returned
assert
len
(
result
)
==
n_rows_query
# check returned objects are sorted according to the storage backend metric
# weaviate uses cosine similarity by default
# annlite uses cosine distance by default
if
n_
rows_query
==
1
:
if
n_
dim
==
1
:
if
storage
==
'
weaviate
'
:
cosine_similarities
=
[
t
[
'
cosine_similarity
'
].
value
for
t
in
result
[:,
'
scores
'
]
...
...
@@ -144,6 +149,7 @@ def test_find_by_tag(storage, config, start_storage):
)
results
=
da
.
find
(
'
token1 token2
'
,
index
=
'
attr1
'
)
assert
isinstance
(
results
,
DocumentArray
)
assert
len
(
results
)
==
2
assert
results
[
0
].
id
==
'
1
'
assert
results
[
1
].
id
==
'
2
'
...
...
@@ -176,3 +182,13 @@ def test_find_by_tag(storage, config, start_storage):
assert
len
(
results
)
==
1
assert
results
[
0
].
id
==
'
3
'
assert
all
([
'
token1
'
in
r
.
tags
[
'
attr3
'
]
for
r
in
results
])
==
True
results
=
da
.
find
([
'
token1 token2
'
],
index
=
'
attr1
'
)
assert
isinstance
(
results
,
list
)
assert
len
(
results
)
==
1
assert
isinstance
(
results
[
0
],
DocumentArray
)
results
=
da
.
find
([
'
token1 token2
'
,
'
token1
'
],
index
=
'
attr1
'
)
assert
isinstance
(
results
,
list
)
assert
len
(
results
)
==
2
assert
all
([
isinstance
(
result
,
DocumentArray
)
for
result
in
results
])
==
True
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment