The way I give agents long-term memory is a small self-hosted stack: a vector database for storage, a Japanese-capable embedding model for indexing, and an open-source memory layer on top. The context window handles the current task; the memory layer handles everything the agent should still know next week. Keeping both local means the agent's memory never leaves my server.
Why agents need memory at all
A context window is a scratchpad, not a memory. When the session ends, everything it contained is gone — unless something wrote it down. Memory is that something: a layer the agent queries before answering, and updates when it learns something durable.
The practical difference is visible within days. An agent with memory does not ask you the same deployment detail twice. An agent without it treats every session as a first meeting.
The stack
Three pieces, each with a specific job:
- Vector database — Qdrant, self-hosted. Vectors in, neighbors out. Running my own instance means the index lives on my server, not in someone's cloud. Qdrant is the one I run, in Docker, with the same backup discipline as everything else.
- Embedding model — a small Japanese-optimized model. My text is a mix of Japanese and English, and generic English embedding models degrade on Japanese. I use a small Qwen3-4B-based embedding model with 2560-dim vectors. Small matters: embeddings are the highest-volume inference in the stack, so the model's size is a cost line, not a detail.
- Memory layer — Mem0 (OSS). The open-source self-hosted version gives the agent-facing tools: search before answering, add when it learns something, update when a fact changes, delete when it goes stale. Configured with my own LLM endpoint, my own embeddings, my own vector store.
The operational warts (this is the honest part)
Self-hosting memory is not set-and-forget. The pieces that bite:
- The embedding key is statically embedded in the config. When the model provider rotates keys, the config needs a manual update. There is no auto-rotation, and forgetting it means silent embedding failures.
- Vector stores are append-heavy. Old facts linger. Without hygiene, the store fills with superseded entries and the search quality degrades.
- Memory is only as good as its write discipline. An agent that never saves learns nothing. The workflow has to include explicit saves: when a durable fact surfaces, it gets stored, not just answered.
Memory hygiene rules I enforce
- Search before answering. Multi-angle searches for multi-part questions, with follow-up searches on what the first results surface. One search is rarely enough.
- Update in place, do not duplicate. When a fact changes, the old entry is replaced, not appended. Duplicate memories are how agents contradict themselves.
- Delete what is stale. Task progress and session state do not belong in memory. They belong in session history, which is searchable separately. Memory holds durable facts — preferences, environment details, conventions — not yesterday's to-do list.
- Keep memory compact. Memory is injected into every turn. Every entry costs tokens every single time. Compact, high-signal entries are a performance decision, not a style preference.
What memory is not
Memory is not a task tracker. That is what session history is for — and searching past sessions is a different, cheaper operation than stuffing everything into a vector store. The rule I use: if a fact will be stale in a week, it does not belong in memory.
What does your agent's memory store, and when did you last prune it?
Originally published at agentjournal.dev.
Top comments (0)