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 4cd5850

Browse filesBrowse files
author
Joan Fontanals
authored
fix: collection and index name in qdrant (#1723)
Signed-off-by: Joan Fontanals Martinez <joan.martinez@jina.ai>
1 parent 304a4e9 commit 4cd5850
Copy full SHA for 4cd5850

2 files changed

+44-5Lines changed: 44 additions & 5 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
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class QdrantDocumentIndex(BaseDocIndex, Generic[TSchema]):
6767

6868
def __init__(self, db_config=None, **kwargs):
6969
"""Initialize QdrantDocumentIndex"""
70+
if db_config is not None and getattr(
71+
db_config, 'index_name'
72+
): # this is needed for subindices
73+
db_config.collection_name = db_config.index_name
7074
super().__init__(db_config=db_config, **kwargs)
7175
self._db_config: QdrantDocumentIndex.DBConfig = cast(
7276
QdrantDocumentIndex.DBConfig, self._db_config
@@ -98,11 +102,7 @@ def collection_name(self):
98102
'To do so, use the syntax: QdrantDocumentIndex[DocumentType]'
99103
)
100104

101-
return (
102-
self._db_config.collection_name
103-
or self._db_config.index_name
104-
or default_collection_name
105-
)
105+
return self._db_config.collection_name or default_collection_name
106106

107107
@property
108108
def index_name(self):
@@ -250,6 +250,12 @@ class DBConfig(BaseDocIndex.DBConfig):
250250
}
251251
)
252252

253+
def __post_init__(self):
254+
if self.collection_name is None and self.index_name is not None:
255+
self.collection_name = self.index_name
256+
if self.index_name is None and self.collection_name is not None:
257+
self.index_name = self.collection_name
258+
253259
@dataclass
254260
class RuntimeConfig(BaseDocIndex.RuntimeConfig):
255261
"""Dataclass that contains all "dynamic" configurations of QdrantDocumentIndex."""
Collapse file

‎tests/index/qdrant/test_subindex.py‎

Copy file name to clipboardExpand all lines: tests/index/qdrant/test_subindex.py
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,36 @@ def test_subindex_contain(index):
222222
# Empty index
223223
empty_index = QdrantDocumentIndex[MyDoc]()
224224
assert (empty_doc in empty_index) is False
225+
226+
227+
def test_subindex_collections():
228+
from typing import Optional
229+
from docarray.typing.tensor import AnyTensor
230+
from pydantic import Field
231+
232+
class MetaPathDoc(BaseDoc):
233+
path_id: str
234+
level: int
235+
text: str
236+
embedding: Optional[AnyTensor] = Field(space='cosine', dim=128)
237+
238+
class MetaCategoryDoc(BaseDoc):
239+
node_id: Optional[str]
240+
node_name: Optional[str]
241+
name: Optional[str]
242+
product_type_definitions: Optional[str]
243+
leaf: bool
244+
paths: Optional[DocList[MetaPathDoc]]
245+
embedding: Optional[AnyTensor] = Field(space='cosine', dim=128)
246+
channel: str
247+
lang: str
248+
249+
db_config = QdrantDocumentIndex.DBConfig(
250+
host='localhost',
251+
collection_name="channel_category",
252+
)
253+
254+
doc_index = QdrantDocumentIndex[MetaCategoryDoc](db_config)
255+
256+
assert doc_index._subindices["paths"].index_name == 'channel_category__paths'
257+
assert doc_index._subindices["paths"].collection_name == 'channel_category__paths'

0 commit comments

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