Skip to main content
AI Kit integrates with Mem0 to provide a powerful and simple memory layer for your agents. This allows agents to remember past interactions, user preferences, and context across different sessions.

Overview

The memory system automatically:
  1. Retrieves relevant memories based on the current user input before generating a response.
  2. Injects these memories into the system prompt.
  3. Stores the new interaction (user input and agent response) into the vector store after the response is generated.

Configuration

To enable memory, you need to provide a memory configuration object when initializing your Agent.

1. Simple (In-Memory)

For testing or temporary agents, you can initialize memory without any configuration. This uses an in-memory vector store that resets when the process ends.

2. Local Persistence

To persist chat history locally between runs, provide a path where the SQLite database should be stored.

3. Advanced (PgVector)

For production applications, we recommend using a robust vector database like PostgreSQL with pgvector.

PgVector Setup

Ensure your PostgreSQL database has the vector extension enabled:

Usage

Once configured, you can use the memory option in generate and stream methods to pass context identifiers like thread (run ID) and metadata (user ID, etc.).

Streaming with Memory

Retrieving Context

In a subsequent call, even in a new session, the agent will recall the information:

Advanced Configuration

The memory configuration accepts the standard mem0 configuration object, allowing you to customize the embedder, vector store, and LLM used for memory operations. Refer to the Mem0 documentation for more advanced configuration options.