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
6 changes: 3 additions & 3 deletions docarray/predefined_document/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Image(BaseDocument):
image = Image(url='http://www.jina.ai/image.jpg')
image.tensor = image.url.load()
model = MyEmbeddingModel()
image.embedding = MyEmbeddingModel(image.tensor)
image.embedding = model(image.tensor)

You can extend this Document:

Expand All @@ -40,8 +40,8 @@ class MyImage(Image):
image = MyImage(url='http://www.jina.ai/image.jpg')
image.tensor = image.url.load()
model = MyEmbeddingModel()
image.embedding = MyEmbeddingModel(image.tensor)
image.second_embedding = MyEmbeddingModel(image.tensor)
image.embedding = model(image.tensor)
image.second_embedding = model(image.tensor)


You can use this Document for composition:
Expand Down
65 changes: 60 additions & 5 deletions docarray/predefined_document/text.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,69 @@
from typing import Optional

from docarray.document import BaseDocument
from docarray.typing.tensor.embedding import Embedding, Tensor
from docarray.typing import TextUrl
from docarray.typing.tensor.embedding import Embedding


class Text(BaseDocument):
"""
base Document for Text handling
Document for handling text.
It can contain a TextUrl (`Text.url`), a str (`Text.text`),
and an Embedding (`Text.embedding`).

EXAMPLE USAGE:

You can use this Document directly:

.. code-block:: python

from docarray import Text

# use it directly
txt_doc = Text(url='http://www.jina.ai/')
txt_doc.text = txt_doc.url.load()
model = MyEmbeddingModel()
txt_doc.embedding = model(txt_doc.text)

You can extend this Document:

.. code-block:: python

from docarray import Text
from docarray.typing import Embedding
from typing import Optional

# extend it
class MyText(Text):
second_embedding: Optional[Embedding]


txt_doc = MyText(url='http://www.jina.ai/')
txt_doc.text = txt_doc.url.load()
model = MyEmbeddingModel()
txt_doc.embedding = model(txt_doc.text)
txt_doc.second_embedding = model(txt_doc.text)


You can use this Document for composition:

.. code-block:: python

from docarray import Document, Image, Text

# compose it
class MultiModalDoc(Document):
image_doc: Image
text_doc: Text


mmdoc = MultiModalDoc(
image_doc=Image(url="http://www.jina.ai/image.jpg"),
text_doc=Text(text="hello world, how are you doing?"),
)
mmdoc.text_doc.text = mmdoc.text_doc.url.load()
"""

text: str = ''
tensor: Optional[Tensor]
embedding: Optional[Embedding]
text: Optional[str] = None
url: Optional[TextUrl] = None
embedding: Optional[Embedding] = None