MongoDB Index Type

Vector Search Indexes in MongoDB: How It Works and When to Use It

MongoDB Vector Search indexes vector embeddings for approximate nearest-neighbor retrieval by a supported similarity measure. It is a MongoDB Search feature with deployment-specific availability, not an ordinary B-tree index type.

What Is a Vector Search Indexes in MongoDB?

MongoDB Vector Search indexes vector embeddings for approximate nearest-neighbor retrieval by a supported similarity measure. It is a MongoDB Search feature with deployment-specific availability, not an ordinary B-tree index type.

How the Vector Search Indexes Algorithm Works

MongoDB Vector Search indexes vector embeddings for approximate nearest-neighbor retrieval by a supported similarity measure. It is a MongoDB Search feature with deployment-specific availability, not an ordinary B-tree index type.

Diagram showing the Vector Search Indexes lookup algorithm
Conceptual Vector Search Indexes algorithm. Exact behavior depends on the database version and query plan.

When to Use Vector Search Indexes

Semantic similarity, recommendation, and retrieval-augmented search on MongoDB deployments that support Vector Search.

How to Create a MongoDB Vector Search Indexes

Review data quality, existing structures, feature support, build time, and deployment requirements before creating an index on a production table.

db.documents.createSearchIndex({ name: "vector_index", type: "vectorSearch", definition: { fields: [{ type: "vector", path: "embedding", numDimensions: 3, similarity: "cosine" }] } })

Vector Search Indexes Query Example

This example demonstrates the matching query shape. Check the execution plan to confirm that the engine can use the index.

db.documents.aggregate([{ $vectorSearch: { index: "vector_index", path: "embedding", queryVector: [0.12, 0.37, 0.81], numCandidates: 100, limit: 10 } }])

Queries Supported by Vector Search Indexes

Semantic similarity, recommendation, and retrieval-augmented search on MongoDB deployments that support Vector Search. A similar-looking predicate may not use the same access path; operators, expressions, key order, and data type all matter.

Read Performance, Storage, and Write Costs

Embeddings use storage and compute; latency and recall depend on dimensions, quantization, filter design, candidate count, and deployment tier. Indexes reduce some search work but require storage and add maintenance to writes.

Vector Search Indexes Limitations and Common Mistakes

Vector Search product support, syntax, limits, and filtering capabilities vary by Atlas/service version. It is not a replacement for exact equality or range indexes.

Do not assume that an index being present means the optimizer chose it or that the query became selective.

How to Measure and Tune Vector Search Indexes

Verify embedding dimensions and model consistency; test recall, latency, candidate counts, filtering, and the correct Atlas environment.

Compare representative plans and timings before and after, including concurrent writes and realistic data volumes.

Vector Search Indexes Questions

Will the database always use this index?

No. The optimizer weighs selectivity, estimated costs, statistics, cache state, and the amount of data returned.

What should I verify before production?

Confirm version support, query compatibility, write overhead, build/rollback procedures, and index behavior during backup and recovery.

Official MongoDB Index Documentation

Check MongoDB Atlas Vector Search documentation for release-specific requirements and supported operators.