Class VectorSearchOperation
java.lang.Object
org.springframework.data.mongodb.core.aggregation.VectorSearchOperation
- All Implemented Interfaces:
AggregationOperation
Performs a semantic search on data in your Atlas cluster. This stage is only available for Atlas Vector Search.
Vector data must be less than or equal to 4096 dimensions in width.
Limitations
You cannot use this stage together with:- Since:
- 4.5
- Author:
- Christoph Strobl, Mark Paluch
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Fluent API to configure a limit on the VectorSearchOperation builder.static interface
Fluent API to configure a path on the VectorSearchOperation builder.static interface
Interface describing a query path contract.static class
Value object capturing query paths.static enum
Search type, ANN as approximation or ENN for exact search.static class
static interface
Fluent API to configure a vector on the VectorSearchOperation builder. -
Method Summary
Modifier and TypeMethodDescriptionfilter
(org.bson.Document filter) Criteria expression that compares an indexed field with a boolean, date, objectId, number (not decimals), string, or UUID to use as a pre-filter.filter
(CriteriaDefinition filter) Criteria expression that compares an indexed field with a boolean, date, objectId, number (not decimals), string, or UUID to use as a pre-filter.Return the MongoDB operator that is used for thisAggregationOperation
.numCandidates
(int numCandidates) Number of nearest neighbors to use during the search.Entrypoint to build aVectorSearchOperation
starting from theindex
name to search.searchType
(VectorSearchOperation.SearchType searchType) Configure the search type to use.org.bson.Document
toDocument
(AggregationOperationContext context) List
<org.bson.Document> withFilterBySore
(Consumer<Criteria> score) Add aMatchOperation
stage targeting the score field name.Add aAddFieldsOperation
stage including the search score usingscore
as field name.withSearchScore
(String scoreFieldName) Add aAddFieldsOperation
stage including the search score usingscoreFieldName
as field name.
-
Method Details
-
search
Entrypoint to build aVectorSearchOperation
starting from theindex
name to search. Atlas Vector Search doesn't return results if you misspell the index name or if the specified index doesn't already exist on the cluster.- Parameters:
index
- must not be null or empty.- Returns:
- new instance of
VectorSearchOperation.PathContributor
.
-
searchType
@Contract("_ -> new") public VectorSearchOperation searchType(VectorSearchOperation.SearchType searchType) Configure the search type to use.VectorSearchOperation.SearchType.ENN
leads to an exact search whileVectorSearchOperation.SearchType.ANN
usesexact=false
.- Parameters:
searchType
- must not be null.- Returns:
- a new
VectorSearchOperation
withVectorSearchOperation.SearchType
applied.
-
filter
Criteria expression that compares an indexed field with a boolean, date, objectId, number (not decimals), string, or UUID to use as a pre-filter.Atlas Vector Search supports only the filters for the following MQL match expressions:
- $gt
- $lt
- $gte
- $lte
- $eq
- $ne
- $in
- $nin
- $nor
- $not
- $and
- $or
- Parameters:
filter
- must not be null.- Returns:
- a new
VectorSearchOperation
withCriteriaDefinition
applied.
-
filter
Criteria expression that compares an indexed field with a boolean, date, objectId, number (not decimals), string, or UUID to use as a pre-filter.Atlas Vector Search supports only the filters for the following MQL match expressions:
- $gt
- $lt
- $gte
- $lte
- $eq
- $ne
- $in
- $nin
- $nor
- $not
- $and
- $or
- Parameters:
filter
- must not be null.- Returns:
- a new
VectorSearchOperation
withCriteriaDefinition
applied.
-
numCandidates
Number of nearest neighbors to use during the search. Value must be less than or equal to (invalid input: '<'=)10000
. You can't specify a number less than the number of documents to return (limit). This field is required ifsearchType(SearchType)
isVectorSearchOperation.SearchType.ANN
orVectorSearchOperation.SearchType.DEFAULT
.- Parameters:
numCandidates
- number of nearest neighbors to use during the search- Returns:
- a new
VectorSearchOperation
withnumCandidates
applied.
-
withSearchScore
Add aAddFieldsOperation
stage including the search score usingscore
as field name.- Returns:
- a new
VectorSearchOperation
with search score applied. - See Also:
-
withSearchScore
Add aAddFieldsOperation
stage including the search score usingscoreFieldName
as field name.- Parameters:
scoreFieldName
- name of the score field.- Returns:
- a new
VectorSearchOperation
withscoreFieldName
applied. - See Also:
-
withFilterBySore
Add aMatchOperation
stage targeting the score field name. Implies that the score field is present by either reusing a previousAddFieldsOperation
fromwithSearchScore()
orwithSearchScore(String)
or by adding a newAddFieldsOperation
stage.- Returns:
- a new
VectorSearchOperation
with search score filter applied.
-
toDocument
Description copied from interface:AggregationOperation
- Specified by:
toDocument
in interfaceAggregationOperation
- Parameters:
context
- theAggregationOperationContext
to operate within. Must not be null.- Returns:
- the Document
-
toPipelineStages
Description copied from interface:AggregationOperation
Turns theAggregationOperation
into list ofstages
by using the givenAggregationOperationContext
. This allows a singleAggregationOptions
to add additional stages for eg.$sort
or$limit
.- Specified by:
toPipelineStages
in interfaceAggregationOperation
- Parameters:
context
- theAggregationOperationContext
to operate within. Must not be null.- Returns:
- the pipeline stages to run through. Never null.
-
getOperator
Description copied from interface:AggregationOperation
Return the MongoDB operator that is used for thisAggregationOperation
. Aggregation operations should implement this method to avoid document rendering.- Specified by:
getOperator
in interfaceAggregationOperation
- Returns:
- the operator used for this
AggregationOperation
.
-