diff --git a/docarray/documents/legacy/__init__.py b/docarray/documents/legacy/__init__.py new file mode 100644 index 00000000000..61cb9c485c1 --- /dev/null +++ b/docarray/documents/legacy/__init__.py @@ -0,0 +1,3 @@ +from docarray.documents.legacy.legacy_document import LegacyDocument + +__all__ = ['LegacyDocument'] diff --git a/docarray/documents/legacy/legacy_document.py b/docarray/documents/legacy/legacy_document.py new file mode 100644 index 00000000000..e3bd0c3b20c --- /dev/null +++ b/docarray/documents/legacy/legacy_document.py @@ -0,0 +1,44 @@ +from __future__ import annotations + +from typing import Any, Dict, Optional + +from docarray import BaseDocument, DocumentArray +from docarray.typing import AnyEmbedding, AnyTensor + + +class LegacyDocument(BaseDocument): + """ + This Document is the LegacyDocument. It follows the same schema as in DocArray v1. + It can be useful to start migrating a codebase from v1 to v2. + + Nevertheless, the API is not totally compatible with DocAray v1 `Document`. + Indeed, none of the method associated with `Document` are present. Only the schema + of the data is similar. + .. code-block:: python + + from docarray import DocumentArray + from docarray.documents.legacy import LegacyDocument + import numpy as np + + doc = LegacyDocument(text='hello') + doc.url = 'http://myimg.png' + doc.tensor = np.zeros((3, 224, 224)) + doc.embedding = np.zeros((100, 1)) + + doc.tags['price'] = 10 + + doc.chunks = DocumentArray[Document]([Document() for _ in range(10)]) + + doc.chunks = DocumentArray[Document]([Document() for _ in range(10)]) + + """ + + tensor: Optional[AnyTensor] + chunks: Optional[DocumentArray[LegacyDocument]] + matches: Optional[DocumentArray[LegacyDocument]] + blob: Optional[bytes] + text: Optional[str] + url: Optional[str] + embedding: Optional[AnyEmbedding] + tags: Dict[str, Any] = dict() + scores: Optional[Dict[str, Any]]