Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b856b0b

Browse filesBrowse files
fix(qdrant): working with external Qdrant collections #1630 (#1632)
Signed-off-by: Kacper Łukawski <lukawski.kacper@gmail.com>
1 parent 2c12353 commit b856b0b
Copy full SHA for b856b0b

3 files changed

+71-2Lines changed: 71 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docarray/index/backends/qdrant.py‎

Copy file name to clipboardExpand all lines: docarray/index/backends/qdrant.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,11 @@ def _convert_to_doc(
612612
self, point: Union[rest.ScoredPoint, rest.Record]
613613
) -> Dict[str, Any]:
614614
document = cast(Dict[str, Any], point.payload)
615-
generated_vectors = document.pop('__generated_vectors')
615+
generated_vectors = (
616+
document.pop('__generated_vectors')
617+
if '__generated_vectors' in document
618+
else []
619+
)
616620
vectors = point.vector if point.vector else dict()
617621
if not isinstance(vectors, dict):
618622
vectors = {'__default__': vectors}
Collapse file

‎tests/index/qdrant/fixtures.py‎

Copy file name to clipboardExpand all lines: tests/index/qdrant/fixtures.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def tmp_collection_name():
2929
def qdrant() -> qdrant_client.QdrantClient:
3030
"""This fixture takes care of removing the collection before each test case"""
3131
client = qdrant_client.QdrantClient(path='/tmp/qdrant-local')
32-
client.delete_collection(collection_name='documents')
32+
for collection in client.get_collections().collections:
33+
client.delete_collection(collection.name)
3334
return client
3435

3536

Collapse file
+64Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from docarray import BaseDoc
2+
from docarray.index import QdrantDocumentIndex
3+
from docarray.typing import NdArray
4+
from tests.index.qdrant.fixtures import qdrant, qdrant_config # noqa: F401
5+
6+
from qdrant_client.http import models
7+
8+
9+
def test_external_collection_without_generated_vectors(qdrant_config):
10+
class Restaurant(BaseDoc):
11+
city: str
12+
price: float
13+
cuisine_vector: NdArray[4]
14+
15+
qdrant_config.collection_name = 'test'
16+
doc_index = QdrantDocumentIndex[Restaurant](qdrant_config)
17+
qdrant_client = doc_index._client
18+
19+
qdrant_client.recreate_collection(
20+
collection_name='test',
21+
vectors_config={
22+
'cuisine_vector': models.VectorParams(
23+
size=4, distance=models.Distance.COSINE
24+
)
25+
},
26+
)
27+
28+
qdrant_client.upsert(
29+
collection_name='test',
30+
points=[
31+
models.PointStruct(
32+
id=1,
33+
vector={'cuisine_vector': [0.05, 0.61, 0.76, 0.74]},
34+
payload={
35+
'city': 'Berlin',
36+
'price': 1.99,
37+
},
38+
),
39+
models.PointStruct(
40+
id=2,
41+
vector={'cuisine_vector': [0.19, 0.81, 0.75, 0.11]},
42+
payload={
43+
'city': 'Berlin',
44+
'price': 1.99,
45+
},
46+
),
47+
models.PointStruct(
48+
id=3,
49+
vector={'cuisine_vector': [0.36, 0.55, 0.47, 0.94]},
50+
payload={
51+
'city': 'Moscow',
52+
'price': 1.99,
53+
},
54+
),
55+
],
56+
)
57+
58+
results = doc_index.find(
59+
query=[0.36, 0.55, 0.47, 0.94],
60+
search_field='cuisine_vector',
61+
limit=3,
62+
)
63+
64+
assert results is not None

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.