<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shivamguptaxia on Medium]]></title>
        <description><![CDATA[Stories by Shivamguptaxia on Medium]]></description>
        <link>https://medium.com/@shivamguptaxia2?source=rss-2191821ad1d8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*x6wc4p64VRODldZG</url>
            <title>Stories by Shivamguptaxia on Medium</title>
            <link>https://medium.com/@shivamguptaxia2?source=rss-2191821ad1d8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 12:51:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shivamguptaxia2/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[     ]]></title>
            <link>https://medium.com/@shivamguptaxia2/-bcd968903941?source=rss-2191821ad1d8------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcd968903941</guid>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[llm-inference]]></category>
            <category><![CDATA[decode]]></category>
            <category><![CDATA[jevs]]></category>
            <category><![CDATA[typesafe-ai]]></category>
            <dc:creator><![CDATA[Shivamguptaxia]]></dc:creator>
            <pubDate>Wed, 23 Sep 2026 12:18:00 GMT</pubDate>
            <atom:updated>2026-09-23T12:32:39.567Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Decoding why Jev is 200x faster</strong></h3><h4>Short answer: it never decodes.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XQBu2J1VuVNQqweODblJ7A.png" /></figure><p>LLM inference has two stages — <strong>prefill</strong>, where all the tokens are computed over and the <strong>decode</strong> stage where we re-use the already available KV cache and compute over the last token in the sequence, to generate the next token. In one decode pass we generate just one single token.</p><p>Jev has NO DECODE STAGE, it only goes through a prefill pass and then <strong>predicts the results directly</strong>!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*4Gz1ZddVmQdXko3XZvTaEw.png" /></figure><p>For multiple questions being answered together, it likely uses <strong>block attention</strong>, where a causal block attention mask is applied over the inputs so that, the questions never see each other. Also the position ids restart after the state for every question. The state is processed once, and <strong>N questions cost one prefill of the state (+ questions) plus N short branches</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*90ZthtJZQSHBeWYxw1lLjA.png" /></figure><p>I want to discuss how kev predicts for the score, noul and choice, it isan <strong>open-source implementation of the jev model</strong>, over a qwen-3.5 base.</p><p>The<strong> token layout </strong>passed to the model is as follows : <br>&lt;state&gt; state tokens<br>&lt;q&gt; instruction tokens &lt;opt&gt; op1 tokens &lt;/opt&gt; &lt;opt&gt; op2 tokens &lt;/opt&gt; &lt;opt&gt; opK tokens &lt;/opt&gt; &lt;decide&gt;</p><p>For the prediction stage, we consider the hidden states for the &lt;/opt&gt; and the &lt;decide&gt; tokens, each of the &lt;/opt&gt; tokens <strong>look at their option and the options before that, plus the state and the instruction </strong>— they act as keys for their respective options, while the final &lt;decide&gt; token <strong>looks at all the options</strong>, it acts as the query.</p><p>After this an <strong>attention style dot product is computed</strong>, and we get the logits for each of the options.</p><p>z = (self.k(h_opts) @ self.q(h_decide)) * self.scale<br>z = z / self.temperature<br>p = softmax(z)</p><p>These <strong>probabilities are used for the final predictions</strong> for choice, noul and score (yes, even for regression like scores).</p><p><strong>Noul — the response is of binary format.</strong> The API builds two options, no then yes, optionally with the caller’s descriptions appended. Softmax over two logits gives [p_no, p_yes]. The response returns p_yes. For example:</p><p>&lt;q&gt; Does this need urgent human attention? &lt;opt&gt; no &lt;/opt&gt; &lt;opt&gt; yes &lt;/opt&gt; &lt;decide&gt; <br>-&gt; [0.07, 0.93] -&gt;<br><strong>-&gt;“noul”: 0.93</strong></p><p><strong>Choice</strong> —<strong> the model chooses one from the multiple options presented to it</strong>. Option text is formatted as ‘name’ or name: description. Softmax over K. Argmax name is the final answer.</p><p>&lt;q&gt; Which team should handle this? &lt;opt&gt; returns: Exchanges &lt;/opt&gt; &lt;opt&gt; shipping: Delivery delays &lt;/opt&gt; &lt;opt&gt; billing: Charges &lt;/opt&gt; &lt;decide&gt;<br> -&gt; [0.47, 0.28, 0.25] -&gt;<br><strong> -&gt;choice “returns”</strong></p><p><strong>Score — a regression like score is returned</strong>. One option is given per rubric level. Softmax over L levels gives a distribution over level indices 0 to L-1. Expectation over indices becomes the regression score.</p><p>&lt;q&gt; How frustrated is the customer? &lt;opt&gt; Calm &lt;/opt&gt; &lt;opt&gt; Frustrated &lt;/opt&gt; &lt;opt&gt; Very angry &lt;/opt&gt; &lt;decide&gt;<br> -&gt; [0.00, 0.56, 0.44]<br><strong> score = 0*0.00 + 1*0.56 + 2*0.44 = 1.44</strong></p><p><strong>And that’s the whole trick, the answer is in the prefill itself.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcd968903941" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OpenClaw’s memory: a deep dive]]></title>
            <link>https://medium.com/@shivamguptaxia2/openclaws-memory-a-deep-dive-2704010699f4?source=rss-2191821ad1d8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2704010699f4</guid>
            <category><![CDATA[ai-memory]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[memory-backend]]></category>
            <category><![CDATA[agentic-memory]]></category>
            <category><![CDATA[openclaw]]></category>
            <dc:creator><![CDATA[Shivamguptaxia]]></dc:creator>
            <pubDate>Sat, 27 Jun 2026 05:23:25 GMT</pubDate>
            <atom:updated>2026-06-27T05:23:25.624Z</atom:updated>
            <content:encoded><![CDATA[<p>So, I have been using openclaw, along with many of my peers, and we were impressed by how good it was at storing memories. We would often see cross session memory, facts from a conversation last week, and agents with a consistent ‘personality’</p><p>So, I decided to dive into the codebase and documentation to learn about how exactly openclaw is working under the hood.</p><p>Turns out, the design is more layered than I expected — there’s a two-tier memory model, three interchangeable backends with meaningfully different tradeoffs, and a consolidation algorithm that runs in the background. Here’s how it all fits together.</p><h3>Overview</h3><p>Memory is divided into two parts, long term memory, and short term memory. Long term memory stores permanent facts and knowledge, like the user’s name, education, date of birth etc..</p><p>while short term memory focuses on the knowledge which is useful for the current task, it may be different for different tasks, agents and sessions depending on the retrieval algorithm that is used.</p><p>Long term memory is stored in MEMORY.md, this is a plain markdown file, the entire file is injected into the context window at every turn, and so the model always has full access to it — though this can cause context bloat as the file gets larger.</p><p>Short term memory is more nuanced, memories for each day are stored in a folder memory/YYYY-MM-DD.md, think of them as ‘running-notes’ for the agent. The notes for the current and previous day are always provided in the context. For getting older memories, or memories from other places there are two key tools</p><ul><li>memory_get: This is used to get ‘exact’ memory, specific memory file or line range needs to be specified, and only that content is received.</li><li>memory_search: This finds relevant memories, uses complex mechanisms for retrieval and re-ranking, depending upon what memory backend is selected.</li></ul><p>On a related note, there’s also memory_flush, which happens right before compaction, saves important knowledge to memory files and basically prevents fact loss during compaction as they are written to memory as discussed above today’s memory is always there in the context, this makes compaction not as lossy as it is.</p><h3>Memory Backends</h3><p>There are three key memory backends present in openclaw, namely sqlite, QMD and honcho, let’s go over them sequentially.</p><h4>SQLite</h4><p>This is the most basic and versatile memory backend of the three. It uses a combination of embedding and keyword based retrieval to find the relevant documents, then uses a weighted search to determine relevancy to the query.</p><p>Each agent gets its own database, with the following 5 tables in each database :-</p><ul><li>Table 1 — stores metadata, in the form of key value pairs, for the configuration values like provider name, embedding technique etc</li><li>Table 2 — This is used to track file level changes, has the file path as well as a hash computed for the file, if the file hash at runtime differs from what is stored in the table, the file is considered that it was updated, and hence it is rechunked and re-embedded</li><li>Table 3 — This is the key table, it stores text chunks, and their corresponding embeddings</li><li>Table 4 — this is basically an embedding cache, content_hash embedding pairs are stored, if the same content needs to be embedded, embeddings come from this table, instead of making redundant calls to the DB</li><li>Table 5 — This is basically a virtual table, coalescing relevant data from above tables, it’s used primarily for keyword search over the text content, it’s used by FTS/BM25 type techniques.</li></ul><p>How search works</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/0*wfyfGfx462XYAy9J.png" /></figure><p>Essentially it’s a 5 step process</p><ul><li>The query is embedded.</li><li>The related text chunks are retrieved from the DB.</li><li>The query gets tokenized.</li><li>Keyword search, BM25 is applied to find relevant chunks, this makes finding exact matches easier, for eg, IDs, names etc.</li><li>The resulting chunks are then de-duped and ranked, based on various factors.</li></ul><p>The top results are then served to the LLM.</p><p>A couple of interesting factors used to weigh the results are:</p><ul><li>Temporal decay — Documents’ creation or modification date is taken into account, older documents are weighted as less relevant, the half life of a document is set as 30 days by-default.</li><li>MMR — This is used to rank the documents on the basis of uniqueness, it helps ensure that different retrieved texts reach the model.</li><li>Jaccard similarity is used here, to measure redundancy between results, instead of embedding vectors, this is primarily because jaccard is a lot cheaper, faster, local, and also good enough for detecting duplicates in this context.</li><li>It’s a relatively simple algorithm, first the highest scored item is picked, after that relevance and redundancy is calculated for each of the remaining results, the MMR score combines the two scores. The highest scoring result is picked, this is repeated for N times.</li></ul><pre>MMR = λ × relevance − (1 − λ) × similarity_to_already_selected<br><br>• High λ (e.g., 0.9) → mostly care about relevance, ignore redundancy  <br>• Low λ (e.g., 0.3) → heavily penalize redundancy, even if relevant</pre><p>Models like Gemini Embedding 2 also support multimodal embeddings, meaning openclaw can store and retrieve image and video memories.</p><h4>QMD</h4><p>QMD functions similarly to SQLite, but with a few significant changes :-</p><ul><li>Query expansion — queries are expanded to get more relevant search results, while working with embeddings, the query is re-worded and re-embedded. On the other hand, while working with keyword search, the query is tokenized, then cleaned, the keywords are then used for search and the resulting chunks are de-duped and merged</li><li>It also supports embedding any file or directory on the disk, to be used as memories, this is useful in cases where we need to give external memory/context to the agent.</li><li>It can also be used to embed and add session transcripts as memories, which I would say is not as effective, as daily memories are anyway stored in the memory/ folder.</li></ul><p>This should primarily be used in places where we want to add external information to the agent’s memory.</p><h3>Honcho</h3><p>This memory backend is more focused on keeping long term consistency in personas. It persists across conversations, and continuously improves the user and agent models.</p><ul><li><strong>User modeling</strong> — Honcho maintains a profile for each user (preferences, facts, communication style) and for the agent (personality, learned behaviors).</li><li><strong>Cross-session memory</strong> — conversations are persisted after every turn, so context carries across session resets, compaction, and channel switches.</li><li>During a conversation, Honcho queries the service in the before_prompt_build phase.</li></ul><p>This should be used in places where long term behaviours are required to stay consistent.</p><p>I think Honcho deserves a deep dive of its own, so please let me know if you’d like one.</p><h3>Dreaming</h3><p>This is the memory consolidation algorithm, used to promote memories from short term memories aka ‘the running notes’ into the long term memory. The goal is to surface the most important memories from the running notes into long term memory — reducing how often short term memory needs to be queried, while keeping the important stuff always in context, as long term memory is always injected into the context.</p><p>Key parameters considered before promoting a memory:</p><ul><li><strong>Frequency</strong>: how often the same candidate was recalled.</li><li><strong>Relevance</strong>: how strong recall scores were when it was retrieved.</li><li><strong>Query diversity</strong>: how many distinct query intents surfaced it.</li><li><strong>Recency</strong>: temporal weighting over recent recalls.</li></ul><p>The algorithm works as follows :-</p><ol><li><strong>Recall tracking</strong> — Every memory_search hit is recorded to memory/.dreams/short-term-recall.json with recall count, scores, and query hash.</li><li><strong>Promotion</strong> — Qualifying entries are appended to MEMORY.md with a promoted timestamp.</li><li><strong>Cleanup</strong> — Already-promoted entries are filtered from future cycles. A file lock prevents concurrent runs.</li></ol><p>Dreaming can be triggered manually, or openclaw provides different modes like core, rem, and deep, to control cadence and other hyperparameters.</p><p>It makes a lot of sense to gradually graduate memories from short term to long term ones, rather than depending on the user to specify what are long term memories, or depending on an LLM to classify… To think of it, this is exactly how human brain works as well, knowledge that we use frequently gets cemented and is easier to access.</p><h3>Closing thoughts</h3><p>One thing I found lacking was deduplication of memories at write time, i.e. openclaw doesn’t check for duplicates while writing to short term memory — the same note can appear across a week of entries, in my opinion, this could lead to the same memory of ‘the user is working on a substack blog’ across a week of notes, which is redundant and wasteful.</p><p>MMR does take care of it by reducing redundancy at query time, but I would prefer we could handle deduplication at write time itself. There are some extensions which provide the said functionality, but it’s not there in the core openclaw offerings.</p><p>Also, I really liked Honcho as a memory backend, the long term persona promises are really interesting, however, I have not used it yet, so I do not know if it works… Maybe I will look into its architecture next week.</p><p>Thank you for reading the blog, I would be writing about AI and adjacent topics. Also, feel free to criticise or suggest topics. Would be great if you would subscribe :).</p><p><em>Originally published at </em><a href="https://substack.com/home/post/p-193152926"><em>https://shivamguptaxia2.substack.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2704010699f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>