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:

  1. ✅ Backend is running correctly
  2. ✅ Database connection works
  3. ❌ Vector search indexes don't exist yet
  4. ❌ No embeddings can be stored until indexes are created

Quick Fix (5 minutes)

Step 1: Open MongoDB Atlas

  1. Go to MongoDB Atlas
  2. Select your cluster
  3. Click on "Search" tab (not "Browse Collections")

Step 2: Create Vector Search Index

  1. Click "Create Search Index"
  2. Choose "JSON Editor" (not Atlas Vector Search UI)
  3. Select database: ai-agents
  4. Select collection: agent_embeddings
    • If collection doesn't exist, that's OK! Create the index anyway.
  5. 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"
      }
    ]
  }
}
  1. Click "Create Search Index"
  2. 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:

Without the index:


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:

  1. Make sure you're using JSON Editor, not the UI builder
  2. Copy the JSON exactly as shown above
  3. Database must be named exactly ai-agents
  4. Collection must be named exactly agent_embeddings

"Still showing 0 embeddings after 5 minutes"

Solution:

  1. Check index status in Atlas (should show READY)
  2. Make sure OPENAI_API_KEY is set in your .env file
  3. Check backend logs for embedding errors
  4. 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:

  1. ✅ AI decisions are being logged
  2. ✅ Embeddings are being generated
  3. ✅ Vector search is working
  4. 🎯 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