Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix: qdrant can not see index_name
Signed-off-by: jupyterjazz <[email protected]>
  • Loading branch information
jupyterjazz committed Jul 17, 2023
commit b4de962c4c7b62024c9e4b9d57b7931da5a4e965
9 changes: 5 additions & 4 deletions docarray/index/backends/qdrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ class QdrantDocumentIndex(BaseDocIndex, Generic[TSchema]):

def __init__(self, db_config=None, **kwargs):
"""Initialize QdrantDocumentIndex"""
if db_config is not None and getattr(db_config, 'index_name'):
db_config.collection_name = db_config.index_name

super().__init__(db_config=db_config, **kwargs)
self._db_config: QdrantDocumentIndex.DBConfig = cast(
QdrantDocumentIndex.DBConfig, self._db_config
Expand Down Expand Up @@ -101,7 +98,11 @@ def collection_name(self):
'To do so, use the syntax: QdrantDocumentIndex[DocumentType]'
)

return self._db_config.collection_name or default_collection_name
return (
self._db_config.collection_name
or self._db_config.index_name
or default_collection_name
)

@property
def index_name(self):
Expand Down
46 changes: 46 additions & 0 deletions tests/index/qdrant/test_configurations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import numpy as np
import pytest
from pydantic import Field

from docarray import BaseDoc
from docarray.index import QdrantDocumentIndex
from docarray.typing import NdArray
from tests.index.qdrant.fixtures import start_storage, tmp_collection_name # noqa: F401


pytestmark = [pytest.mark.slow, pytest.mark.index]


def test_configure_dim():
class Schema1(BaseDoc):
tens: NdArray = Field(dim=10)

index = QdrantDocumentIndex[Schema1](host='localhost')

docs = [Schema1(tens=np.random.random((10,))) for _ in range(10)]
index.index(docs)

assert index.num_docs() == 10

class Schema2(BaseDoc):
tens: NdArray[20]

index = QdrantDocumentIndex[Schema2](host='localhost')
docs = [Schema2(tens=np.random.random((20,))) for _ in range(10)]
index.index(docs)

assert index.num_docs() == 10


def test_index_name():
class Schema(BaseDoc):
tens: NdArray = Field(dim=10)

index1 = QdrantDocumentIndex[Schema]()
assert index1.index_name == 'schema'

index2 = QdrantDocumentIndex[Schema](index_name='my_index')
assert index2.index_name == 'my_index'

index3 = QdrantDocumentIndex[Schema](collection_name='my_index')
assert index3.index_name == 'my_index'