Fluent Interface#

Documents provide a simple fluent interface that let you process (often preprocess) a Document object by chaining methods. For example to read an image file as numpy.ndarray, resize it, normalize it and then store it to another file:

from docarray import Document

d = (
    Document(uri='apple.png')
    .load_uri_to_image_tensor()
    .set_image_tensor_shape((64, 64))
    .set_image_tensor_normalization()
    .save_image_tensor_to_file('apple1.png')
)
../../../_images/apple1.png

Original apple.png#

../../../_images/apple11.png

Processed apple1.png#

Note that chaining methods always modifies the original Document in-place. That means the above example is equivalent to:

from docarray import Document

d = Document(uri='apple.png')

(
    d.load_uri_to_image_tensor()
    .set_image_tensor_shape((64, 64))
    .set_image_tensor_normalization()
    .save_image_tensor_to_file('apple1.png')
)

Methods#

All the following methods can be chained.

BlobData#

Provide helper functions for Document to handle binary data.

ImageData#

Provide helper functions for Document to support image data.

Convert#

Provide helper functions for Document to support conversion between tensor, text and blob.

ContentProperty#

Provide helper functions for Document to allow universal content property access.

TextData#

Provide helper functions for Document to support text data.

SingletonSugar#

Provide sugary syntax for Document by inheriting methods from DocumentArray.

FeatureHash#

Provide helper functions for feature hashing.

Porting#

Provide helper functions for Document to convert between serialization types.

Protobuf#

Pydantic#

Provide helper functions to convert to/from a Pydantic model.

Strawberry#

Provide helper functions to convert to/from a Strawberry model.

AudioData#

Provide helper functions for Document to support audio data.

MeshData#

Provide helper functions for Document to support 3D mesh data and point cloud.

VideoData#

Provide helper functions for Document to support video data.

UriFile#

Provide helper functions for Document to dump content to a file.