<?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 Atisha Rajpurohit on Medium]]></title>
        <description><![CDATA[Stories by Atisha Rajpurohit on Medium]]></description>
        <link>https://medium.com/@atisharajpurohit?source=rss-775e2973891a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*eW7NuU5vgfw3NnEQcWGk1A.jpeg</url>
            <title>Stories by Atisha Rajpurohit on Medium</title>
            <link>https://medium.com/@atisharajpurohit?source=rss-775e2973891a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:42:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@atisharajpurohit/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[Agentic Context Engineering (ACE)]]></title>
            <link>https://pub.towardsai.net/agentic-context-engineering-ace-456337c0b0ea?source=rss-775e2973891a------2</link>
            <guid isPermaLink="false">https://medium.com/p/456337c0b0ea</guid>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[context-engineering]]></category>
            <dc:creator><![CDATA[Atisha Rajpurohit]]></dc:creator>
            <pubDate>Tue, 25 Aug 2026 21:31:01 GMT</pubDate>
            <atom:updated>2026-08-25T21:31:01.217Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>Adding Tactful Determinism to Stochastic LLMs to build reliable agentic systems</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p4RVK_KqsvNIh5cEE1Ruiw.png" /><figcaption><em>The ACE architecture — Generator, Reflector, Curator, and the Context Playbook — reimagined as a cork board. Inspired by Figure 4 of the ACE paper (Zhang et al.). Image created by the author using ChatGPT.</em></figcaption></figure><blockquote>Agentic Context Engineering (ACE) improves LLM systems by evolving their context instead of their weights. Context here is not a summary to be rewritten and compressed, but a playbook that accumulates what the system has learned. Three agents : a Generator, a Reflector, and a Curator — maintain it through small, localized, deterministic edits. This avoids the two failures current methods hit: brevity bias and context collapse, while adapting faster and cheaper. This piece covers why those failures happen, how ACE engineers around them, and what the results show.</blockquote><h3><strong>Introduction</strong></h3><p>LLMs, and the agents we build on them, have benefited much from their inherent stochastic nature — the same stochasticity we’ve used to generate immense amounts of data. But to build systems that run reliably, determinism needs to be re-added, so the system holds the right information for the task. Two issues push us there: duration, when systems struggle to keep the right context over long runs, and granularity, where domain-specific nuances get thrown away into summaries. Respectably referred to as brevity bias and context collapse. Agentic Context Engineering (ACE)’s answer isn’t one revolutionary idea — it’s a lot of simple ideas engineered right where things break, adding determinism in three ways:</p><p>I. Three agents that each do one job; generator, reflector and curator respectively<br>II. A revolving playbook that accumulates context instead of compacting it<br>III. A grow-and-refine step that keeps it in check as it grows.</p><p><strong>Adding the right amount of determinism is how you make agents work better — and that’s Agentic Context Engineering.</strong></p><h3><strong>Context adaptation, and where it starts to break</strong></h3><p>LLMs, and the agentic systems built on them, have increasingly come to rely on context adaptation : <strong>modifying the input to the LLM rather than modifying the weights of the LLM</strong>. This has numerous benefits: it’s cheaper, multiple models can work off the same context, new knowledge can be added at runtime, and context can be shared across models and modules.</p><p>Context adaptation leverages natural language feedback, where the model generates reasoning trajectories, execution traces, or validation steps. These are then evaluated, and the assessment guides how the context should be revised.</p><p>Several research efforts put this to work:</p><ul><li><strong>Reflexion</strong> — reflects on failures to improve agentic planning.</li><li><strong>TextGrad</strong> — optimizes prompts through textual feedback, a gradient-like signal expressed in words.</li><li><strong>GEPA</strong> — iteratively refines prompts based on execution traces.</li><li><strong>Dynamic Cheatsheet</strong> — builds an external memory of strategies and lessons from past successes and failures, reused at inference time.</li></ul><p>What ties these together is that each one uses natural language feedback to decide how to move ahead — Reflexion reads its own failures, TextGrad pushes a gradient-like signal back onto the prompt, GEPA iteratively optimizes the prompt, and Dynamic Cheatsheet accumulates strategies from successes and failures. Each is reflecting on what happened and folding that back into the context.</p><p>However, these methods struggle in two specific areas: longer-horizon tasks involving multi-turn reasoning, and domain-specific work that demand intensive, rich knowledge. All of the above methods fall short when you need reliable access to the right context at the right time.</p><p>These break down in two specific ways: <strong>brevity bias</strong> and <strong>context collapse</strong>.</p><h3><strong>Brevity bias: the cost of staying short</strong></h3><p>Brevity bias is the tendency of prompt optimization methods to push context toward shorter, compact, generic summaries.</p><p>The issue this causes is that these iterative methods produce nearly identical prompts, and because of this convergence, there’s no diversity left in what they generate. And by creating these summaries, the domain-specific nuances and terminology get lost — traded away for summaries. There’s another problem too: because you’re iterating from the original prompt, it’s also sometimes going it propagates the reflective errors that were in the seed itself. Whenever a task needs context-rich guidance — multi-step agents, program synthesis, or knowledge-intensive reasoning — brevity bias emerges.</p><blockquote>GEPA exhibits this: a single agent produces the reasoning trajectories, identifies what went wrong, and rewrites the prompt. Across multiple iterations, important domain-specific detail can slip away through constant summarization. Each rewrite builds on the previous summary rather than the original, so once a detail is gone, later passes can’t recover it — and that is brevity bias.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n8972XWmCiCG4tyxkOuVgA.png" /><figcaption><em>GEPA (Agrawal et al., 2025) reflects on execution traces, proposes new prompt variants, and maintains a Pareto frontier of high-performing prompts. Because the objective favours brevity, iterations converge on short, generic prompts that shed domain detail. </em>Diagram built with Claude; GEPA described in §4.2 of the ACE paper.</figcaption></figure><p><strong>The monolithic rewriting of prompts breaks down for long-horizon or domain-specific work.</strong></p><h3><strong>Context collapse: </strong>the price of the full rewrite</h3><p>Context collapse is the tendency of an LLM, over repeated rewrites, to compress its own context into much shorter, less informative summaries — and that dramatic loss of information is the collapse itself.</p><p>As the model rewrites its own prompt, new information comes in that may conflict with what’s already there. One way to picture it: the attention mechanism can’t effectively hold all of it, causing “context anxiety” resulting in the token count to suddenly drop. This can be seen in the image below where the context held a large number of tokens, and suddenly both tokens and accuracy fell off a cliff. As the adaptation steps increase, this monolithic rewriting is what triggers the loss.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a9CiW147Mv2uq7BBByEqRA.png" /><figcaption><em>Context collapse: at step 60 the context held 18,282 tokens at 66.7 accuracy; one step later it collapsed to 122 tokens and 57.1 — below the 63.7 baseline with no adaptation at all. </em>Figure 2, ACE (Zhang et al., arXiv:2510.04618).</figcaption></figure><blockquote>The obvious first conclusion is that memory needs to be externalized. But this example is actually Dynamic Cheatsheet — a method where memory is already externalized. Externalizing memory can’t be the whole answer, then, because the memory is external here and it still collapses. What becomes clear instead is that the monolithic rewriting of the prompt is the real culprit — that’s what destroys the information, especially domain-specific information, across iterations.</blockquote><p>These are the exact problems ACE sets out to fix.</p><h3><strong>ACE: context as an evolving playbook</strong></h3><p>ACE — Agentic Context Engineering — is a framework for scalable and efficient context adaptation, in both offline settings (system prompts that guide downstream tasks) and online settings (test-time memory that evolves the playbook).</p><p>Its core move is to change how context is even defined. Instead of treating it as a summary to be rewritten and compressed, ACE treats it as an evolving <em>playbook</em> — a structured, itemized collection of what’s been learned, that accumulates over time rather than being flattened.</p><p><strong>Context accumulation rather than context compaction.</strong></p><p>ACE builds on the agentic design of Dynamic Cheatsheet — a persistent external memory that accumulates strategies from past successes and failures. But where Dynamic Cheatsheet leans on essentially one model to both reflect and curate, ACE goes further and splits that work apart.</p><p>The paper’s author’s frame ACE’s contribution as <strong>three key innovations</strong>:</p><blockquote><strong><em>A dedicated Reflector, incremental delta updates, and a grow-and-refine mechanism.</em></strong></blockquote><p>The way the article is structured is a little different — as three places where ACE puts determinism back into a stochastic system: <strong>fixing <em>who</em> acts, <em>how</em> the context is written, and <em>how</em> it is kept in shape</strong>. That is the lens this article takes from here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*PbBY12UXx2AbJc2LE3wDSg.png" /><figcaption><em>The ACE framework: a Generator produces reasoning trajectories, a Reflector distills insights, a Curator turns them into delta context items merged by non-LLM logic. Localized edits, never a full rewrite. </em>Figure 4, ACE paper.</figcaption></figure><h3>The context playbook — the hero piece</h3><p>Everything ACE does, is to one object: the playbook. Each entry is a bullet, and each bullet holds two things. First, metadata — a unique identifier, and counters tracking how often it was marked helpful or harmful. Second, content — a small, reusable unit: a strategy, a domain concept, or a common failure mode.</p><p>That metadata is what makes the playbook self-correcting. When the Generator is solving a problem, it flags which bullets were helpful and which were harmful, and that feedback is what guides the Reflector in proposing updates. So the playbook doesn’t just accumulate — it accumulates a record of what has actually worked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*E4vJsana0ExsfoQITiarpA.png" /><figcaption><em>What ACE accumulates on AppWorld: strategies and hard rules, reusable code, troubleshooting entries — each an itemised bullet with its own identifier. This is what the delta updates write into. </em>Figure 3, ACE paper.</figcaption></figure><h4>Deterministic Roles : Division of labor</h4><p>The first is <strong><em>who does the work</em></strong>. Rather than a single model that produces the reasoning trajectories, evaluates its own trajectory, and then curates what matters — where it all blurs together in the episodic memory of one model — ACE gives each agent exactly one job.</p><p>Those roles are the Generator, the Reflector, and the Curator. The Generator produces the reasoning trajectories. The Reflector does nothing but reflect on those trajectories and extract insight from them. The Curator does nothing but turn that insight into updates. Separating evaluation and insight-extraction from curation is a deliberate design choice — and, as the results show, it is part of why ACE performs better.</p><h4>Deterministic Writes : Delta updates</h4><p>The second is <strong><em>how the context is written</em></strong>. Instead of rewriting the whole prompt, ACE makes localized delta updates, storing what was helpful or not for each bullet. These delta entries are merged deterministically, by simple non-LLM logic, rather than by an LLM.</p><p>This is what closes the loop on context collapse: no LLM ever rewrites the entire playbook, so there is no step where the context can be compressed away. Because the updates are itemized and localized, multiple deltas can be merged in parallel — enabling batched adaptation at scale, and multi-epoch adaptation where the same queries are revisited to strengthen the context. Dropping the expensive full rewrite also lowers cost and latency.</p><h4>Deterministic Upkeep : Grow-and-refine</h4><p>The third is <strong><em>how the playbook is kept from bloating</em></strong>. Even as the context grows, ACE doesn’t rewrite it or keep summarizing it. It uses a grow-and-refine mechanism that balances steady expansion with redundancy control: new bullets are appended with new identifiers, existing bullets are updated in place as their helpful/harmful counters increment, and a de-duplication step compares bullets by their semantic embeddings and prunes redundancy.</p><p>Depending on the accuracy and latency needs of the system, this refinement can happen actively — after each delta — or lazily, only when the context window is exceeded. Either way, the effect is the same: it removes the variance that monolithic context rewriting introduces, and keeps the playbook compact without ever compressing detail away.</p><h3>Why it works — Tactful Determinism</h3><p>This design enables <strong>three</strong> properties:</p><ol><li><strong>Localization</strong> — only the relevant bullets get updated, which is what avoids context collapse.</li><li><strong>Fine-grained retrieval</strong> — the Generator can focus on the most pertinent knowledge, so it gets the right information for domain-specific tasks.</li><li><strong>Incremental adaptation</strong> — merging, pruning, and de-duplication can all happen efficiently at inference time.</li></ol><p>The secret sauce implicitly underlying ACE’s success is <strong><em>tactful determinism</em></strong>: a modular structure of three specific roles instead of one agent doing everything; localized edits instead of constant rewriting; and context growth stored as itemized bullets that are merged and kept compact deterministically.</p><blockquote>Tactful being key, determinism isn’t sprinkled everywhere — it’s placed exactly where free-form rewriting did the damage, while the model keeps the one thing it’s genuinely good at: reasoning about what went wrong. The paper argues this mirrors how humans actually learn — experiment, reflect, consolidate.</blockquote><h3>The evidence: better, faster, cheaper</h3><p>ACE was tested on two families of tasks, chosen because they’re exactly where rich accumulated context should pay off: AppWorld, where an agent acts inside a live world of apps, and domain-specific finance — FiNER (tagging) and Formula (numerical reasoning).</p><p><strong><em>On agents : </em></strong>ACE beat the baselines by about 10.6% on average, and by up to 17.1% on AppWorld — from execution feedback alone, no labels. The moment that matters: on the open-source DeepSeek-V3.1, ReAct plus ACE hit 59.4%, matching IBM’s GPT-4.1 CUGA at 60.3%, and beating it on the harder test-challenge split. A smaller open model, nothing but a well-maintained context, drawing level with a frontier production system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZFftHUg_JEWCenX2zcURyw.png" /><figcaption><em>ReAct + ACE gains +17.0 average offline and +17.1 online, the latter without ground-truth labels. At 59.4% it comes level with IBM CUGA (60.3%) and surpasses it on test-challenge, using the smaller open-source DeepSeek-V3.1. </em>Left: Table 1. Right: Figure 5, the AppWorld leaderboard snapshot of 20 Sept 2025 (Appendix C). Assembled in Claude Design.</figcaption></figure><p><strong><em>On domains :</em></strong> On finance it gained about 8.6%, with Formula jumping from 67.5 to 85.5 — the playbook holding onto real procedures a short prompt can’t. It&#39;s not finance-specific either: big gains on medical reasoning (DDXPlus) and text-to-SQL (BIRD-SQL) show the approach transfers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ri-USS2wrRjw1qOEIgxcQ.png" /><figcaption><em>ACE gains +12.8 over the base LLM offline with labels. The caveat is the paper’s own: without reliable feedback, both ACE and Dynamic Cheatsheet can degrade — adaptation depends critically on feedback quality. </em>Table 2, ACE paper. Rebuilt in Claude Design.</figcaption></figure><p><strong><em>Why the gains are real :</em> </strong>The ablation is where “it works” becomes “here’s why.” Remove incremental delta updates — go back to wholesale rewriting — and performance drops by roughly 12 points on TGC and 28 on SGC. That one choice, localized edits over monolithic rewrites, is most of the gain. Also, ACE isn’t sensitive to hyper-parameters — across reasonable ranges, performance barely moves. The simple ideas are doing the work, without fussy tuning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9bkvkh5gsnn5HgisZ-Q6Qg.png" /><figcaption><em>Ablation on AppWorld: no component is decorative. Removing the Reflector and multi-epoch refinement drops the average from 59.4 to 55.1 — over a quarter of ACE’s gain over bare ReAct. </em>Table 3, ACE paper. Rebuilt in Claude Design.</figcaption></figure><p><strong><em>Cost and speed.</em> </strong>This is what actually matters in practice. ACE wins on both while being more accurate: about 82% lower latency than GEPA offline; 91% lower latency and 84% lower token cost than Dynamic Cheatsheet online — roughly 87% lower adaptation latency on average. If you think the cost of an ever increasing playbook will become untenable fear not: KV-cache reuse means most of it is served from cache, so length doesn&#39;t scale linearly into cost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6cnFkbE5WtTowqCDnrA2pA.png" /><figcaption><em>Adaptation cost against the strongest baseline in each setting: −82.3% latency and −75.1% rollouts offline against GEPA; −91.5% latency and −83.6% token cost online against Dynamic Cheatsheet. </em>Table 4, ACE paper. Rebuilt in Claude Design.</figcaption></figure><blockquote><em>Put together, the takeaway is architectural. ACE wins offline and online, with and without labels, on the hard split, across model families — cheaper and faster too. Not from a bigger model, but from the design: split the roles, edit locally</em>, leveraging a dash of tactful determinism.</blockquote><h4><strong>Limitations of ACE</strong></h4><p>ACE isn’t always the answer. When a task turns on a single fixed rule (Game-of-24) or is better served by one concise, high-level instruction (HotPotQA), a growing playbook is just overhead — you’re paying for detail the task doesn’t need. It earns its keep only where success depends on accumulated domain knowledge, complex tool use, or environment-specific strategy — which, not coincidentally, is exactly where the other methods fell short.</p><h3>References</h3><p><strong>The paper this article is about</strong></p><ul><li><strong>ACE — Agentic Context Engineering: Evolving Contexts for Self-Improving Language Models.</strong> Qizheng Zhang, Changran Hu, et al. ICLR 2026. <a href="https://arxiv.org/abs/2510.04618">arxiv.org/abs/2510.04618</a> · Code: <a href="https://github.com/ace-agent/ace">github.com/ace-agent/ace</a></li></ul><p><strong>The lineage — context adaptation methods discussed</strong></p><ul><li><strong>Reflexion: Language Agents with Verbal Reinforcement Learning.</strong> Noah Shinn, et al. NeurIPS 2023. <a href="https://arxiv.org/abs/2303.11366">arxiv.org/abs/2303.11366</a></li><li><strong>TextGrad: Automatic “Differentiation” via Text.</strong> Mert Yuksekgonul, et al. 2024. <a href="https://arxiv.org/abs/2406.07496">arxiv.org/abs/2406.07496</a></li><li><strong>GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning.</strong> Lakshya A. Agrawal, et al. ICLR 2026. <a href="https://arxiv.org/abs/2507.19457">arxiv.org/abs/2507.19457</a></li><li><strong>Dynamic Cheatsheet: Test-Time Learning with Adaptive Memory.</strong> Mirac Suzgun, et al. EACL 2026. <a href="https://arxiv.org/abs/2504.07952">arxiv.org/abs/2504.07952</a></li></ul><p><strong>The benchmarks</strong></p><ul><li><strong>AppWorld: A Controllable World of Apps and People for Benchmarking Interactive Coding Agents.</strong> Harsh Trivedi, et al. ACL 2024. <a href="https://arxiv.org/abs/2407.18901">arxiv.org/abs/2407.18901</a> · <a href="https://appworld.dev/">appworld.dev</a></li><li><strong>FiNER-139: Financial Numeric Entity Recognition for XBRL Tagging.</strong> Lefteris Loukas, et al. ACL 2022. <a href="https://arxiv.org/abs/2203.06482">arxiv.org/abs/2203.06482</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=456337c0b0ea" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/agentic-context-engineering-ace-456337c0b0ea">Agentic Context Engineering (ACE)</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking Knowledge: How Reading Research Papers Can Boost Your Intellectual Growth]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@atisharajpurohit/unlocking-knowledge-how-reading-research-papers-can-boost-your-intellectual-growth-60f0425fac47?source=rss-775e2973891a------2"><img src="https://cdn-images-1.medium.com/max/2600/1*5GsztH7wzDoWJ2o6LBCNBA.jpeg" width="3748"></a></p><p class="medium-feed-snippet">I urge all of you to start reading research papers, but ONE thing I can tell you for certain, it is very challenging and you do get lost&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@atisharajpurohit/unlocking-knowledge-how-reading-research-papers-can-boost-your-intellectual-growth-60f0425fac47?source=rss-775e2973891a------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@atisharajpurohit/unlocking-knowledge-how-reading-research-papers-can-boost-your-intellectual-growth-60f0425fac47?source=rss-775e2973891a------2</link>
            <guid isPermaLink="false">https://medium.com/p/60f0425fac47</guid>
            <category><![CDATA[study-habits]]></category>
            <category><![CDATA[technical-reading]]></category>
            <category><![CDATA[research-paper]]></category>
            <dc:creator><![CDATA[Atisha Rajpurohit]]></dc:creator>
            <pubDate>Fri, 17 Jan 2025 19:35:06 GMT</pubDate>
            <atom:updated>2025-01-17T19:35:06.739Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[DRAGIN: Dynamic Retrieval Augmented Generation based on the Information Needs of Large Language…]]></title>
            <link>https://medium.com/data-science/dragin-dynamic-retrieval-augmented-generation-based-on-the-information-needs-of-large-language-dbdb9aabc1ef?source=rss-775e2973891a------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbdb9aabc1ef</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Atisha Rajpurohit]]></dc:creator>
            <pubDate>Thu, 05 Dec 2024 18:56:06 GMT</pubDate>
            <atom:updated>2024-12-05T18:56:06.302Z</atom:updated>
            <content:encoded><![CDATA[<h3>DRAGIN: Dynamic Retrieval Augmented Generation based on the Information Needs of Large Language Models</h3><h4><em>Traditional RAG vs. dynamic RAG</em></h4><p><em>In this article, I explore the fundamental concepts explained in the research paper titled “</em><strong><em>DRAGIN : Dynamic Retrieval Augmented Generation based on the Information Needs of Large Language Models” by </em></strong><em>Weihang Su, Yichen Tang, Qingyao Ai, Zhijing Wu, and Yiqun Liu. This paper can be accessed </em><a href="https://arxiv.org/abs/2403.10081"><em>here</em></a><em>.</em></p><p><strong>Introduction — Lets look at a short story!</strong></p><blockquote><em>Imagine you’re working on a problem. At the very beginning, you get </em><strong><em>only one chance</em></strong><em> to ask your professor for guidance. This means it’s important to understand the entire scope of the problem upfront. If it’s a simple problem, that might be fine — you ask your question, get clarity, and move forward.</em></blockquote><blockquote><em>Now, imagine that the problem is </em><strong><em>much more complex</em></strong><em>. The more you dive into it, the </em><strong><em>more questions</em></strong><em> you have! Unfortunately, you can’t go back to your professor because all your questions had to be asked at the start. This makes solving the problem much harder.</em></blockquote><blockquote><em>But what if, instead, </em><strong><em>you were allowed</em></strong><em> to go back to your professor every time you discovered a new question that expanded the scope of the problem? This approach lets you navigate the complexity iteratively, asking for guidance whenever the problem evolves. </em><strong><em>That is the essence of DRAGIN (Dynamic RAG) over Traditional RAG.</em></strong></blockquote><blockquote><em>And given how complex and multi-dimensional our tasks, problems, and worlds have become, </em><strong><em>the need for this dynamic approach is greater than ever!</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J-OSRrmHJNcyWAbp1QOARg.jpeg" /><figcaption>Image taken from <a href="https://unsplash.com/">Unsplash</a></figcaption></figure><p>Large Language models have changed the way we all access information. We are at that point where the way we search has forever changed. Now, instead of finding multiple links and processing the information to answer our questions, we can directly ask the LLM!</p><p>However, there are still a number of issues :</p><ol><li>Hallucinations : Generating fabricated information</li><li>Datedness/Staleness : Inability to incorporate up to date information</li><li>Proprietary Information : Inaccessibility to specialised knowledge</li></ol><p>To overcome the above issues, <strong>Retrieval Augmented Generation (RAG)</strong> emerged as a promising solution. The way it works, is by accessing and incorporating the relevant external information needed for the LLM to generate accurate responses.</p><p>However with traditional RAG methods, they rely on single-round retrieval, which would mean retrieving external information once, at the start of the information generation. This works well for straightforward tasks, however our needs and requirements from LLMs are getting more complex, multi-step and requiring longer responses.</p><p>In these cases, a single-round of retrieval will not work well and mutiple rounds of retrieval need to be conducted. Now when, we talk about retrieving information more than once, the two next questions are :</p><p><strong><em>When </em></strong><em>to retrieve and</em><strong><em> What </em></strong><em>to retrieve? </em>To solve these, a number of RAG methods have been devised :</p><h4><strong>Fixed Retrieval Methods :</strong></h4><p><strong>IRCoT (Fixed Sentence RAG)</strong> <strong>[1]</strong> : Retrieval is conducted for each generated query and the latest sentence is used as a query.</p><p><strong>RETRO [2] and IC-RALM [3]</strong> <strong>(Fixed Length RAG)</strong> : A sliding window is defined and the retrieval module is triggered every <em>n</em> tokens.</p><blockquote><em>But aren’t we retrieving </em><strong><em>too often</em></strong><em> and hence retrieving information that may be unnecessary ? This would introduce noise and could jeopardize the quality of the LLM’s outputs, which defeats the original purpose of improving accuracy. These rules are still </em><strong><em>static</em></strong><em> and we need to think of </em><strong><em>dynamic</em></strong><em> ways of retrieval.</em></blockquote><h4><strong>Dynamic Retrieval Methods :</strong></h4><p><strong>FLARE [4]</strong> <strong>(Low Confidence RAG)</strong> : Retrieval is conducted dynamically, when the LLM’s confidence (the generation probability) on the next token is lower than certain thresholds. So FLARE, is triggering retrieval based on <strong>uncertainty</strong>.</p><p>For determining what to retrieve, the LLMs often restrict themselves to queries based on the last few generated tokens or sentences. These methods of query formulation for retrieval may not work, when the tasks get more complex and the LLM’s information needs span over the entire context!</p><p><em>Finally, moving on to the star of the show : DRAGIN!</em></p><h4><strong>DRAGIN (Dynamic Retrieval Augmented Generation based on Information Needs) :</strong></h4><p>This method is specifically designed to make decisions about when and what to retrieve to cater to the LLM’s information needs. So, it optimizes the process of information retrieval using two frameworks. As the authors explain in their paper, DRAGIN has two key frameworks :</p><p><strong><em>I. RIND (Real-time Information Needs Detection) : When to retrieve ?</em></strong></p><p>It considers the LLM’s <strong>uncertainty</strong> about its own content, the <strong>influence</strong> of each token and the <strong>semantics </strong>of each token.</p><p><strong><em>II. QFS (Query Formulation based on Self-Attention) : What to retrieve?</em></strong></p><p>Query formulation leverages the LLM’s <strong>self-attention</strong> across the entire context, rather than not just the last few tokens or sentences.</p><h4><strong>Illustration of the DRAGIN framework</strong></h4><p>To illustrate the above frameworks, the paper uses an example query about the ‘<strong>brief introduction to Einstein’.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*onsF_KA1U1UVM7RzSas1Dw.png" /><figcaption>Figure 1 : An illustration of the DRAGIN framework, taken from the <a href="https://arxiv.org/abs/2403.10081">research paper</a></figcaption></figure><p><strong><em>Explanation :</em></strong></p><p><strong><em>Input is Provided:</em></strong><em> The system is queried to provide some introduction about Einstein.</em></p><p><strong><em>Processing Starts:</em></strong><em> The system begins generating a response based on what it knows. It uses the RIND module to decide if it has enough information or if it needs to look things up.</em></p><p><strong><em>Checking for Required Information (RIND): </em></strong><em>The system breaks down the query into smaller parts (tokens), like “position,” “at,” “University,” etc. It checks which parts (tokens) need more information. For example, “university” might need additional data because it’s not specific enough.</em></p><p><strong><em>Triggering Retrieval: </em></strong><em>If a token like “university” is considered to be important and unclear, the system triggers retrieval to gather external information about it. In this case, it looks up relevant data about Einstein and universities.</em></p><p><strong><em>Formulating the Query (QFS): </em></strong><em>The system uses its self attention mechanism to determine which words are most relevant for forming a precise query. For example, it might pick “Einstein,” “1903,” and “secured a job” as the key parts.</em></p><p><em>These keywords are used to craft a query, such as “Einstein 1903 secured a job,” which is sent to an external source for information.</em></p><p><strong><em>Retrieving and Adding Information: </em></strong><em>The external source provides the required details. For example, it might return, “In 1903, Einstein secured a job at the Swiss Patent Office.” The system incorporates this new information into the response.</em></p><p><strong><em>Continuing Generation: </em></strong><em>With the new details, the system continues generating a more complete and accurate response.For example, it might now say, “In 1903, Einstein secured a job at the Swiss Patent Office. This allowed him to have a stable income.”</em></p><p><strong><em>Repeating the Process: </em></strong><em>If more requirements are identified, the process repeats: </em><strong><em>checking, retrieving, and integrating information</em></strong><em> until the response is complete and accurate. This process ensures that the system can dynamically fill in gaps in its knowledge and provide detailed, accurate answers by combining what it knows with retrieved external information.</em></p><h4>Detailed Methodology about RAG</h4><p>The frameworks mentioned in the paper are:</p><p><strong>A. Real-time Information Needs Detection</strong> <strong>(RIND)</strong> : Retrieval is triggered based on uncertainty of tokens, influence on other tokens and semantic significance of each token.</p><p>i. The <strong>uncertainty</strong> of each token generated by the LLM, is quantified. This is done by calculating the <strong>entropy</strong> of the token’s probability distribution across the vocabulary. Consider an output sequence <em>T = {t1,t2,…tn}, </em>with each ti representing an individual token at the position <em>i</em>. For any token <em>ti</em>, the entropy is calculated as follows :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*1LzO1503NUgn7P0uH6eATw.png" /></figure><p>where <em>pi(v)</em> denotes the probability of generating the token <em>v</em> over all the tokens in the vocabulary.</p><p>ii. The <strong>influence</strong> of each token on subsequent tokens, is done by leveraging the self-attention scores. For a token t, the max attention value is identified</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*IwWJkteEloloWhTxw3EjBg.png" /></figure><p>iii. The <strong>semantic contribution</strong> of each token ti, a binary indicator is employed. This filters out stop words.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*JyO3Yt5IlmdAaPWcbi9FwA.png" /></figure><p>Combining the <strong>uncertainty, significance and semantics,</strong> RIND computes a score and if this is greater than a pre-defined threshold then retrieval is triggered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*y8LxPPh8noqRyCJb1qu8lg.png" /></figure><p><strong>B</strong>. <strong>Query Formulation based on Self-Attention (QFS)</strong></p><p>Once retrieval is triggered, the next step is to formulate an efficient query from external databases for the continued generation of LLMs. In the existing dynamic RAG frameworks, queries are formulated using the last sentence or last tokens generated by the LLM. This narrow scope doesn’t capture the need for real-time information needs. It examines the full context.</p><p>Suppose RIND identifies the token <em>ti </em>at position <em>i, </em>requires external knowledge and triggers retrieval.</p><blockquote>Since the token ti was generated based on based on the knowledge of all the preceding tokens, it only makes sense to look at the entire content generated, until now, to formulate a query. It uses the following steps:</blockquote><p><strong>Step 1</strong>: Extracts the attention scores of the last transformer layer for each token <em>ti</em>.</p><p><strong>Step 2</strong>: Sorts the attention scores in descending order, to identify the top <strong><em>n</em></strong> scores. <em>(This is basically, identifying the most important tokens).</em></p><p><strong>Step 3</strong>: Finds the words corresponding to these tokens from the vocabulary and arranges them in their original order. <em>(This brings back the structure of the language form the attention scores and tokens).</em></p><p><strong>Step 4</strong> : Construct the query <em>Qi</em> using the words associated with these top <strong><em>n</em></strong> tokens.</p><p><strong>C. Continue Generation after Retrieval</strong></p><p>Once RIND has identified the position <em>i</em>, at which external knowledge is needed and QFS creates the query, Qi to extract the information using an off-the-shelf retrieval model (e.g. BM25).</p><p>It finds the relevant information in documents <em>Di1</em>, <em>Di2</em> and <em>Di3</em>. It integrates the relevant information at position <em>i, </em>by truncating the LLM’s output. This retrieved knowledge is integrated using the following designed prompt template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*MNQgDQcrJgGkvYWfQXM-fw.png" /><figcaption>Designed prompt template used to integrate externally retrieved information.</figcaption></figure><h4><strong>Limitations</strong></h4><p>As the paper states, the primary limitations of this paper is the reliance on the self-attention mechanisms for both the Real-time Information Needs Detection (RIND) and Query Formulation based on Self-Attention (QFS). While self-attention scores are available for all source LLMs, it is not applicable for certain APIs that do not provide access to self-attention scores.</p><p><em>A point worth considering is the impact on inference time latency and cost: in the paper, the authors point out that these are only marginally more since an imperfect token sub-sequence is rapidly detected, and further generation is interrupted until remediation.</em></p><h4>Conclusion</h4><p>The DRAGIN framework allows us to look to move a few steps ahead of the traditional RAG framework. It allows us to perform multiple retrievals, based on the information needs of generation. It is an optimized framework for multiple retrievals!</p><p>Our needs and requirements from LLMs are becoming larger and more complex, and in such cases where we want to retrieve information accurately, with just the right number of retrievals.</p><blockquote>To conclude, DRAGIN :</blockquote><blockquote>Strikes the perfect balance for the number of retrievals.<br>Produces highly context-aware queries for retrievals.<br>Generates content from the LLMs with better accuracy!</blockquote><p><em>Thank you so much for reading and for a more detailed explanation of the research paper, please watch my video!</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FK5dacRVjTF8%3Fstart%3D1474%26feature%3Doembed%26start%3D1474&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DK5dacRVjTF8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FK5dacRVjTF8%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd116e405774e71ae429db0dcf033937/href">https://medium.com/media/dd116e405774e71ae429db0dcf033937/href</a></iframe><p><strong>References :</strong></p><p><em>[1] Harsh Trivedi, Niranjan Balasubramanian, Tushar Khot, and Ashish Sabharwal. 2022. Interleaving retrieval with chain-of-thought reasoning for knowledge-intensive multi-step questions. arXiv preprint arXiv:2212.10509.</em></p><p><em>[2] Sebastian Borgeaud, Arthur Mensch, Jordan Hoffmann, Trevor Cai, Eliza Rutherford, Katie Millican, George Bm Van Den Driessche, Jean-Baptiste Lespiau, Bogdan Damoc, Aidan Clark, et al. 2022.</em></p><p><em>[3] Ori Ram, Yoav Levine, Itay Dalmedigos, Dor Muhlgay, Amnon Shashua, Kevin Leyton-Brown, and Yoav Shoham. 2023. In-context retrieval-augmented language models. arXiv preprint arXiv:2302.00083.</em></p><p><em>[4] Zhengbao Jiang, Frank F Xu, Luyu Gao, Zhiqing Sun, Qian Liu, Jane Dwivedi-Yu, Yiming Yang, Jamie Callan, and Graham Neubig. 2023. Active retrieval augmented generation. arXiv preprint arXiv:2305.06983.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbdb9aabc1ef" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/dragin-dynamic-retrieval-augmented-generation-based-on-the-information-needs-of-large-language-dbdb9aabc1ef">DRAGIN: Dynamic Retrieval Augmented Generation based on the Information Needs of Large Language…</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Assumptions to Accuracy: The Role of Conditional Probability in Real-World Predictions]]></title>
            <link>https://medium.com/data-science/from-assumptions-to-accuracy-the-role-of-conditional-probability-in-real-world-predictions-ebf9c9fe4bb9?source=rss-775e2973891a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebf9c9fe4bb9</guid>
            <category><![CDATA[probability]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[predictions]]></category>
            <category><![CDATA[conditional-probability]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Atisha Rajpurohit]]></dc:creator>
            <pubDate>Sat, 25 May 2024 05:22:49 GMT</pubDate>
            <atom:updated>2024-05-25T05:22:49.475Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong><em>Conditional probability is better than probability ; IF you have the relevant information</em></strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j7fMmSztbRSJA_Pf" /><figcaption>Image taken from <a href="https://unsplash.com/s/photos/dice">Unsplash</a></figcaption></figure><p><strong>Introduction</strong></p><p>Anyone who has ever studied probability has heard of the long-established definition of probability of “<em>Probability can be defined as the number of favorable outcomes divided by the total number outcomes</em>.” I can still hear my 4th grade teacher reiterating this!</p><p>While this definition is <strong>correct</strong>, it often makes me wonder, how <strong>accurate</strong> is this definition for the real-world? How accurate is it when we have some <strong>more information</strong> about the favorable outcomes? To put it more clearly, when we have some more “<strong>conditions</strong>” to put to our favorable outcomes.</p><p>Putting “<strong>conditions</strong>” is like slicing your original pie of number of favorable outcomes in a number of ways, using multiple conditions, to give you the slice that represents the number of favorable outcomes for you more truly. The image below attempts to depict this concept in a very brief manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*07oqDinT7Y5m4t8C" /><figcaption>Image created by Author</figcaption></figure><p><em>What better way than to represent what is in the mind’s of a lot of international data science students studying in the US and looking for jobs! The original number of available jobs is depicted on the extreme left.</em></p><p><strong><em>1st Condition :</em></strong><em> Introducing the </em><strong><em>1st</em></strong><em> </em><strong><em>condition</em></strong><em> for “</em><strong><em>Work Experience Duration</em></strong><em>” refines the slice for the number of available jobs for a new joiner.</em></p><p><strong><em>2nd Condition : </em></strong><em>Furthermore, introducing the </em><strong><em>2nd condition</em></strong><em> for “</em><strong><em>Nationality/Citizenship</em></strong><em>” refines the slice even more.</em></p><p><strong><em>3rd Condition</em></strong><em> : The small dark blue slice in the extreme right chart represents the most accurate representation for the number of available jobs (number of favorable outcomes).</em></p><p>Before proceeding into why conditional probability may be better than probability, let’s do a quick recap of the definitions.</p><p><strong>2. Definition of probability and conditional probability</strong></p><p><strong>Probability :</strong></p><p>P(A) = Number of favorable outcomes for A / Total number of outcomes</p><p><strong>Conditional probability :</strong></p><p>Now consider two events A and B. The foundation of conditional probability is when there is an “event given another event”. In this case, when one says <strong>A given B</strong>, what that means is the event A occurring <strong>given</strong> event B has occurred. So that is attaching the “<strong>condition of B, to A</strong>”.</p><p>P(A|B) = P(A intersection B) / P(B) where</p><p>P(A intersection B)* is given as the probability of both event A and event B occurring.</p><p>*<em>given (A intersection B) and (A’ intersection B) are mutually exclusive. Hence (A intersection B) union (A’ intersection B) = B.</em></p><p>After defining these slightly confusing definitions, I will move to why I think conditional probability is actually better.</p><p><strong>3. Example — Inspiration for this article</strong></p><p>To start off, the reason I got an idea for this article was when I was watching a Bollywood movie the other day and when there was a scene about two old friends discussing the probability of them bumping into each other!</p><p>Let me introduce some more information about this scene:</p><ul><li><strong>1st friend</strong> : <strong>Police officer</strong>, originally from Mumbai city, who was traveling to Kalimpong; a small town, for a case.</li><li><strong>2nd friend</strong> : <strong>Math professor</strong>, who was a resident of the town — Kalimpong.</li></ul><p>These friends know each other since they both studied in the <strong>same university</strong>.</p><ul><li>Currently, the friends met each other at a cafe where the professor would go everyday.</li></ul><p>After introducing this information, let’s go back to what was the probability of both of them bumping into each other in Kalimpong.</p><p><em>Police Officer : “Bro, what are the chances!”</em></p><p><em>Math Professor : “One out of 95675”</em></p><p><em>Police Officer : “Wrong! You did not count me”</em></p><p><em>Math Professor “I did. The current population is 95674”</em></p><p>Hmm… so let’s break this logic :</p><p><strong>Initial Probability Calculation:</strong></p><ul><li>The math professor calculated the probability of meeting his friend, the police officer as 1/95,675.</li><li>This assumes that all the 95,674 residents of Kalimpong have the same probability of meeting the professor as the police officer.</li></ul><p><strong>Why is this calculation inaccurate:</strong></p><ul><li>This calculation assumes that meeting the police officer is the same as meeting ANY OTHER resident of Kalimpong!</li></ul><p><strong>Introducing conditional probability:</strong></p><p>Let’s consider some specific scenarios</p><p><strong>I. Relevant Information:</strong></p><ul><li>The police officer is a resident of Mumbai who traveled to Kalimpong.</li><li>The math professor goes to this cafe every day.</li><li>The police officer happened to go to the same cafe this one time.</li></ul><p><strong>II. Conditional Events:</strong></p><p><strong>Event A</strong>: The professor and police officer meet in Kalimpong.</p><p><strong>Event B</strong>: The police officer travels from Mumbai to Kalimpong .</p><p>Probability of the two friends meeting :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*n4gVbs0mI2A-hOK4" /></figure><p>1. The probability of police officer traveling from Mumbai to Kalimpong, depends on factors such as:</p><ul><li>How often does he travel for work?</li><li>How often does he get assigned to cases from small towns?</li><li>Let’s assume this probability is 0.1%.</li></ul><p>2. The probability of the two friends meeting, depends on factors such as:</p><ul><li>How often do they both go to the cafe?</li><li>How popular is the cafe?</li><li>The professor regularly goes to the cafe.</li><li>Let’s assume this probability is 1%.</li></ul><p><strong>Final calculations :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vZKlU7IKWLrM6hFi" /></figure><ul><li>The probability of the two friends meeting in Kalimpong, given that the police officer is there, is 0.001%.</li><li>This is a simplistic representation of the concept, but what I am trying to say is to always look for more relevant information to refine your probability.</li></ul><p><strong>Conclusion</strong></p><p>Probability is simple and complicated at the same time! However there is always refining we can do with any additional information that we are provided. In real world situations, always try to look for how additional information can help you add conditions to make your probabilities more accurate.</p><p>Thank you for reading and I hope this article was useful to you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebf9c9fe4bb9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/from-assumptions-to-accuracy-the-role-of-conditional-probability-in-real-world-predictions-ebf9c9fe4bb9">From Assumptions to Accuracy: The Role of Conditional Probability in Real-World Predictions</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>