A vector index organizes stored embeddings so a query vector can quickly retrieve similar documents. In Atlas Vector Search, the index is separate from the MongoDB collection it searches. It supports semantic search and recommendation workloads without comparing every result by hand. section 12.8 section 12.2.1
To define and use an Atlas vector index:
- Store embeddings in a collection, then define a vectorSearch index with the database, collection, embedding field path, vector dimensions, and similarity metric. The configured dimensions must describe the stored vectors; Atlas supports up to 4,096. section 12.2.3 section 12.2.1
- Choose a metric for the application: cosine similarity for text comparisons, Euclidean distance where spatial distance matters, or dot product for preference-based recommendations. section 12.2.3
- Create the index from its JSON definition with the Atlas CLI and check that it is ready before querying. A $vectorSearch aggregation stage then names the index, embedding path, and query vector. section 12.2.4 section 12.3
{
"name": "MongoDB-in-Action-VectorSearchIndex",
"type": "vectorSearch",
"collectionName": "embedded_movies",
"database": "sample_mflix",
"fields": [
{
"type": "vector",
"path": "plot_embedding",
"numDimensions": 1536,
"similarity": "cosine"
},
{
"type": "filter",
"path": "genres"
},
{
"type": "filter",
"path": "languages"
},
{
"type": "filter",
"path": "year"
}
]
}
This movie-search definition indexes 1,536-dimensional plot_embedding vectors with cosine similarity. The genres, languages, and year fields are separately declared as filter fields so queries can narrow results before vector search. section 12.2.3 section 12.3.2
atlas cluster search index create \ --clusterName MongoDB-in-Action \ --file vector-definition.json
Pass the saved definition to the Atlas CLI to create the cluster’s search index; afterward, list its status and wait until it is ready to query. section 12.2.4
Query choices affect the speed–precision trade-off. Approximate nearest-neighbor search (ANN) is the default; exact nearest-neighbor search (ENN) can be more precise but slower. For ANN, increasing numCandidates may improve precision at additional processing cost. Prefilters require fields declared with type filter in the index definition. section 12.3 section 12.3.2
Keep dimensions only as high as accuracy needs justify, and avoid indexing or reindexing during searches. If the embedding model changes, create a new index for the new vectors. Sufficient memory and a warmed filesystem cache also help avoid search latency; exclude large vector fields from returned results when they are unnecessary. section 12.7
Indexing chatbot embeddings
A chatbot setup indexes the embedding field in a langchain collection as 1,536-dimensional vectors using cosine similarity. Its local Atlas deployment verifies the resulting index with getSearchIndexes(), checking for READY and queryable status. section 14.5.3







