docarray.document.mixins.attribute module

class docarray.document.mixins.attribute.GetSetAttributeMixin[source]

Bases: object

Provide helper functions for Document to allow advanced set and get attributes


Bulk fetch Document fields and return a list of the values of these fields


Arguments will be extracted using dunder_get .. highlight:: python .. code-block:: python

d = Document({‘id’: ‘123’, ‘hello’: ‘world’, ‘tags’: {‘id’: ‘external_id’, ‘good’: ‘bye’}})

assert == ‘123’ # true assert d.tags[‘hello’] == ‘world’ # true assert d.tags[‘good’] == ‘bye’ # true assert d.tags[‘id’] == ‘external_id’ # true

res = d.get_attrs_values(*[‘id’, ‘tags__hello’, ‘tags__good’, ‘tags__id’])

assert res == [‘123’, ‘world’, ‘bye’, ‘external_id’]


fields (str) – the variable length values to extract from the document

Return type

Union[Any, List[Any]]


a list with the attributes of this document ordered as the args

update(source, fields=None)[source]

Updates fields specified in fields from the source to current Document.

  • source (~T) – The Document we want to update from as source. The current Document is referred as destination.

  • fields (Optional[List[str]]) – a list of field names that we want to update, if not specified, use all present fields in source.


*. if fields are empty, then all present fields in source will be merged into current document. * tags will be updated like a python dict. *. the current Document will be modified in place, source will be unchanged. *. if current document has more fields than source, these extra fields wll be preserved.

Return type