A memory service is a small pipeline: on write, ask an LLM to pull durable facts out of a conversation and drop duplicates; on read, embed the query and return the closest facts, with a keyword match alongside. A competent agent builds that against SQLite in one sitting, and Mem0's docs describe the same steps. The catch is quality rather than code: deciding what counts as a fact, handling contradictions and keeping results relevant as memories pile up, which is why the prompt includes a small evaluation script. Mem0's own library is Apache-2.0, so you can read how they do it.
Before you buildHobby is free with 10,000 add requests a month, and Mem0's own library is free to self-host. Check both before building: your rebuild only wins if you want a memory store you can read end to end.
Build me a self-hosted memory service for my AI agents to replace Mem0. Requirements:
- Python 3.12: a FastAPI server (`uvicorn`) on http://localhost:8890 with POST /memories (add),
POST /search, GET /memories, PATCH /memories/{id}, DELETE /memories/{id} and GET /memories/{id}/history,
each scoped by user_id and an optional agent_id.
- Storage: SQLite in ./data/memory.db with `sqlite-vec` for embeddings: memories (id, scope ids, text,
metadata JSON, created, updated, deleted) and a history table that keeps the old and new text of every
add, update and delete.
- Add: take a list of chat messages and ask the LLM (an OpenAI-compatible endpoint, LLM_BASE_URL and
LLM_API_KEY in .env, Ollama works) for durable facts as JSON. Compare each fact with the 5 nearest stored
memories and let the model choose ADD, UPDATE, DELETE or NONE. Apply the choice and log it.
- Search: embed the query (EMBED_MODEL in .env), take the top 20 by vector distance and the top 20 by FTS5
keyword match, merge them with reciprocal rank fusion, apply an optional metadata filter and a small
recency boost, and return the top k with scores.
- Auth: one bearer token per project from .env; reject everything else. Bind to 127.0.0.1 unless HOST is set.
- MCP: a stdio MCP server (`mcp` package) exposing add_memory, search_memories and delete_memory over the
same code.
- Evaluation: `python -m memsvc.eval` loads 30 hand-written conversation snippets from ./eval/cases.json,
runs add then search, and prints recall@3, so I can tell whether a prompt change helped.
- No accounts, no telemetry, local-first: only the configured LLM and embedding endpoints are called, and
the README lists exactly what text is sent to them.
- Out of scope: graph memory, a dashboard, multi-tenant billing, SDK packages, memory decay.
- README: the .env keys, running with Ollama only, backing up memory.db, and a warning that stored
memories can contain personal data.Opens your agent with the prompt filled in, you press enter. Or copy it and paste it into an empty folder.
The first prompt builds the core. Run these one at a time in the same folder to grow it into your own Mem0.
Extend the memory service in this folder with entity links. Requirements: - On add, have the LLM also return entities (name, type) for each stored fact; keep an entities table and a link table to memories, normalising names to lower case with aliases. - In search, add an entity score: memories sharing an entity with the query get a boost, merged into the existing rank fusion with a configurable weight. - GET /entities lists entities with memory counts; deleting a memory removes orphaned links. - Extend the eval script with 10 cases that only the entity boost can answer, and print recall with and without it. - Update the README.
Add a consolidation job to the memory service in this folder. Requirements: - A command `python -m memsvc.consolidate` that, per user, finds memory pairs with cosine similarity above 0.92, asks the LLM whether they say the same thing, and merges them into one memory while keeping both in the history table. - Mark memories not returned by any search for 180 days as archived, not deleted, and exclude archived ones from search unless asked. - Print a report of merged, archived and unchanged counts, and support --dry-run. - Update the README with a cron line and how to restore an archived memory.
Add an importer to the memory service in this folder. Requirements: - `python -m memsvc.import_json <file>` reads a JSON file that is a list of objects with a `memory` or `text` field and optional user_id, agent_id, created_at and metadata. - Store each item as a memory without calling the extraction LLM, embed it with EMBED_MODEL, and keep the original created_at when present. - Skip exact duplicates, print counts of imported, skipped and failed items, and write failures to ./data/import_errors.json. - Update the README with the expected fields and how to map a custom export schema to them.
Add a dashboard to the memory service in this folder. Requirements: - A server-rendered page at /admin behind the same bearer token or a password in .env, listing memories per user with search, edit and delete. - Each memory shows its history (adds, updates, deletes with old and new text) and which request created it. - A request log page with the last 500 calls: route, status, duration, and no message bodies. - Update the README.
Developers pay so they don't run a vector store, an extraction pipeline and an evaluation harness next to their product. The managed Platform adds graph memory, a dashboard and analytics, and support on higher tiers. Quality is the product: whether the right fact comes back at the right moment.
Estimate · Runs locally. Running costs are LLM and embedding tokens on your own account, or nothing with a local model on your own hardware. The build is token usage on your agent plan.
| Plan | Monthly | Annual, per month | What you get |
|---|---|---|---|
| Hobby | $0 | $0 | 10,000 add requests and 1,000 retrieval requests a month, 1 project, unlimited end users, community support. |
| Starter | $19 | — | 50,000 add requests and 5,000 retrieval requests a month, 1 project, unlimited end users, community support. |
| Pro | $249 | — | 500,000 add requests and 50,000 retrieval requests a month, unlimited projects, graph memory, advanced analytics, Dream (background memory consolidation), private Slack support. |
| Enterprise | custom | — | Unlimited requests and projects, SLA support, on-prem deployment, audit logs, custom integrations and SSO. |
Hobby is free: 10,000 add requests and 1,000 retrieval requests a month, one project, unlimited end users.
Yes. An AI coding agent such as Claude Code, Codex or Cursor can build a usable personal version in one session with the prompt on this page, running on your own machine.
About $19 a month on the Starter plan, $228 a year (checked 2026-10-19).
A managed service with a dashboard, a request log and analytics; Graph memory over extracted entities, a Platform feature; Memory decay, temporal reasoning and Dream, the background consolidation job; Webhooks, batch operations and structured memory export; SDKs and framework integrations maintained by someone else. If any of those matter to you, keep paying.
Yes: Mem0 open source (open source), Letta (open source), Graphiti (open source).