Skip to main content
Use MongoDB as a document-backed memory store with optional Atlas Vector Search for semantic retrieval.
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.
The user chats with the agent; short- and long-term memory persist in MongoDB.

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

When use_vector_search: True:
  • Long-term writes include an embedding (via text-embedding-3-small by default).
  • Searches use MongoDB $vectorSearch against index vector_index on field embedding.
  • If vector search fails or is unavailable, the adapter falls back to MongoDB text search.
When use_vector_search: False (default), only MongoDB text indexes are used.
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

  1. Create a vector search index named vector_index on the long_term_memory collection.
  2. Set the indexed path to embedding.
  3. Pass use_vector_search: True in agent config.

Best Practices

Store connection strings in MONGODB_URI rather than hard-coding credentials in source files.
Set use_vector_search: True on Atlas when you need similarity search; text indexes suffice for keyword lookup.
Tune max_pool_size and min_pool_size when running many agents against the same cluster.
Configure the vector_index Atlas index and text indexes before scaling agent workloads.

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.