How I measure coding-agent memory retrieval, including where it fails

2026-11-28来源 dev.toEnglish
How I measure coding-agent memory retrieval, including where it fails

Here is a situation most teams using coding agents will recognise.

On Tuesday, your agent spends forty minutes working out why a retry around the payments webhook keeps failing. It isn't the backoff. The upstream returns a 409 on the second attempt because the idempotency key is regenerated on every retry. The fix is two lines. The understanding behind it took most of the afternoon.

On Thursday, a teammate picks up a related ticket. Their agent starts from zero. It proposes raising the backoff. It suggests the same dead ends. Nobody wrote the finding down, because writing things down is the step that always gets skipped.

That gap, where one agent learned something and the next one never hears about it, is the problem I'm working on with Palace. Palace is an MIT-licensed memory engine for coding agents: one Rust binary, one SQLite file, a local embedder, and hybrid BM25 + vector search, exposed over MCP to Claude Code, Cursor, Codex, OpenCode and other clients. (It is a separate project from the Python "mempalace". The two get confused.)

A memory layer is only useful if it brings back the right thing when asked. So this post is about how I measure that, which numbers I report, and where the numbers fall down.

Bar charts: recall_any@5 0.987 vs recall_all@5 0.900 overall and 0.992 vs 0.818 on multi-session questions; at 10x haystack R@5 falls from 0.987 to 0.919 and R@1 from 0.915 to 0.732

What is measured: retrieval recall, not QA accuracy

The benchmark is LongMemEval. Each question comes with its own haystack of past chat sessions, and one or more of those sessions holds the answer.

Many memory systems report QA accuracy: an LLM reads what was retrieved, writes an answer, and another LLM grades it. That measures the whole pipeline, including the reader model.

I report something narrower: session-level retrieval recall. For each question, Palace returns its top K results. If a gold session is among them, it counts as a hit. No LLM reads anything and no LLM grades anything.

That choice has consequences you should keep in mind:

  • A retrieval number and a QA number can't be compared directly. If you see a retrieval figure placed next to someone else's end-to-end QA score, the comparison is misleading.
  • Retrieval is necessary but not sufficient. If the right session is at position 4 and your agent only reads position 1, the agent still answers wrong.
  • What I can claim is narrower: when the agent searches, the session it needs is usually in what comes back.

The setup

  • Data: longmemeval_s_cleaned.json (about 50 sessions, ~115k tokens per question) and longmemeval_m_cleaned.json (about 500 sessions, ~1.5M tokens per question), from the cleaned release on Hugging Face.
  • Storage: each session goes through the same normaliser and chunker that palace mine-convos uses on real chats. One drawer per user turn and its reply, stored verbatim. Nothing is summarised, filtered or extracted by an LLM.
  • Retrieval: Palace's normal hybrid search (BM25 fused with cosine similarity, plus its ranking rules), with the default minilm-l6-v2-q8 embedder. A session ranks by its best drawer.
  • Dates: each question is asked on its own question_date, so "two weeks ago" resolves the way it would in a live palace.
  • Hardware: CPU only, Windows, 16 threads. No GPU, no API calls.

The headline number, and the stricter one

On s_cleaned, 470 questions (the 30 abstention questions excluded, which is the usual convention):

Metric @1 @5 @10
recall_any 0.915 0.987 0.996
recall_all 0.900 0.938

On all 500 questions, R@5 is 0.986.

The 0.987 is the number people quote. It's real, but it's the lenient one, and you should know why.

Some questions need information from more than one session. "How many times did I change the deploy target this year?" might need three. recall_any counts the question as a hit if any one gold session is in the top 5. recall_all only counts it if every gold session is there.

For an agent, recall_all is often the one that matters. If the answer depends on combining two earlier decisions and only one comes back, the agent answers with half the story and sounds confident doing it.

Broken down by question type, recall_all@5 looks like this:

Question type n recall_all@5 recall_all@10
knowledge-update 72 0.986 1.000
multi-session 121 0.818 0.876
single-session-assistant 56 1.000 1.000
single-session-preference 30 0.933 0.933
single-session-user 64 1.000 1.000
temporal-reasoning 127 0.827 0.906

Multi-session questions go from 0.992 under recall_any to 0.818 under recall_all. Roughly one in five multi-session questions is missing at least one of the sessions it needs in the top 5. That's the biggest gap in the results, and it's the one I'd want to know about if I were evaluating a memory tool.

On cost: the five drawers behind the @5 figures hold about 1,700 tokens between them, about 1.3% of the haystack (counting four bytes of text per token). Average query time, including embedding the question, was 6 ms.

What happens at 10x the haystack

s_cleaned gives each question about 50 sessions. A real team's memory after a few months is larger than that. So I also run m_cleaned, with about 500 sessions per question and around 4,000 drawers to search.

Haystack R@1 R@5 R@10
s_cleaned (~50 sessions) 0.915 0.987 0.996
m_cleaned (~500 sessions) 0.732 0.919 0.949

R@5 drops from 0.987 to 0.919, and R@1 falls much further, from 0.915 to 0.732. With ten times the distractors, the right session is still usually in the top 5, but noticeably less often at the top. Query time goes from 6 ms to 78 ms.

If you're building on any memory layer, this is the curve worth asking about: how does recall change as the store grows?

The weakest categories

Two question types stand out on m_cleaned:

Question type n R@1 R@5
single-session-preference 30 0.300 0.700
temporal-reasoning 127 0.701 0.866
(for contrast) single-session-assistant 56 0.964 1.000

Preferences are the weakest category on both splits (0.933 R@5 on s_cleaned, 0.700 on m_cleaned). The cause is simple. "I prefer squash merges" doesn't share many words with "how should I merge this PR?". BM25 gets nothing, and a small embedding model only partly closes the gap. Palace has a dedicated pass for preference-shaped questions against tagged preference spans, and it still misses 3 in 10 at 10x scale. Only 30 questions are behind this number, so treat it as a direction rather than a precise figure.

Temporal questions ("what did I decide about caching last Tuesday?") improved once ranking started favouring drawers from the period the question points at. But on s_cleaned the three remaining temporal misses lose on topic, not on date: the gold chunk scores below unrelated chunks from the same days.

What I can't claim yet

  • Nobody else has reproduced these numbers. Everything here comes from my runs. If you rerun it and get something different, I want to know.
  • No parameters were fitted on s_cleaned. One ranking weight (how much a session's other matching chunks count) was chosen on m_cleaned data together with probes from a real palace, then frozen before the s_cleaned run. So m_cleaned is not a clean held-out set for that one weight. I'd rather tell you than have you find it in the diff.
  • LongMemEval is chat memory, not code memory. The repo also has a small coding-agent eval (51 questions about decisions, failures, commands and conventions), but the ranker's coding boosts include a few phrases taken from that eval's questions, so I don't lead with it.
  • Session-level recall is coarse. It says the right session came back. It doesn't say the agent used it well.

Reproduce it

The runner, palace-bench, lives on the benchmarks/longmemeval-beam-runner branch. Its BENCHMARKS.md has the full runbook.

git clone https://github.com/AncientiCe/palace-rs && cd palace-rs git checkout benchmarks/longmemeval-beam-runner cargo install --path . --no-default-features --features benchmarks --bin palace-bench mkdir -p data/longmemeval data/out/longmemeval curl -L -o data/longmemeval/longmemeval_s_cleaned.json \ https://huggingface.co/datasets/xiaowu0162/longmemeval-cleaned/resolve/main/longmemeval_s_cleaned.json # 470-question set (abstention excluded) palace-bench long-mem-eval data/longmemeval/longmemeval_s_cleaned.json \ data/out/longmemeval/s_cleaned --model minilm-l6-v2-q8 --chunking exchange # add --include-abstention for all 500 

Each run writes a per-case JSONL and a summary JSON, so you can check every miss yourself. Run the BM25-only smoke test first (--bm25-only --limit 3). A full hybrid run on s_cleaned takes tens of minutes on one CPU, and m_cleaned is a 2.7 GB download.

Back to Thursday's teammate

Benchmarks measure whether retrieval works. They don't fix the scenario at the top of this post, because there the problem is that the memory sits on one laptop.

On one machine, Palace already shares memory between agents: a Codex session can read what a Claude Code session wrote. For a team, the open-source client has a remote mode that points every developer's palace mcp at a shared Palace Server:

palace remote set --endpoint https://palace.yourco.internal # prompts for your ps_… key palace remote on palace remote test 

Palace Server is the paid, closed-source part, and I want to be upfront about that. It's self-hosted: it runs on your infrastructure (Postgres with pgvector, via Docker or a binary), and an offline or air-gapped install is supported, with the embedding model baked into the Docker image. Each developer gets their own API key. OIDC/SSO login, roles and an audit log of memory writes are built in. Your agents' memory never goes to my servers.

In the 90-second handoff demo, Dev A's agent records three approaches that were ruled out on a ticket, with sources. Dev B, on another machine in a fresh session, asks "what did we already rule out?" and gets all three back, each with its source link.

Handoff demo: Dev A's agent records ruled-out approaches; Dev B's agent on another machine recalls all three with sources

If your team runs into this, try it with one teammate and one ticket. The trial is self-serve: 10 seats for 60 days, no card, no sales call:
palacememory.com/trial

The engine, the benchmark runner and every number above are in the open-source repo: github.com/AncientiCe/palace-rs. If you rerun the benchmark, please post your results in the comments, including results that disagree with mine.

I'm iCe, and I build Palace on my own in Munich. Questions about the method are welcome here or in GitHub Discussions.

原文:https://www.a8q9.cn/en/article/how-i-measure-coding-agent-memory-retrieval-including-where-it-fails-5ca3e6.html

相关文章