jina.types.arrays.search_ops module

class jina.types.arrays.search_ops.DocumentArraySearchOpsMixin[source]

Bases: object

A mixin that provides search functionality to DocumentArrays

sample(k, seed=None)[source]

random sample k elements from DocumentArray without replacement.

Parameters
  • k (int) – Number of elements to sample from the document array.

  • seed (Optional[int]) – initialize the random number generator, by default is None. If set will save the state of the random function to produce certain outputs.

Return type

DocumentArray

Returns

A sampled list of Document represented as DocumentArray.

shuffle(seed=None)[source]

Randomly shuffle documents within the DocumentArray.

Parameters

seed (Optional[int]) – initialize the random number generator, by default is None. If set will save the state of the random function to produce certain outputs.

Return type

DocumentArray

Returns

The shuffled list of Document represented as DocumentArray.

split(tag)[source]

Split the DocumentArray into multiple DocumentArray according to the tag value of each Document.

Parameters

tag (str) – the tag name to split stored in tags.

Return type

Dict[Any, ForwardRef]

Returns

a dict where Documents with the same value on tag are grouped together, their orders are preserved from the original DocumentArray.

Note

If the tags of Document do not contains the specified tag, return an empty dict.