Skip to main content
Long-term memory lets your agent store and recall information across different conversations and sessions. This guide shows how to use MongoDB Atlas as the persistent store backend. MongoDB stores memories as documents in a collection. With an Atlas Vector Search index, the same store can run semantic search over stored memories.
For a deeper dive into memory types and strategies for writing memories, see the Memory conceptual guide.

Setup

Installation

Install the store package (langgraph-store-mongodb):

Credentials

Set your Atlas connection string:
If you want automated tracing of your model calls, set your LangSmith API key:

Usage

Create a MongoDBStore and pass it to create_agent. The from_conn_string context manager creates the required indexes when it opens. You do not call a separate setup() method.

Memory storage

LangGraph stores memories as JSON documents organized by namespace and key. Namespaces typically include a user or org ID to keep memories scoped. The following example configures vector indexing so store.search can run semantic queries. Use create_vector_index_config and pass it as index_config:
For more information about store operations, see the Stores guide.

Read long-term memory in tools

Tools can read from the store using the runtime parameter, which LangGraph injects automatically:

Write long-term memory from tools

Tools can also write to the store using runtime.store.put, persisting data that survives across threads:

See also