Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions docarray/documents/legacy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from docarray.documents.legacy.legacy_document import LegacyDocument

__all__ = ['LegacyDocument']
44 changes: 44 additions & 0 deletions docarray/documents/legacy/legacy_document.py
Original file line number Diff line number Diff line change
@@ -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]]