The claim that 'typed memory beats flat retrieval' is usually asserted. Here it is measured on a concrete policy, with committed data — and the measurement also reveals where the policy is fragile: a hard criticality threshold that gives near-identical constraints qualitatively different protection.
The question, made falsifiable
A recurring argument in agent design is that a typed memory store (facts, constraints, episodes with criticality) is better than treating retrieval as memory — ranking everything by similarity and filling the context window. I have made that argument in prose before. This article tests it on a specific system I built, memcell, whose `baseline_v0` policy assigns a retrieval mode per cell and enforces a token budget by priority (constraints > criticality > future-utility > score > confidence).
Concretely: in a regulated case, one cell is a critical constraint — `account under fraud review: no outbound transfers until review closes` (criticality 0.95). The agent's query is `review account 456 transactions for fraud indicators`. By construction, that query shares few words with the constraint but many words with wrong distractor cells like `fraud review transactions … review completed, no constraints apply`. The falsifiable question: under a tight budget and growing distractor pressure, does the constraint stay in the selected context?
- Typed system: the real memcell pipeline — `retrieve_cells` (top-k) then `apply_baseline_v0` (criticality-aware budgeting).
- Flat baseline: rank purely by word overlap, greedily fill the same token budget. No types, no criticality.
- Metric: critical-constraint retention rate. Everything deterministic — no LLM, no randomness.
Result: 0% vs 100% retention
Sweeping the number of wrong-but-similar distractors from 0 to 24 (budget = 120 tokens, k = 10), the flat lexical retriever keeps the critical constraint in 0 of 13 conditions — a retention rate of 0.00. The typed pipeline keeps it in all 13 — a retention rate of 1.00. The gap is not marginal; it is total, because the lexical trap is exactly the case typed memory is designed for: the right cell does not look like the query, and the wrong cells do.
A natural objection is that the typed advantage lives only in the final selection step, so a large enough distractor set should push the constraint out of the top-k during retrieval before the policy ever sees it. I tested that by sweeping k from 5 to 30 at 20 distractors. The constraint is retained at every k, including k = 5. The reason — which I only confirmed by reading the scorer — is that memcell's retrieval score itself folds in `0.5 × criticality`, so the 0.95 constraint never falls out of the top-k. Criticality-awareness lives in retrieval and selection together, not only in the final policy.
- flat top-k lexical: constraint retention 0.00
- typed (memcell): constraint retention 1.00 (robust across distractors 0–24 and k 5–30)
- Mechanism: criticality enters the retrieval score, so the constraint survives the k-cutoff that would sink a purely-lexical ranking.
The finding worth keeping: a discontinuity at criticality 0.7
Measuring a system you trust is most useful when it surprises you. In a second experiment I swept the token budget from 10 to 400 with k large enough to disable the retrieval pre-filter, isolating the policy's budgeting. The 0.95 constraint is the last thing the policy gives up: it survives down to a 20-token budget — essentially its own size — while episodes and facts are squeezed out first. That is the intended behavior, and it holds.
But I also planted a second constraint at criticality 0.69 — just below the policy's hard `criticality ≥ 0.7` cutoff for 'constraint mode'. It is dropped much earlier (gone below a 40-token budget), because under the cutoff it no longer gets constraint priority and competes with ordinary cells on raw criticality. Two near-identical constraints — 0.69 vs 0.71 — receive qualitatively different protection. If criticality is ever estimated by a model rather than hand-set, that knife-edge is a latent safety bug: a small estimation error around 0.7 flips whether a safety constraint is protected at all. The fix is to make the priority continuous near the threshold rather than a hard gate.
- critical constraint (0.95): retained down to a 20-token budget (dropped last)
- near-threshold constraint (0.69): dropped below a 40-token budget
- Implication: replace the hard 0.7 gate with a smooth priority, or the policy is brittle to criticality-estimation error.
Honesty notes and limits
The flat baseline is lexical (Jaccard word overlap), not embedding-based. An embedding retriever would handle paraphrase better, but it still has no notion of criticality or type, so the qualitative gap should persist; quantifying it needs an embedding model, which this study does not run. The corpus is a single hand-built case with hand-set criticality, so these results characterize the policy's behavior, not real-world task accuracy. Plugging an LLM judge and a multi-case suite on top is the obvious next step.
What makes this research rather than a demo is that every number here is produced by running the real policy code, the experiments are deterministic, and the data, plots, and regression tests are committed in the repo. Anyone can reproduce them with two commands. The contribution is small but real: a measured comparison plus a specific, fixable fragility in the policy.
Implementation notes
- Reproduce: `./.venv/bin/python -m studies.study_b_policy` and `./.venv/bin/python -m studies.study_c_typed_vs_flat` in the memcell-rl repo. Results land in `studies/results/` as JSON + PNG.
- The findings are pinned by regression tests (`tests/test_studies.py`): if a policy change breaks constraint protection, CI fails.
- When a selection policy uses hard thresholds on a continuous feature, test cells on both sides of the threshold — that boundary is where safety behavior changes discontinuously.