docarray.array.document module

class docarray.array.document.DocumentArray(docs=None)[source]

Bases: docarray.array.mixins.AllMixins,

DocumentArray is a mutable sequence of Document. It gives an efficient view of a list of Document. One can iterate over it like a generator but ALSO modify it, count it, get item, or union two ‘DocumentArray’s using the ‘+’ and ‘+=’ operators.

It is supposed to act as a view containing a pointer to a RepeatedContainer of DocumentProto while offering Document Jina native types when getting items or iterating over it


docs (Optional[ForwardRef]) – the document array to construct from. One can also give DocumentArrayProto directly, then depending on the copy, it builds a view or a copy from it. It also can accept a List

insert(index, doc)[source]

Insert doc at index.

  • index (int) – Position of the insertion.

  • doc (Document) – The doc needs to be inserted.

Return type



Append doc in DocumentArray.


doc (Document) – The doc needs to be appended.


Extend the DocumentArray by appending all the items from the iterable.


docs (Iterable[Document]) – the iterable of Documents to extend this array with

Return type



Clear the data of DocumentArray


In-place reverse the sequence.

sort(key, top_k=None, reverse=False)[source]

Sort the items of the DocumentArray in place.

  • key (Callable) – key callable to sort based upon

  • top_k (Optional[int]) – make sure that the first topk elements are correctly sorted rather than sorting the entire list

  • reverse (bool) – reverse=True will sort the list in descending order. Default is False