Repo Frameworks

mem0ai/mem0

Mem0 is a memory layer for AI agents and apps that stores and retrieves user, session and agent memories, available as a library, self-hosted server, or cloud platform.

  • 69.4k GitHub stars
  • Python
  • ⚖️ Apache-2.0
  • 🎯 Intermediate

Last verified: repo last pushed

pip install mem0ai
mem0ai/mem0 preview image

What it is

Mem0 ("mem-zero") adds an intelligent memory layer to AI assistants and agents so they can remember user preferences, adapt to individual needs, and learn over time. It retains User, Session, and Agent state and is offered as a Python/npm library, a self-hosted server, or a managed cloud platform. It also ships a CLI and agent skills for coding assistants.

Who it's for

  • Developers building AI assistants, customer support chatbots, or autonomous agents that need persistent memory
  • Teams that want to self-host a memory server on their own infrastructure
  • Teams wanting a zero-ops managed memory platform
  • Developers using AI coding assistants (Claude Code, Codex, Cursor, Windsurf, etc.) who want Mem0 integration skills

Requirements

Requirements

  • An LLM is required; default is gpt-5-mini from OpenAI (other LLMs are supported)
  • Default embedding model is text-embedding-3-small from OpenAI
  • Self-hosted server setup uses docker compose
  • For hybrid search with BM25 and entity extraction, install the nlp extra and the spaCy en_core_web_sm model
  • Self-hosted auth is on by default

Setup

  1. Install the Python library

    Install the library for testing and prototyping.

    bash
    pip install mem0ai
  2. Optional NLP support for hybrid search

    Install with NLP support for BM25 keyword matching and entity extraction.

    bash
    pip install mem0ai[nlp]
    python -m spacy download en_core_web_sm
  3. Install the npm SDK

    Install the SDK via npm.

    bash
    npm install mem0ai
  4. Run the self-hosted server

    Recommended: one command starts the stack, creates an admin, and issues the first API key. Alternatively, start the stack and finish setup via the browser wizard at http://localhost:3000.

    bash
    # Recommended: one command — start the stack, create an admin, issue the first API key.
    cd server && make bootstrap
    
    # Manual: start the stack and finish setup via the browser wizard.
    cd server && docker compose up -d    # http://localhost:3000
  5. Install the CLI

    Manage memories from your terminal.

    bash
    npm install -g @mem0/cli   # or: pip install mem0-cli
    
    mem0 init
    mem0 add "Prefers dark mode and vim keybindings" --user-id alice
    mem0 search "What does Alice prefer?" --user-id alice

Examples

Chat loop with memory retrieval and storage

python
python
from openai import OpenAI
from mem0 import Memory

openai_client = OpenAI()
memory = Memory()

def chat_with_memories(message: str, user_id: str = "default_user") -> str:
    # Retrieve relevant memories
    relevant_memories = memory.search(query=message, filters={"user_id": user_id}, top_k=3)
    memories_str = "\n".join(f"- {entry['memory']}" for entry in relevant_memories["results"])

    # Generate Assistant response
    system_prompt = f"You are a helpful AI. Answer the question based on query and memories.\nUser Memories:\n{memories_str}"
    messages = [{"role": "system", "content": system_prompt}, {"role": "user", "content": message}]
    response = openai_client.chat.completions.create(model="gpt-5-mini", messages=messages)
    assistant_response = response.choices[0].message.content

    # Create new memories from the conversation
    messages.append({"role": "assistant", "content": assistant_response})
    memory.add(messages, user_id=user_id)

    return assistant_response

What it does: Searches memories for the user, injects them into the system prompt, gets an OpenAI response, then stores the conversation as new memories.

Agent sign-up and first memory via CLI

bash
bash
# 1. Install
npm install -g @mem0/cli      # or: pip install mem0-cli

# 2. Sign up as an agent (replace `claude-code` with your name)
mem0 init --agent --agent-caller claude-code

# 3. Add a memory
mem0 add "I am using mem0"

# 4. Search
mem0 search "am I using mem0"

What it does: Lets an AI agent get a working Mem0 API key and add and search memories in four commands; the human owner can later claim the account with mem0 init --email <their-email>.

Install agent skills for a coding assistant

bash
bash
npx skills add https://github.com/mem0ai/mem0 --skill mem0
npx skills add https://github.com/mem0ai/mem0 --skill mem0-cli
npx skills add https://github.com/mem0ai/mem0 --skill mem0-vercel-ai-sdk

What it does: Reference skills that load Mem0 SDK knowledge into the AI coding assistant's context.

Pros & cons

Pros

  • Pro:Multiple deployment options: library, self-hosted server (docker compose), or managed cloud platform
  • Pro:Retrieval combines semantic, BM25 keyword, and entity matching, with temporal reasoning; benchmark results are published and the evaluation framework is open-sourced
  • Pro:Supports a variety of LLMs and embedding models rather than only the OpenAI defaults
  • Pro:Includes a CLI, Python and npm SDKs, and agent skills for coding assistants, plus LangGraph and CrewAI integrations

Cons

  • Con:Requires an LLM to function, with OpenAI models as the defaults
  • Con:Published benchmark scores reflect the managed platform's proprietary optimizations; open-source users should expect only directionally similar gains
  • Con:Self-hosted auth is on by default, so upgrading from a pre-auth build requires extra steps (ADMIN_API_KEY, wizard, or AUTH_DISABLED for local dev)

Images