How I Self-Hosted a Mem0 Memory Stack (So My AI Agent Remembers)
Описание и применение
Автор создал приватный слой памяти для своего AI‑ассистента, развернув стек Mem0 на Synology NAS. Это позволяет агенту запоминать предпочтения клиентов и историю взаимодействий, не отправляя данные в облако.
Задача
An AI agent that forgets everything between conversations requires a persistent memory layer to retain context across sessions.
Результат
The self-hosted Mem0 stack delivers a private, persistent memory layer that enables the AI agent to remember customer preferences, past interactions, and decisions across sessions, all without data leaving the local network.
Рабочий процесс
- Deploy three Docker containers on the Synology NAS using Portainer compose: mem0 API, LiteLLM gateway, and PostgreSQL 17 with pgvector extension.
- Configure mem0 API with environment variables for OpenAI API key, LiteLLM base URL, MEM0_API_KEY, and PostgreSQL connection string.
- Set up LiteLLM to route fact extraction requests to the chosen LLM (e.g., OpenAI).
- Use POST /memories to add facts, optionally with infer=false for fast verbatim storage.
- Use POST /memories/search to retrieve relevant memories for a user_id and query.
- Inject retrieved facts into the AI agent’s system prompt or context before generating a response.
- Iterate: store new facts, retrieve relevant ones, and use them in subsequent replies.
Доказательства
An AI agent that forgets everything between conversations is a tool you have to reintroduce yourself to every session.
The stack sits in my own PostgreSQL behind my own network, none of that leaves my control.
POST /memories with the default infer=true runs the LLM fact extractor — it classifies and cleans each memory. That's smart but slow, and every call costs a model round-trip.
- Дата записи: 2026-10-20T05:41:21.270Z