MongoDB Vector Search Setup - Quick Start
Set up vector search indexes for AI agent learning in 5 minutes
MongoDB Vector Search Setup - Quick Start
Your backend is running but showing 0 embeddings because the MongoDB Atlas vector search indexes haven't been created yet.
What You're Missing
The backend logs show:
📊 Vector stats retrieved: 0 embeddings
This means:
- ✅ Backend is running correctly
- ✅ Database connection works
- ❌ Vector search indexes don't exist yet
- ❌ No embeddings can be stored until indexes are created
Quick Fix (5 minutes)
Step 1: Open MongoDB Atlas
- Go to MongoDB Atlas
- Select your cluster
- Click on "Search" tab (not "Browse Collections")
Step 2: Create Vector Search Index
- Click "Create Search Index"
- Choose "JSON Editor" (not Atlas Vector Search UI)
- Select database:
ai-agents - Select collection:
agent_embeddings- If collection doesn't exist, that's OK! Create the index anyway.
- Paste this JSON:
{
"name": "decision_vector_index",
"type": "vectorSearch",
"definition": {
"fields": [
{
"type": "vector",
"numDimensions": 1536,
"path": "embedding",
"similarity": "cosine"
},
{
"type": "filter",
"path": "qualityRating"
},
{
"type": "filter",
"path": "taskType"
},
{
"type": "filter",
"path": "agentType"
},
{
"type": "filter",
"path": "decisionType"
},
{
"type": "filter",
"path": "wasSuccessful"
},
{
"type": "filter",
"path": "tenantId"
}
]
}
}
- Click "Create Search Index"
- Wait 1-2 minutes for index to become READY
Step 3: Verify It Works
Check your backend logs again. After the index is created and your next Cursor session logs a decision, you should see:
📊 Vector stats retrieved: 1 embeddings ← Success!
Why This Is Required
MongoDB Atlas Vector Search requires explicit index creation. It doesn't auto-create indexes like regular MongoDB collections.
The index enables:
- ✅ Semantic similarity search (find related decisions)
- ✅ Fast vector queries (< 50ms)
- ✅ Filtered search (by task type, quality, etc.)
Without the index:
- ❌ Vector search queries fail silently
- ❌ No embeddings can be stored
- ❌ AI learning system can't work
Troubleshooting
"Collection doesn't exist"
Solution: Create the index anyway. MongoDB will create the collection automatically when first embedding is saved.
"Index creation failed"
Solution:
- Make sure you're using JSON Editor, not the UI builder
- Copy the JSON exactly as shown above
- Database must be named exactly
ai-agents - Collection must be named exactly
agent_embeddings
"Still showing 0 embeddings after 5 minutes"
Solution:
- Check index status in Atlas (should show READY)
- Make sure
OPENAI_API_KEYis set in your.envfile - Check backend logs for embedding errors
- Try triggering a decision manually in the frontend
Environment Variables Required
Make sure these are in your .env:
# Required for embeddings
OPENAI_API_KEY=sk-your-key-here
# Should already exist
MONGODB_CONNECTION_STRING=mongodb+srv://...
Next Steps After Index Creation
Once you see embeddings > 0:
- ✅ AI decisions are being logged
- ✅ Embeddings are being generated
- ✅ Vector search is working
- 🎯 AI will start learning from your decisions automatically!
Full Setup Guide: /apis/backend-api/src/app/ai-agents/scripts/setup-vector-search.md
Created: December 10, 2025
Session: 13