<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>RRF on RockB</title><link>https://baeseokjae.github.io/tags/rrf/</link><description>Recent content in RRF on RockB</description><image><title>RockB</title><url>https://baeseokjae.github.io/images/og-default.png</url><link>https://baeseokjae.github.io/images/og-default.png</link></image><generator>Hugo</generator><language>en-us</language><lastBuildDate>Thu, 19 Nov 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://baeseokjae.github.io/tags/rrf/index.xml" rel="self" type="application/rss+xml"/><item><title>Elasticsearch as Agent Memory: three indices, hybrid RRF retrieval, and the 0.89 recall number Elastic published</title><link>https://baeseokjae.github.io/posts/persistent-agent-memory-on-elasticsearch-building-0-89-recall/</link><pubDate>Thu, 19 Nov 2026 00:00:00 +0000</pubDate><guid>https://baeseokjae.github.io/posts/persistent-agent-memory-on-elasticsearch-building-0-89-recall/</guid><description>Map agent memory onto Elasticsearch with episodic, semantic and procedural indices, BM25 plus dense retrieval fused by RRF at rank_constant 30, supersession, and per-user document-level security, with the vendor-reported 0.89 recall@10 in its real scope.</description><content:encoded><![CDATA[<p>You build agent memory on Elasticsearch by splitting it into three indices — episodic events, semantic facts, procedural playbooks — writing each memory once into a BM25 field and a <code>semantic_text</code> field, recalling with a hybrid query that fuses 80 keyword and 80 dense candidates through reciprocal rank fusion at <code>rank_constant=30</code>, reranking the merged pool with a cross-encoder, hiding contradicted documents behind a <code>superseded_by</code> filter, and isolating tenants with a query-level security rule. That is the shape of the reference implementation Elastic Search Labs published on 2026-06-16, described in <a href="https://www.elastic.co/search-labs/blog/agent-memory-elasticsearch">Agent memory on Elasticsearch: hybrid retrieval and DLS</a>.</p>
<p>The number usually attached to that design — recall@10 of 0.89 — is the vendor&rsquo;s own eval result over 168 questions. It is not a measurement by this site, and nothing below claims to have reproduced it. The rest of this page is the layout, the query mechanics, the failure modes and the evaluation protocol you need to produce your own number on your own corpus.</p>
<h2 id="what-the-089-actually-measures-and-what-it-does-not">What the 0.89 actually measures, and what it does not</h2>
<p>The vendor post reports R@10 averaging 0.89 over 168 QA-style questions, with zero cross-tenant leaks, and states that the reranker has serving-side variance: across four back-to-back runs R@10 landed at 0.85, 0.88, 0.89 and 0.893. Per type, semantic facts are the harder case at about 0.81, episodic averages 0.98 and procedural reaches 1.0. The evaluation is gated in CI at R@10 ≥ 0.85, R@5 ≥ 0.75 and leaks = 0, so a regression fails the build rather than being noticed later. Read the attribution precisely: <strong>Elastic Search Labs reports</strong> those figures for its own eval set; the spread across runs is 0.043.</p>
<table>
	<thead>
			<tr>
					<th>Reported figure</th>
					<th>Value</th>
					<th>Scope</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>R@10, overall</td>
					<td>0.89 averaged; 0.85 / 0.88 / 0.89 / 0.893 across four runs</td>
					<td>Vendor QA-style eval, 168 questions</td>
			</tr>
			<tr>
					<td>R@5, overall</td>
					<td>≥ 0.75 gate</td>
					<td>Same eval; no per-run R@5 published in the post body</td>
			</tr>
			<tr>
					<td>R@10, semantic</td>
					<td>≈ 0.81</td>
					<td>Same eval, semantic-fact subset</td>
			</tr>
			<tr>
					<td>R@10, episodic</td>
					<td>0.98</td>
					<td>Same eval, episodic subset</td>
			</tr>
			<tr>
					<td>R@10, procedural</td>
					<td>1.0</td>
					<td>Same eval, procedural subset</td>
			</tr>
			<tr>
					<td>Cross-tenant leaks</td>
					<td>0</td>
					<td>Same eval</td>
			</tr>
	</tbody>
</table>
<p>What that number is not: it is not a benchmark of Elasticsearch against Qdrant, Weaviate or pgvector, and it is not measured on your documents. The post is explicit about how the eval is built — QA-style passage retrieval, in which an LLM writes two questions a user might plausibly ask whose answer is that doc, and the retriever then has to surface the source doc in the top-k — and it links <a href="https://github.com/noamschwartz/atlas-memory-demo">the full implementation</a>. The boundary is narrower than &ldquo;no fixture exists&rdquo; and wider than &ldquo;you can re-run 0.89&rdquo;: the question set is LLM-generated and cached on disk (<code>qa_questions_cache.json</code>) so re-runs are deterministic against a fixed question set, which makes the protocol reproducible while leaving 0.89 tied to that generated set and the persona corpus behind it, not to a static fixture handed to readers. Treat 0.89 as evidence that a hybrid-plus-rerank pipeline on this engine reached high recall on one generated question set, and as a reason to build your own eval before you tune anything.</p>
<h2 id="three-indices-three-lifecycles">Three indices, three lifecycles</h2>
<p>The design separates memory by how it ages, not by topic. Each type gets its own index because each has a different write rate, a different staleness rule and a different update path; collapsing them into one index with a <code>type</code> field makes every decay and isolation filter branch on a value the engine cannot use for routing.</p>
<table>
	<thead>
			<tr>
					<th>Memory type</th>
					<th>What it stores</th>
					<th>Date field used for decay</th>
					<th>Update rule</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Episodic</td>
					<td>Timestamped events from a session</td>
					<td><code>timestamp</code> (event time)</td>
					<td>Written constantly, decays with age</td>
			</tr>
			<tr>
					<td>Semantic</td>
					<td>Distilled stable facts about a user</td>
					<td><code>last_used_at</code> (set at write, bumped on recall)</td>
					<td>Curated, deduped, superseded on contradiction</td>
			</tr>
			<tr>
					<td>Procedural</td>
					<td>Multi-step playbooks with <code>success_count</code> / <code>failure_count</code></td>
					<td>none — exempt from decay</td>
					<td>Counters updated when a fix is confirmed or rejected</td>
			</tr>
	</tbody>
</table>
<p>Alongside the three memory indices sits a fourth retrieval surface: the world data already in the cluster (product catalog, reference content). It is not memory, but it has to be recallable in the same query, which is why the isolation rule later has to admit documents that carry no <code>user_id</code> at all.</p>
<h2 id="one-write-two-retrieval-legs">One write, two retrieval legs</h2>
<p>Each document is indexed twice from a single write. The raw text lands in the BM25 inverted index, and <code>copy_to</code> routes the same value into a <code>semantic_text</code> field that generates dense vectors through an inference endpoint. That keeps one source of truth while giving the query two independent signals:</p>
<ul>
<li><strong>BM25</strong> anchors literal tokens that paraphrase destroys — version numbers, error codes, product names, exact identifiers.</li>
<li><strong>Dense retrieval</strong> catches the same intent expressed in different words, which is most of what an agent sees in conversation.</li>
</ul>
<p>Both legs over-fetch 80 candidates. The two result sets are fused with reciprocal rank fusion, which combines rankings rather than scores, so the two legs never need their scores calibrated against each other. The reference implementation sets <code>rank_constant=30</code>, tighter than the documented default of 60; a lower constant increases the influence of the top-ranked documents from each leg. The <a href="https://www.elastic.co/docs/reference/elasticsearch/rest-apis/reciprocal-rank-fusion">reciprocal rank fusion reference</a> documents <code>rank_constant</code> as an optional integer that must be at least 1 and defaults to 60, and requires two or more child retrievers.</p>
<p>A Jina v2 cross-encoder then scores the merged candidates directly against the query. That second stage is where the cost lands: it runs only on the fused pool, not on the corpus, which is why the pipeline stays affordable at conversation latency. It is also the source of the run-to-run variance the vendor reports, because a hosted reranker is not bit-for-bit deterministic across calls.</p>
<h2 id="recency-and-reuse-gauss-decay-plus-a-use-count-boost">Recency and reuse: gauss decay plus a use-count boost</h2>
<p>Two multipliers adjust each result&rsquo;s score before the final ranking. The first is time decay: a gauss-shaped multiplier computed per index, with <code>offset=180d</code> (a flat zone where recent memories are not penalised), <code>scale=1825d</code> and <code>decay=0.5</code>. The second is a frequency refinement for semantic memory only: <code>1 + log10(1 + use_count) * 0.2</code>, roughly a 1.2× boost after ten recalls and 1.4× after a hundred.</p>
<p>The engineering detail worth copying is where the decay lives. Elasticsearch&rsquo;s native <code>gauss</code> decay takes one field name that must exist on every index in the search, and episodic decays on <code>timestamp</code> while semantic decays on <code>last_used_at</code>. The reference implementation therefore computes the same gauss shape in a Painless script that branches on <code>_index</code>, keeping the two date fields in one query. The <a href="https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-function-score-query">function score query reference</a> documents the decay functions (<code>gauss</code>, <code>linear</code>, <code>exp</code>) and the <code>function_score</code> composition; a single <code>function_score</code> with <code>score_mode</code> and <code>boost_mode</code> both set to <code>multiply</code> is what the post shows for the combined factors.</p>
<p>Procedural memory is deliberately exempt: a playbook that worked two years ago is not stale, and its counters carry the signal instead. Semantic memory gets one more tilt — a catalog source prior of 0.85 so user memory wins near-ties against shared catalog text, without preventing the catalog from winning when it is clearly the better match.</p>
<p>What the post does not publish is an ablation: no run separates how much of the recall came from decay, from the use-count boost, or from the source prior. Keep the constants as a defensible starting point and change them only when your own eval set can show the change helps — the vendor itself says the scale should be tightened for fast-churn domains and loosened for personal-assistant memory where facts stay relevant for years.</p>
<h2 id="contradictions-supersede-do-not-delete">Contradictions: supersede, do not delete</h2>
<p>Append-only memory rots, and overwriting destroys the audit trail. The reference protocol stamps the old document with <code>superseded_by</code> and <code>superseded_at</code> and writes the replacement with a confidence level that depends on which contradiction mode was passed: a <code>natural</code> update (moved house, upgraded plan, changed preference) is written at full confidence, while a <code>harsh</code> contradiction — the customer explicitly denying or correcting the prior fact — carries a small confidence penalty on the new assertion. Every recall then applies <code>must_not exists superseded_by</code>, so the contradicted document stops surfacing while the chain of how a belief changed stays queryable for debugging.</p>
<p>The post does not say what happens when two writers supersede the same document concurrently; the only pattern it shows is one writer calling <code>write_memory</code> with a <code>supersedes_id</code>, so concurrent supersession is the decision left to you. Where superseded documents live, it does specify. They accumulate in the index and stay invisible to recall behind the <code>must_not exists superseded_by</code> filter unless a query explicitly asks for them with <code>include_superseded=True</code>; in production a periodic reindex moves them into a separate archive index that Elasticsearch&rsquo;s Index Lifecycle Management ages through cold and frozen tiers using searchable snapshots, so the audit chain stays queryable on cold storage while the active semantic index stays hot and small. Explicit deletion is a separate path: <code>forget_memory</code> is reserved for a user asking to forget something, and supersession is not deletion — the old document stays in the index with its link to the replacement. What an explicit forget actually removes in this engine is a different measurement, and this page does not make it.</p>
<h2 id="same-turn-visibility-is-a-storage-decision">Same-turn visibility is a storage decision</h2>
<p>An agent that writes a memory and recalls it in the same turn hits the refresh gap: Elasticsearch&rsquo;s default asynchronous refresh, plus the inference cost of generating the embedding, can leave the just-written document invisible to the next query. The reference implementation passes <code>refresh=True</code> on every <code>write_memory</code> call, forcing the shard to refresh before the call returns.</p>
<p>That is the simple correct choice at low write volume and the wrong one at high write volume — the post says so explicitly and suggests shifting to asynchronous indexing plus an agent-layer &ldquo;just-written&rdquo; register that holds recent writes in the model&rsquo;s context until the index catches up. Pick per workload: single-conversation agents can afford the refresh, high-throughput ingestion cannot.</p>
<h2 id="isolation-what-the-cluster-guarantees-and-what-your-code-guarantees">Isolation: what the cluster guarantees, and what your code guarantees</h2>
<p>The reference design puts the isolation rule in the cluster with document-level security. Each user gets an API key whose role descriptor carries a DLS query admitting documents whose <code>user_id</code> equals that user, plus documents that have no <code>user_id</code> field at all (the shared catalog). An agent using that key can run any query it likes and the cluster will not return another user&rsquo;s memories. The retriever also applies a <code>user_id</code> filter in code, explicitly as a second layer against configuration drift — a new index template without the DLS clause, a role edited and the clause dropped, an admin key reused by mistake. DLS is the architecture; the code filter is the cheap paranoia pass.</p>
<p>One boundary this page will not cross: which subscription tier includes document-level security was not confirmed during this check, and the reference post does not state it. Elasticsearch&rsquo;s subscription documentation is where that has to be settled for your deployment. Until you have confirmed it, the honest reading is that cluster-enforced isolation is available on tiers that include document-level security — not that a basic self-managed node enforces it. If your tier does not, the application-level filter is not a defence-in-depth extra; it is your only boundary, and it belongs in the repository&rsquo;s query builder rather than in each caller.</p>
<h2 id="producing-your-own-recall-number">Producing your own recall number</h2>
<p>The vendor number is not portable, so the useful deliverable is the protocol. Five things make a recall measurement reusable:</p>
<ol>
<li><strong>A pinned corpus snapshot.</strong> Record the exact document set — commit hash or a content-addressed manifest — so the same questions always run against the same passages.</li>
<li><strong>One gold passage per question.</strong> Recall is only meaningful if there is exactly one correct target per question, chosen before you see what the retriever returns.</li>
<li><strong>Recall@5 and recall@10 per memory type.</strong> Aggregate numbers hide the pattern the vendor found: semantic facts are the weak slice while episodic and procedural are near-ceiling. Per-type reporting tells you where to tune.</li>
<li><strong>Three repeat runs and the spread.</strong> A hosted reranker varies between calls; a single run is not a measurement. Report the range, not just the mean.</li>
<li><strong>A gate that fails loudly.</strong> Copy the vendor&rsquo;s shape: floors on R@10 and R@5 plus an assertion that cross-tenant leaks equal zero, run in CI on every change to mappings, analyzers or retrieval parameters.</li>
</ol>
<p>The public reference for all five is <a href="https://github.com/noamschwartz/atlas-memory-demo/blob/main/backend/scripts/atlas/eval_recall.py">the vendor&rsquo;s own harness</a>: it samples memory docs per persona across the three indices, generates two questions per doc, caches them in <code>qa_questions_cache.json</code> so re-runs are deterministic against a fixed question set, reports Recall@1 / Recall@5 / Recall@10 plus MRR capped at k=10, and runs a tenant-isolation sweep that takes one QA pair per owner and memory type, replays that pair&rsquo;s first question as each other user, and treats any hit as a leak — one cross-user query per sampled pair, not a full replay of the question set. Read it as the shape to copy rather than as proof that 0.89 reproduces: it ships the method, but its question set is LLM-generated and the persona corpus is its own. This article still ships no corpus, question set or score file — the source check described at the end is a private author record, not a downloadable dataset. Build the five pieces on your documents and you get a number with provenance, which is the only kind worth quoting.</p>
<h2 id="what-to-build-first">What to build first</h2>
<p>Start smaller than the reference design. One tenant, one semantic index, BM25 plus dense retrieval with RRF, and a fifteen-question eval set is enough to prove the plumbing and to establish your baseline. Add the second and third indices when you can name the lifecycle difference they encode. Add decay, the use-count boost and the source prior only when the eval set exists to show each one helps — otherwise you are tuning constants you cannot defend.</p>
<p>Instrument three things from day one: which index answered each recall, whether the gold passage appeared in the reranked top five, and whether any recall returned a document belonging to another <code>user_id</code>. Those three signals turn an incident (&ldquo;the agent forgot&rdquo;) into a diagnosis (&ldquo;semantic recall dropped because the supersession filter now hides two of the three candidate facts&rdquo;).</p>
<p>Expect three failure modes in this order: semantic recall lagging episodic badly, because sibling facts collide; same-turn misses when a write is not refreshed before the recall; and isolation that fails open when a role descriptor is edited without the DLS clause. The first needs better extraction or a reranker, the second needs a refresh policy, and the third needs a test that asserts the leak count is zero rather than a reviewer&rsquo;s confidence.</p>
<h2 id="sources-and-verification">Sources and verification</h2>
<p>Every external fact above was read from the linked page during this check. The source reads are timezone-aware UTC and are listed with the round that made them, because two of them were re-read after the first draft: the vendor architecture post at 2026-11-19T09:42:37Z (earlier reads at 2026-11-02T07:28:56Z and 07:37:01Z), the reciprocal rank fusion reference at 2026-11-02T07:28:59Z, and the function score reference at 2026-11-02T07:29:02Z. The vendor&rsquo;s eval harness was re-read as raw source at 2026-11-19T09:42:37Z; its docstring and its sweep function are the basis for the Recall@1/5/10, MRR and isolation-sweep description above. What was not done: no Elasticsearch cluster was started for this page, no recall run was performed, the harness was not executed, and the DLS subscription tier was not confirmed. The 0.89 figure therefore carries vendor attribution throughout, and the pipeline constants are described as the reference implementation&rsquo;s choices rather than as tuned results. Model names (Jina v5 embeddings via <code>semantic_text</code>, Jina v2 cross-encoder) are as stated in the vendor post and were not re-verified against model cards; pin the versions you actually deploy, because embedding and reranker behaviour changes with them.</p>
<p>For the conceptual split behind episodic, semantic and procedural memory, the <a href="/posts/agent-memory-architecture-guide-2026/">agent memory architecture guide</a> covers the types without the Elasticsearch mechanics. If the question is whether to add a separate vector database instead of using the search engine you already run, the <a href="/posts/vector-database-comparison-2026/">vector database comparison</a> frames that trade-off. And if you would rather not operate the store yourself, <a href="/posts/agent-memory-cloudflare-workers/">agent memory on Cloudflare Workers</a> covers a managed substrate with different compaction semantics.</p>
]]></content:encoded></item></channel></rss>