docarray.array.mixins.find module#
- class docarray.array.mixins.find.FindMixin[source]#
Bases:
object
A mixin that provides find functionality to DocumentArrays
Subclass should override
_find()
notfind()
.- find(query: Union[Document, DocumentArray, ArrayType], metric: Union[str, Callable[[ArrayType, ArrayType], np.ndarray]] = 'cosine', limit: Optional[Union[int, float]] = 20, metric_name: Optional[str] = None, exclude_self: bool = False, only_id: bool = False, **kwargs) Union[DocumentArray, List[DocumentArray]] [source]#
- find(query: Dict, **kwargs) DocumentArray
Returns matching Documents given an input query. If the query is a DocumentArray, Document or ArrayType, exhaustive or approximate nearest neighbor search will be performed depending on whether the storage backend supports ANN. If the query is a dict object, Documents will be filtered according to DocArray’s query language and all matching Documents that match the filter will be returned. If the query is a string or list of strings, a search by text will be performed if the backend supports indexing and searching text fields. If not, a NotImplementedError will be raised.
- Parameters
query (
Union
[ForwardRef
,ForwardRef
,ForwardRef
,Dict
,str
,List
[str
]]) – the input query to search bylimit (
Union
[int
,float
,None
]) – the maximum number of matches, when not given defaults to 20.metric_name (
Optional
[str
]) – if provided, then match result will be marked with this string.metric (
Union
[str
,Callable
[[ForwardRef
,ForwardRef
],ForwardRef
]]) – the distance metric.exclude_self (
bool
) – if set, Documents in results with sameid
as the query values will not be considered as matches. This is only applied when the input query is Document or DocumentArray.only_id (
bool
) – if set, then returning matches will only containid
index (
str
) – if the query is a string, text search will be performed on the index field, otherwise, this parameter is ignored. By default, the Document text attribute will be used for search, otherwise the tag field specified by index will be used. You can only use this parameter if the storage backend supports searching by text.kwargs – other kwargs.
- Return type
Union
[ForwardRef
,List
[ForwardRef
]]- Returns
a list of DocumentArrays containing the closest Document objects for each of the queries in query.