For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.

vectorSearch (MongoDB Search Operator)

You can use the vectorSearch operator to perform a vector search on your data. A vector search allows you to query your data based on semantic meaning rather than just keyword matches, which helps you retrieve more relevant search results. Use this operator to add analyzed text capabilities such as fuzzy search, phrase matching, location filtering, wildcard pattern matching, and more alongside semantic search.

Embeddings
Vector Search
Interface

vectorSearch has the following syntax:

vectorSearch uses the following fields to construct a query:

You must index the fields to search using the vectorSearch operator. You can index the following types of fields in the MongoDB Search index definition:

You can pre-filter the documents to narrow the scope of your semantic search. Use any supported MongoDB Search operator in the filter field to query and filter the documents.

Important

Filtered queries are typically slower than an otherwise equivalent unfiltered query.

You can include the score of each document in your search results. Specify the $meta expression with the searchScore value in the $project stage. You can also specify the searchScoreDetails value for the scoreDetails field $meta expression for a detailed breakdown of the score.

To learn more, see Score the Documents in the Results and Return the Score Details.

The vectorSearch operator must be the top-level operator in your queries. Therefore, you can't use the vectorSearch operator inside the following MongoDB Search operators:

You can't use the vectorSearch operator to query fields indexed using a vectorSearch type index.

You can't use the following $search options with the vectorSearch operator:

You can't run $search queries with the vectorSearch operator in the MongoDB Search Playground.