docarray.array.mixins.traverse module#
- class docarray.array.mixins.traverse.TraverseMixin[source]#
Bases:
objectA mixin used for traversing
DocumentArray.- traverse(traversal_paths, filter_fn=None)[source]#
Return an Iterator of :class:
TraversableSequenceof the leaves when applying the traversal_paths. Each :class:TraversableSequenceis either the root Documents, a ChunkArray or a MatchArray.- Parameters:
traversal_paths (
str) – a comma-separated string that represents the traversal pathfilter_fn (
Optional[Callable[[Document],bool]]) – function to filter docs during traversal
- Yield:
:class:
TraversableSequenceof the leaves when applying the traversal_paths.
Example on
traversal_paths:r: docs in this TraversableSequence
m: all match-documents at adjacency 1
c: all child-documents at granularity 1
r.[attribute]: access attribute of a multi modal document
cc: all child-documents at granularity 2
mm: all match-documents at adjacency 2
cm: all match-document at adjacency 1 and granularity 1
r,c: docs in this TraversableSequence and all child-documents at granularity 1
r[start:end]: access sub document array using slice
- Return type:
Iterable[T]
- traverse_flat_per_path(traversal_paths, filter_fn=None)[source]#
Returns a flattened :class:
TraversableSequenceper path intraversal_pathswith all Documents, that are reached by the path.- Parameters:
traversal_paths (
str) – a comma-separated string that represents the traversal pathfilter_fn (
Optional[Callable[[Document],bool]]) – function to filter docs during traversal
- Yield:
:class:
TraversableSequencecontaining the document of all leaves per path.
- traverse_flat(traversal_paths, filter_fn=None)[source]#
Returns a single flattened :class:
TraversableSequencewith all Documents, that are reached via thetraversal_paths.Warning
When defining the
traversal_pathswith multiple paths, the returned :class:Documentsare determined at once and not on the fly. This is a different behavior then in :method:traverseand :method:traverse_flattened_per_path!- Parameters:
traversal_paths (
str) – a list of string that represents the traversal pathfilter_fn (
Optional[Callable[[Document],bool]]) – function to filter docs during traversal
- Return type:
- Returns:
a single :class:
TraversableSequencecontaining the document of all leaves when applying the traversal_paths.