Interface VectorSearchOptions
- All Superinterfaces:
Bson
- All Known Subinterfaces:
ApproximateVectorSearchOptions,ExactVectorSearchOptions
$vectorSearch pipeline stage of an aggregation pipeline.
This includes options for searching against nested (embedded) embeddings and arrays of embeddings,
via parentFilter(Bson) and nestedOptions(VectorSearchNestedOptions).
- Since:
- 4.11
- See Also:
- MongoDB Atlas documentation
- $vectorSearch
- Since server release
- 6.0.11
-
Field Summary
Fields inherited from interface org.bson.conversions.Bson
DEFAULT_CODEC_REGISTRY -
Method Summary
Modifier and TypeMethodDescriptionapproximateVectorSearchOptions(long numCandidates) ReturnsApproximateVectorSearchOptionsthat represents server defaults.static ExactVectorSearchOptionsReturnsExactVectorSearchOptionsthat represents server defaults with theexactoption set to true.Creates a newVectorSearchOptionswith the filter specified.nestedOptions(VectorSearchNestedOptions nestedOptions) Creates a newVectorSearchOptionswith thenestedOptionsspecified.Creates a newVectorSearchOptionswith the specified option in situations when there is no builder method that better satisfies your needs.parentFilter(Bson parentFilter) Creates a newVectorSearchOptionswith the parent filter specified.returnStoredSource(boolean returnStoredSource) Creates a newVectorSearchOptionsthat instructs to return only stored source fields.Methods inherited from interface org.bson.conversions.Bson
toBsonDocument, toBsonDocument
-
Method Details
-
filter
Creates a newVectorSearchOptionswith the filter specified.- Parameters:
filter- A filter that is applied before applying thequeryVectorOne may useFiltersto create this filter, though not all filters may be supported. See the MongoDB documentation for the list of supported filters.- Returns:
- A new
VectorSearchOptions.
-
parentFilter
Creates a newVectorSearchOptionswith the parent filter specified.Applies only when searching against a nested (embedded) field: this filter is applied to the parent (root) documents, while
filter(Bson)is applied to the leaf (embedded) documents. For a non-nested search, usefilter(Bson)instead.Unlike some other MongoDB drivers, the Java driver does not automatically re-route a top-level
filter(Bson)toparentFilterbased on the path: you must callparentFilter(Bson)explicitly to specify a parent (root-level) filter for a nested search.- Parameters:
parentFilter- A filter applied to the parent documents of a nested$vectorSearch. One may useFiltersto create this filter, though not all filters may be supported. See the MongoDB documentation for the list of supported filters.- Returns:
- A new
VectorSearchOptions. - Since:
- 5.10
- MongoDB Atlas documentation
- $vectorSearch
- Since server release
- 8.3
-
nestedOptions
Creates a newVectorSearchOptionswith thenestedOptionsspecified.Applies only when searching against arrays of embeddings within nested (embedded) documents; for example it controls how the scores of the individual matching embeddings within a document are aggregated (see
VectorSearchNestedOptions.scoreMode(VectorSearchScoreMode)).- Parameters:
nestedOptions- The options for a nested (embedded)$vectorSearch.- Returns:
- A new
VectorSearchOptions. - Since:
- 5.10
- MongoDB Atlas documentation
- $vectorSearch
- Since server release
- 8.3
-
returnStoredSource
Creates a newVectorSearchOptionsthat instructs to return only stored source fields.- Parameters:
returnStoredSource- The option to return only stored source fields.- Returns:
- A new
VectorSearchOptions. - Since:
- 5.8
- MongoDB Atlas documentation
- $vectorSearch
-
option
Creates a newVectorSearchOptionswith the specified option in situations when there is no builder method that better satisfies your needs. This method cannot be used to validate the syntax.Example
The following code creates two functionally equivalentVectorSearchOptionsobjects, though they may not be equal.VectorSearchOptions options1 = VectorSearchOptions.vectorSearchOptions() .filter(Filters.lt("fieldName", 1)); VectorSearchOptions options2 = VectorSearchOptions.vectorSearchOptions() .option("filter", Filters.lt("fieldName", 1));- Parameters:
name- The option name.value- The option value.- Returns:
- A new
VectorSearchOptions.
-
approximateVectorSearchOptions
ReturnsApproximateVectorSearchOptionsthat represents server defaults.- Parameters:
numCandidates- The number of candidates.- Returns:
ApproximateVectorSearchOptionsthat represents server defaults.- Since:
- 5.2
-
exactVectorSearchOptions
ReturnsExactVectorSearchOptionsthat represents server defaults with theexactoption set to true.- Returns:
ExactVectorSearchOptionsthat represents server defaults.- Since:
- 5.2
-