Example
Mem0 — store and recall a memory

A real, runnable mini-project. Download it and run with Docker.

June 28, 2026

Mem0 — store and recall a memory

A tiny Mem0 script: it adds a fact for a user, then searches for it. Mem0 distils messages into compact facts (with an LLM) and recalls the relevant ones (from a vector store). The config uses OpenAI.

Configure

cd samples/mem0_1
cp .env.sample .env
# edit .env: set OPENAI_API_KEY

Mem0's config here uses OpenAI for fact extraction and embeddings. Get a key at platform.openai.com/api-keys. .env is gitignored — only .env.sample is committed.

Run with Docker

cd samples/mem0_1
docker build -t aas-mem0 .
docker run --rm --env-file .env aas-mem0 "what are alice's travel preferences?"

Run with Docker (in a devcontainer with DooD)

In a dev container that talks to the host Docker daemon (Docker-outside-of-Docker), the foreground docker run above often prints nothing and exits 0 — but the run itself succeeds. The script runs to completion and Docker captures all of its output; only the live attached stream drops it over the VM boundary. Run detached and follow the logs instead:

cd samples/mem0_1
docker build -t aas-mem0 .
docker logs -f "$(docker run -d --env-file .env aas-mem0 \
  "what are alice's travel preferences?")"

Run locally

cd samples/mem0_1
pip install -r requirements.txt
python app.py "what are alice's travel preferences?"

python-dotenv loads .env automatically.


Example run

Output varies by model and run — LLMs are non-deterministic, so the recalled phrasing differs each time. Below is one run (extraction + recall via OpenAI).

query: what are alice's travel preferences?
  - User prefers window seats when traveling and enjoys vegetarian meals.

Files

.env.sample
# Copy this file to `.env` and add your OpenAI API key.
#   cp .env.sample .env
#
# Mem0's default config uses OpenAI for both fact extraction and embeddings.
# Get a key at https://platform.openai.com/api-keys
OPENAI_API_KEY=