Skip to content

find doesn't return DocList with same doc_type as index #1445

@wizrds

Description

@wizrds

When using find, the DocList returned in the FindResult doesn't keep the same doc_type as the index. Is this intended? It would be a nice QOL to use specific attributes for all of the matches such as .text.

Python version: 3.11.2
Docarray version: 0.30.0

Reproducible example:

import numpy
from docarray import DocList, BaseDoc
from docarray.typing import NdArray
from docarray.utils.find import find


class Text(BaseDoc):
    embedding: NdArray[128]
    text: str


if __name__ == "__main__":
    store = DocList[Text](
        [Text(embedding=numpy.random.rand(128), text="Hello, world!") for i in range(10)]
    )
    query = Text(embedding=numpy.random.rand(128), text="Random query")

    matches, scores = find(
        index=store,
        query=query,
        search_field="embedding",
        limit=3
    )

    print(matches.doc_type, store.doc_type)
    # Fails on print(matches.text)

Output <class 'docarray.base_doc.any_doc.AnyDoc'> <class '__main__.Text'>

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions