Skip to main content
Use MongoDB as a document-backed memory store with optional Atlas Vector Search for semantic retrieval.

Quick Start

from praisonaiagents import Agent

agent = Agent(
    name="assistant",
    memory={
        "provider": "mongodb",
        "config": {
            "connection_string": "mongodb+srv://user:pass@cluster.mongodb.net/",
            "database": "praisonai",
            "use_vector_search": True,
        },
    },
)
Install the optional dependency first: pip install pymongo or pip install "praisonaiagents[mongodb]".

Configuration

OptionTypeDefaultDescription
connection_stringstrmongodb://localhost:27017/MongoDB URI
databasestrpraisonaiDatabase name
use_vector_searchboolFalseEnable Atlas Vector Search on long-term memory
max_pool_sizeint50Connection pool maximum
min_pool_sizeint10Connection pool minimum
max_idle_timeint30000Max idle time in ms
server_selection_timeoutint5000Server selection timeout in ms
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.

Custom Memory Adapters

Registry pattern and custom backend registration.

Memory Concepts

Overview of memory providers and lifecycle.