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 varstring
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 * 10Configuration
Environment Variables
With Custom Client
Setting Up MongoDB Atlas
Create Atlas Search Index
- Go to your MongoDB Atlas cluster
- Navigate to the “Search” tab
- Click “Create Search Index”
- Use JSON editor and configure:
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 equalin- Value in arraynin- 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
- Index metadata fields: Only index fields you’ll filter on
- Match dimensions: Ensure embedding dimensions match your model
- Use auto-create: Let the store manage index creation
- Tune candidates: Adjust
numCandidatesfor performance vs accuracy - Monitor costs: Track Atlas usage and storage
- Use connection pooling: Reuse MongoDB client instances