This is PraisonAI’s first-party MongoDB memory adapter. It is not the same as running mem0 with a MongoDB vector store backend. Mem0’s MongoDB vector store has an upstream bug; the adapter documented on this page is a separate implementation and is unaffected. See Memory Troubleshooting if you were sent here from a mem0 error.
embedding_model directly:
How It Works
Quick Start
1
Simple Usage
2
With Configuration
Install the optional dependency first:
pip install pymongo or pip install "praisonaiagents[mongodb]".Configuration
As of PraisonAI #4203, MongoDB memory scopes
collection_name per agent by default (memory_store_<user_id>) so two agents in one process don’t share one collection. Set collection_name explicitly to keep a shared collection. See Per-agent isolation across backends.Vector Search
Whenuse_vector_search: True:
- Both short-term and long-term writes include an embedding — using
text-embedding-3-smallby default, or whatever you configure (see below). - Searches use MongoDB
$vectorSearchagainst indexvector_indexon fieldembedding— the same field in both collections. - If vector search fails or is unavailable, either tier falls back to MongoDB text search.
use_vector_search: False (default), only MongoDB text indexes are used.
Configuring the embedding model
The adapter resolves the embedding model at construction, in this precedence order:embedding_model → config["embedder"] → falls back to text-embedding-3-small.
Use the embedder block (preferred — the same shape used across memory, knowledge, and the MongoDB knowledge adapter):
embedding_model string (litellm-style, shortest):
Atlas vector search indexes are built for a specific dimension. Switching from
text-embedding-3-small (1536) to nomic-embed-text (768) means you must re-create the vector_index on both short_term_memory and long_term_memory at the new dimension. Otherwise writes succeed but searches error or return nothing.Configurable embedder (PR #4802): Before this fix the adapter hardcoded
text-embedding-3-small. An agent configured entirely against Ollama still silently embedded through OpenAI — and if that OpenAI call failed, documents were written with no vectors and vector search degraded to text search with no warning. The adapter now honours embedding_model / embedder, mirroring the MongoDB knowledge adapter.Short-term embeddings parity (PR #3419): Before #3419,
use_vector_search: True produced embeddings only for long-term writes and searches. Short-term writes were text-only, so semantic recall on recent context silently degraded to keyword lookup. The adapter now uses the shared _store / _search helpers for all four operations, matching DakeraMemoryAdapter.As of PraisonAI PR #2060,
use_vector_search is always initialised on the Memory instance — even when MongoDB is not the active provider. Previously, a missing attribute could raise AttributeError deep in store/search paths.Atlas Setup
- Create a vector search index named
vector_indexon both theshort_term_memoryandlong_term_memorycollections. - Set the indexed path to
embeddingon each. - Pass
use_vector_search: Truein agent config.
Best Practices
Use environment variables for credentials
Use environment variables for credentials
Store connection strings in
MONGODB_URI rather than hard-coding credentials in source files.Enable vector search for semantic recall
Enable vector search for semantic recall
Set
use_vector_search: True on Atlas when you need similarity search; text indexes suffice for keyword lookup.Size the connection pool for concurrency
Size the connection pool for concurrency
Tune
max_pool_size and min_pool_size when running many agents against the same cluster.Create indexes before production traffic
Create indexes before production traffic
Configure the
vector_index Atlas index and text indexes before scaling agent workloads.Related
Custom Memory Adapters
Registry pattern and custom backend registration.
Memory Advanced Search
Reranking, relevance cutoffs, and quality filtering.
Dakera Memory
Self-hosted, decay-weighted vector recall via the Dakera server.
Local Memory & Knowledge
Run memory and knowledge fully local with Ollama embeddings.
Ollama Embeddings
Local embedding models and their auto-detected dimensions.

