Skip to main content

Overview

MongoDB Atlas Vector Search provides native vector search capabilities within MongoDB Atlas, combining document storage with vector similarity search.

Installation

Basic Usage

Constructor Options

string
required
MongoDB database name
string
required
MongoDB collection name for storing vectors
MongoClient
MongoDB client instance. If not provided, creates client using MONGODB_URI env var
string
default:"default"
Name of the vector search index
string
default:"embedding"
Field name for storing embedding vectors
string
default:"text"
Field name for storing text content
string
default:"id"
Field name for storing node IDs
string
default:"metadata"
Field name for storing metadata
boolean
default:true
Automatically create vector search index if it doesn’t exist
string[]
default:[]
List of metadata fields to index for filtering
object
Custom embedding configuration. Default: {type: "knnVector", dimensions: 1536, similarity: "cosine"}
(query) => number
Function to determine number of candidates for search. Default: similarityTopK * 10

Configuration

Environment Variables

With Custom Client

Setting Up MongoDB Atlas

Create Atlas Search Index

  1. Go to your MongoDB Atlas cluster
  2. Navigate to the “Search” tab
  3. Click “Create Search Index”
  4. Use JSON editor and configure:
Or let the vector store auto-create the index:

Querying

Basic Query

Metadata Filtering

Supported Filter Operators

MongoDB Atlas Vector Search supports:
  • == - Equal
  • != - Not equal
  • < - Less than
  • <= - Less than or equal
  • > - Greater than
  • >= - Greater than or equal
  • in - Value in array
  • nin - Value not in array

Managing Data

Add Documents

Delete by Document ID

Access MongoDB Client

Advanced Configuration

Custom Number of Candidates

Multiple Indexed Metadata Fields

Complete Example

Best Practices

  1. Index metadata fields: Only index fields you’ll filter on
  2. Match dimensions: Ensure embedding dimensions match your model
  3. Use auto-create: Let the store manage index creation
  4. Tune candidates: Adjust numCandidates for performance vs accuracy
  5. Monitor costs: Track Atlas usage and storage
  6. Use connection pooling: Reuse MongoDB client instances

Troubleshooting

Index Not Found

If you see errors about missing index:

Dimension Mismatch

Ensure your embedding model matches the index configuration:

See Also