DEV Community

Cover image for How I measure coding-agent memory retrieval, including where it fails
iCe Gaming
iCe Gaming

Posted on Edited on

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (16)

Collapse
 
analista_83 profile image
Sammi De Blas •

The sharing gap between agents is a workflow problem before it is a retrieval problem. One Rust binary with SQLite and hybrid BM25 plus vector search keeps the memory auditable, which matters when a stored finding is wrong. How do you score stale memory that still matches the query, and do you decay entries that were never reused?

Collapse
 
icegaming profile image
iCe Gaming •

Agreed, it's a workflow problem first: retrieval only helps if the finding gets written down at all, which is why the hooks prompt the agent to save decisions at the end of a session.

Stale-but-matching memory is handled in two ways. Ranking decays with age: every memory gets a recency bonus that falls off exponentially (half-life about 35 days), and queries with time phrases ("what did we decide last week") get a separate date boost. A second decay spreads results across sources, so one file can't fill the top 5.

For facts that are actually wrong, decay isn't enough, so it's explicit: the agent calls palace_kg_invalidate and adds the new fact, which closes the old one with an end date while the timeline keeps both. palace_conflicts flags facts that look stale or contradictory.

Nothing is deleted automatically, and there's no usage-based decay yet: a memory that's never retrieved isn't penalised. Removal stays explicit (palace_forget, or palace prune --older-than-days N with --dry-run). I'm interested in reuse as a ranking signal. How would you weigh it against recency?

Collapse
 
analista_83 profile image
Sammi De Blas •

A half-life works only if the decay tracks the source change, not just the date the note was written.

Thread Thread
 
icegaming profile image
iCe Gaming •

Agreed, and for anything mined from the repo that's already how it works. palace mine hashes every file's content, so when a file changes its old memories are replaced with fresh ones, and when a file is deleted its memories go with it (palace watch does the same on save). Those don't age on a clock, they follow the file.
The half-life is for notes the agent writes itself, like "we dropped X because Y". I kept those off file changes on purpose: a refactor can touch every line of a file while the decision behind it still holds, and quietly burying a valid decision is the worse failure. When a decision really is overturned, the agent closes it explicitly (palace_kg_invalidate for facts, or editing the note in place), so the old version stops competing instead of slowly fading out.

Collapse
 
princejain756 profile image
Prince Jain •

That single-session-preference drop to 0.300 R@1 on m_cleaned matches the exact failure mode I hit with my own local SQLite FTS5 + BGE memory daemon. On 150 active records across 3 machines (plus 5,310 raw staged session segments), indexing only the verbatim rule failed almost every time a later question used different phrasing.

Two changes moved the needle for me: storing multiple query-shaped intent vectors per record (779 intent embeddings across those 150 records) and pulling the 12 standing preferences and constraints out into a 1,331-char core digest loaded up front instead of making hybrid search fight distractors for them. Where I still get burned is update chains: if I tweak a workflow rule twice in one week, the older wording sometimes still outranks the newer note on BM25 until I manually mark the old entry superseded.

Since Palace avoids LLM extraction on ingest, have you tried attaching synthetic question phrasings only to those tagged preference spans, or are you keeping ingest strictly zero-LLM?

Collapse
 
icegaming profile image
iCe Gaming •

Your digest is basically what Palace does for standing rules too. The session-start hook loads the user's preferences up front, ranked and kept to a token budget, so they never have to win a search against distractors. LongMemEval doesn't use that path at all (everything sits in one haystack), so the 0.300 is the cold case: a preference that only exists somewhere in old chat history.
Ingest stays zero-LLM, on purpose. Same input gives the same index, it runs offline on a laptop, and everything search matches on is text someone actually wrote. Generated phrasings would mean ranking on a model's guess at what the question might be, and a wrong guess is hard to spot later. Preference spans get tagged by rules at write time, and preference-shaped questions get a separate pass over them.
For update chains I went explicit rather than trying to fix it in ranking: the agent edits the rule in place (the embedding is recomputed) or closes the old fact with an end date, so there's only one current wording left to find. Your intent-vector numbers are interesting though. Did the 779 vectors come from an LLM, or from templates?

Collapse
 
mohakbajaj profile image
Mohak Bajaj •

Splitting retrieval recall from downstream QA accuracy is the right call. Otherwise you never know if the search layer missed the note or the model just ignored it in context. For my own local capture vault (plain .md files with a size+mtime parse cache and substring scan, no DB), simple scan holds up fine at a few thousand notes, and the R@1 drop you measured at 10x haystack is a good reminder of where naive retrieval starts breaking down.

Collapse
 
icegaming profile image
iCe Gaming •

Thanks, that split was the main point of the post. If you can't tell a search miss from the model ignoring the note, you can't fix either.

A plain scan over a few thousand notes is a reasonable setup, especially when you wrote the notes yourself and remember the words you used. Where it starts to hurt is when the question uses different words than the note: "how should I merge this PR?" against a note saying "I prefer squash merges". That's the case the embedding half of the hybrid search is there for, and it's also where my numbers are weakest, so your instinct about where naive retrieval breaks is right.

Collapse
 
syedfahads profile image
Syed Fahad •

knowledge-update at 0.986 says the new fact comes back, but does the old one come back above it? that's where agents get burned, they read the stale note first and trust it

Collapse
 
icegaming profile image
iCe Gaming •

Usually both show up. Knowledge-update scores 0.986 recall_all@5, so the old value and the new one are almost always in the top 5 together. Between them, a recency bonus (about a 35-day half-life) puts the newer one first when the matches are close. It's a small weight, so a much stronger text match can still win. In real use the agent shouldn't leave both versions around as equals: it edits the memory in place or closes the old fact with palace_kg_invalidate, so it reads as no longer current.

Collapse
 
izgorodin profile image
Edward Izgorodin •

Newer first is the order that hurt one of the two models in StaleBench, an arXiv paper from 15 November. Table 24 builds the contexts by hand. qwen2.5:14b answers 99.1 percent of the facts correctly with only the current version, 85.0 percent when one stale version comes before it, and 31.4 percent when the stale one comes after the current one. With the stored year printed next to each version, that 31.4 percent case goes back to 92.5 percent. glm-4.6 starts at 98.7 and scores 63.7 and 59.2 in the same two orders, so it loses a lot either way and the order matters much less. So if the hook writes results in rank order, the close cases where the recency bonus decides put qwen in the worse order, the current version first. The part I would check is whether the "no longer current" mark from palace_kg_invalidate is printed next to the old text. The year is not the same signal, but it is the only such signal in that table, and for qwen it did most of the work.

Thread Thread
 
icegaming profile image
iCe Gaming •

Thanks, useful table. In Palace every search hit comes back with the date it was filed. Knowledge-graph facts come back with valid_from/valid_to and a current/ended flag, so an invalidated fact reads as ended, not just as lower in the list.

Collapse
 
paul_irolla_6b5ae261d0224 profile image
Paul Irolla •

Once retrieved memory is loaded, the agent re-reads it on every later turn, so some misses may be a size problem. Does the failure rate change once the retrieved block passes 50k tokens?

Collapse
 
icegaming profile image
iCe Gaming •

Good question, and that failure mode is real. Palace is built to stay far from it: the hooks inject only the few top-ranked memories for the current prompt, not the store. In the benchmark the top 5 results come to about 1,700 tokens in total, around 1.3% of the haystack, so the injected block never gets near 50k.

The benchmark measures retrieval (is the right session in the top K), not how the agent performs as the loaded context grows, so I haven't measured the 50k case. Keeping retrieval tight and verbatim is the design answer to it: fewer, better memories instead of a big block the agent has to re-read every turn.

Collapse
 
vexaloom-labs profile image
vexaloom-labs •

Session-level hits flatter retrieval when the useful finding is buried in a long transcript; finding the folder isn't finding the sentence.

Collapse
 
icegaming profile image
iCe Gaming •

Fair point, and it's exactly why the post calls session-level recall coarse. Two things soften it in practice. Palace doesn't store or return whole sessions: each memory is one user turn plus its reply, stored verbatim, so what the agent gets back is the exchange, not the folder. In the benchmark the top 5 come to about 1,700 tokens, so roughly 350 tokens per result. The session label is only how LongMemEval's gold answers are defined.

A stricter, exchange-level view (is the exact exchange holding the answer in the top 5) is the honest next number, and it's lower. I'm planning to publish it next to the session numbers.