# Long-term memory for AI agents

- URL: https://bodhamlabs.com/research/agent-memory
- Theme: Memory & retrieval
- Area: AGENT MEMORY · MCP
- Status: IN USE — Used in our own daily work; log on file.
- Period: Aug 2025–May 2026
- Updated: 2026-10-12
- Author: Prabhakar Chandra, Bodham Labs

## Question

Can a small, fully local server give AI coding agents a memory that lasts between sessions?

## Summary

A local MCP memory server for AI coding agents, used daily from March to May 2026. Why we took the language model out of the query path.

## What we built

- Nexus RAG: a local MCP server, over stdio, that gives AI coding agents long-term memory.
- Vectors in ChromaDB with HOT, WARM and COLD tiers and time decay. An entity graph in Neo4j.
- Small models for each job: all-MiniLM for embeddings, GLiNER for entity extraction, and Qwen3:8b only for offline consolidation.
- Time decay in ranking: score = similarity × max(0.3, exp(−λ · age in days)). The design paper set λ = 0.05 on days since last access; the code we ran uses λ = 0.5 on days since a memory was created, so ranking strongly favours the last two or three days.
- A surprise flag: a new chunk that is very similar to an old one but says something different is flagged. This prevents silent overwrite of decisions.
- A router with no ML model in it, because the set of operations is small and deterministic.

## Evidence

| What | Value | Where it was recorded |
| --- | --- | --- |
| Bootstrap starts | 505 | MCP server log, 9 Mar – 21 May 2026 |
| memory_query calls | 111 | MCP server log, 9 Mar – 21 May 2026 |
| memory_ingest calls | 82 | MCP server log, 9 Mar – 21 May 2026 |
| Tier moves | Real hot → warm → cold moves recorded | MCP server log, 9 Mar – 21 May 2026 |
| Local 8B model, generation speed on CPU | about 3.58 tokens/s | CPU benchmark, cited in our internal research paper |
| Time to write one answer with that model | roughly 60–120 s | internal research paper |
| Retrieval latency, vector path (embed + search + rank) | p50 16.4 ms · p95 19.1 ms · p99 20.6 ms | our benchmark, 103 queries × 3 passes, laptop CPU (i5-12500H), Oct 2026 |
| Of which: embedding the question | p50 9.8 ms | same benchmark |
| Store searched | 46 active chunks (hot 10, warm 36); 192 archived | same benchmark |
| Cold start (load PyTorch, ChromaDB, embedding model) | about 17.8 s, once per session | same benchmark |
| Process memory after loading / peak | 511 MB / 545 MB | same benchmark, measured |

## Where it led

- The biggest change was removing synthesis from the query hot path. A local 8B model took roughly 60–120 s to write an answer. Now the server returns raw passages, and the calling agent writes the answer.
- A 1.7B model (SmolLM2) hallucinated entities during extraction. We switched to GLiNER, because it can only select substrings that exist in the input text.
- An SSE transport through a Node bridge failed. We moved to stdio.
- The project moved from a first cloud version (Neon and OpenAI, Aug 2025) to fully local (Mar 2026). It was then used daily until May 2026.
- A proper benchmark in Oct 2026 (309 timed queries) put the vector query path at about 16 ms at the median on a laptop CPU, with embedding the question the largest part. Our March figures came from 5 queries and are withdrawn.

## Open questions

- How does latency grow with a store of thousands of chunks, and with the graph lookup and stdio transport included?
- What is recall on real questions, rather than on text taken from the store?
- Does the surprise flag catch the contradictions that matter, and how often does it flag by mistake?

## Next step (not done yet)

Benchmark the full MCP path (graph lookup and stdio transport included) on a larger store, and run a recall test on real questions.

## Related notes

- [Why our agent memory stopped waiting for a language model](https://bodhamlabs.com/notes/language-model-out-of-search-path)

## References

- [Model Context Protocol](https://modelcontextprotocol.io)
- [GLiNER: Generalist Model for Named Entity Recognition using Bidirectional Transformer (arXiv:2311.08526)](https://arxiv.org/abs/2311.08526)
