Skip to content

Crash when using non-class type field in Document with QdrantDocumentIndex #1748

@TerboucheHacene

Description

@TerboucheHacene

Initial Checks

  • I have read and followed the docs and still think this is a bug

Description

I'm encountering an issue when attempting to define an index of type QdrantDocumentIndex for documents that include fields with non-class types (e.g., lists). The error message I'm receiving is as follows:

TypeError: issubclass() arg 1 must be a class

It seems that this error is related to the interaction between the document's fields and the index definition. The error happens in:

if any(issubclass(python_type, vt) for vt in QDRANT_PY_VECTOR_TYPES):

I suggest the following:
if any(safe_issubclass(python_type, vt) for vt in QDRANT_PY_VECTOR_TYPES):

Steps to Reproduce:

  1. Create a Document with a field of non-class type (e.g., a list).
  2. Attempt to define an index of type QdrantDocumentIndex for the created Document.
  3. Observe the TypeError mentioned above.

Example Code

from docarray import DocVec, BaseDoc
from docarray.index import QdrantDocumentIndex

class DocPaper(BaseDoc):
    id: str
    title: str
    abstract: str
    authors: List[str]

host = "localhost"
port = 6333
collection_name = "papers"
qdrant_config = QdrantDocumentIndex.DBConfig(
    host=host, port=port, collection_name=collection_name
)
doc_index = QdrantDocumentIndex[DocPaper](qdrant_config)

Python, Pydantic & OS Version

0.37.0, ubuntu system, Python 3.9.16

Affected Components

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions