<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Butter Ngo</title>
    <description>The latest articles on DEV Community by Butter Ngo (@butterngo).</description>
    <link>https://dev.to/butterngo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F218044%2F46caed83-c195-4077-9bda-2f811439baef.jpeg</url>
      <title>DEV Community: Butter Ngo</title>
      <link>https://dev.to/butterngo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/butterngo"/>
    <language>en</language>
    <item>
      <title>My agent's memory was ranking by age, and the counter said otherwise</title>
      <dc:creator>Butter Ngo</dc:creator>
      <pubDate>Fri, 04 Dec 2026 00:46:26 +0000</pubDate>
      <link>https://dev.to/butterngo/my-agents-memory-was-ranking-by-age-and-the-counter-said-otherwise-34hm</link>
      <guid>https://dev.to/butterngo/my-agents-memory-was-ranking-by-age-and-the-counter-said-otherwise-34hm</guid>
      <description>&lt;p&gt;My coding agents write small memories ("this API needs a header", "run X before Y") and get them back at the start of every session. The recall step sorted by &lt;strong&gt;importance&lt;/strong&gt;, then by &lt;strong&gt;recall_count&lt;/strong&gt;: how many times a memory had been returned before.&lt;/p&gt;

&lt;p&gt;It looked reasonable. It wasn't.&lt;/p&gt;

&lt;h2&gt;
  
  
  The measurement
&lt;/h2&gt;

&lt;p&gt;Over 509 memories, I compared &lt;code&gt;recall_count&lt;/code&gt; with "number of sessions started since the memory was written".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spearman correlation: 0.999.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every session start returned the memories and added +1 to each. So the counter only measured age. Sorting by it meant &lt;em&gt;oldest first&lt;/em&gt;, and every recall made the old ones stronger. Meanwhile one scope had 141 memories, and every session start loaded all of them: up to ~180k characters of mostly irrelevant context.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Rank by relevance to the current task: &lt;strong&gt;BM25&lt;/strong&gt; (SQLite FTS5) over the memory text, with the task title + body as the query.&lt;/li&gt;
&lt;li&gt;Multiply by importance and an &lt;strong&gt;age decay&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;score = bm25 × (importance / 100) × 2^(−age_days / h)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Return at most &lt;strong&gt;10&lt;/strong&gt; memories.&lt;/li&gt;
&lt;li&gt;Recall is now read-only: it no longer changes the counter.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Picking h by replay, not by feel
&lt;/h2&gt;

&lt;p&gt;Most write-ups pick a half-life by hand (a week, 30 days). I replayed &lt;strong&gt;141 real past session starts&lt;/strong&gt;: for each, rank only the memories that existed at that moment and see where the relevant ones land.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;half-life h&lt;/th&gt;
&lt;th&gt;MRR&lt;/th&gt;
&lt;th&gt;recall@10&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1 day&lt;/td&gt;
&lt;td&gt;0.708&lt;/td&gt;
&lt;td&gt;0.800&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;3 days&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0.743&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0.793&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7 days&lt;/td&gt;
&lt;td&gt;0.724&lt;/td&gt;
&lt;td&gt;0.777&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;30 days&lt;/td&gt;
&lt;td&gt;0.732&lt;/td&gt;
&lt;td&gt;0.689&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;no decay&lt;/td&gt;
&lt;td&gt;0.639&lt;/td&gt;
&lt;td&gt;0.642&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Without BM25 (decay alone) the best MRR was 0.686: the word match is what puts the right memory first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveat
&lt;/h2&gt;

&lt;p&gt;"Relevant" here means a memory written on the same, parent, child or sibling task. Sibling tasks run close together in time, so this label favours recent memories and probably flatters short half-lives. I'll re-run the sweep once I log which recalled memories were actually used.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaway
&lt;/h2&gt;

&lt;p&gt;A usage counter that the read path itself increments is not a usefulness signal: it is a clock with a feedback loop. Check what your ranking feature correlates with before you trust it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;p&gt;It lives in &lt;a href="https://github.com/butterngo/choda-deck" rel="noopener noreferrer"&gt;choda-deck&lt;/a&gt;, my open-source task tracker for coding agents:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ranking: &lt;a href="https://github.com/butterngo/choda-deck/blob/dee0a19/src/core/domain/repositories/agent-memory-repository.ts" rel="noopener noreferrer"&gt;agent-memory-repository.ts&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Half-life sweep: &lt;a href="https://github.com/butterngo/choda-deck/blob/dee0a19/scripts/memory-half-life-sweep.ts" rel="noopener noreferrer"&gt;memory-half-life-sweep.ts&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>search</category>
      <category>llm</category>
    </item>
  </channel>
</rss>
