diff --git a/docarray/predefined_document/image.py b/docarray/predefined_document/image.py index 4e6db086f54..185a7a32bf7 100644 --- a/docarray/predefined_document/image.py +++ b/docarray/predefined_document/image.py @@ -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: @@ -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: diff --git a/docarray/predefined_document/text.py b/docarray/predefined_document/text.py index f02586190f1..cc73bb783ae 100644 --- a/docarray/predefined_document/text.py +++ b/docarray/predefined_document/text.py @@ -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