<?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 Kimi Pawar on Medium]]></title>
        <description><![CDATA[Stories by Kimi Pawar on Medium]]></description>
        <link>https://medium.com/@kimibulia?source=rss-3d082fc94e40------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*9WDCe5UiWwPQMW0M</url>
            <title>Stories by Kimi Pawar on Medium</title>
            <link>https://medium.com/@kimibulia?source=rss-3d082fc94e40------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 00:16:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kimibulia/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[LLM Cost Engineering in Production: Token Economics, Caching, and Routing]]></title>
            <link>https://medium.com/@kimibulia/llm-cost-engineering-in-production-token-economics-caching-and-routing-8baa21670587?source=rss-3d082fc94e40------2</link>
            <guid isPermaLink="false">https://medium.com/p/8baa21670587</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[cost-optimization]]></category>
            <category><![CDATA[genai]]></category>
            <dc:creator><![CDATA[Kimi Pawar]]></dc:creator>
            <pubDate>Mon, 16 Mar 2026 00:42:48 GMT</pubDate>
            <atom:updated>2026-03-16T00:42:48.079Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to scale GenAI without turning it into a financial liability</h3><p><strong>TL;DR</strong><br> Prototype costs are misleading. Production cost grows with context length, retries, and poor routing. This article provides a practical playbook (<strong>COST</strong>) and specific patterns: semantic caching, retrieval minimization, structured extraction with small models, and risk-based model routing.</p><h3>Why costs explode after “successful” pilots</h3><p>Common reasons:</p><ul><li>retrieval returns too many chunks (large contexts)</li><li>prompts carry repeated boilerplate</li><li>answers are too long by default</li><li>no caching for repeated questions</li><li>all requests go to the largest model</li><li>retries happen silently on failures/timeouts</li></ul><p>Cost growth isn’t linear. It’s stepwise and spiky.</p><h3>COST Playbook: Caps, Observability, Savings, Triage</h3><h3>C — Caps (budgets that force discipline)</h3><p>Implement budgets in code:</p><ul><li>max input tokens</li><li>max output tokens</li><li>max chunks</li><li>max retries</li><li>per-user/day budget</li><li>per-workflow budget</li></ul><p>Also implement “budget-aware responses”:</p><ul><li>short answer when budget exceeded</li><li>offer drill-down follow-up instead of one giant answer</li></ul><h3>O — Observability (unit economics)</h3><p>Track per endpoint:</p><ul><li>tokens in/out (p50/p95)</li><li>retrieval chunk count + size</li><li>model selected</li><li>cache hit rate</li><li>retries and their token cost</li><li>cost per <em>successful task outcome</em></li></ul><p><strong>Practical metric:</strong><br><strong>Cost per Resolved Task</strong> = total tokens cost / number of tasks completed without escalation.</p><p>This aligns cost with value.</p><h3>S — Savings levers (highest ROI changes)</h3><ol><li><strong>Context minimization</strong></li></ol><p>better reranking so you need fewer chunks</p><ul><li>“quote-first” answers (cite minimal evidence)</li><li>dedupe similar chunks</li></ul><p><strong>2. Prompt compression</strong></p><ul><li>remove repetitive policies/instructions</li><li>move stable instructions into system prompt once</li></ul><p><strong>3. Output control</strong></p><ul><li>default to concise</li><li>expand only on request</li></ul><p><strong>4. Caching</strong></p><ul><li><strong>semantic cache</strong> for repeated questions</li><li><strong>retrieval cache</strong> for repeated evidence sets</li><li>“policy summary cache” for stable docs</li></ul><p><strong>5. Use small models for extraction</strong></p><ul><li>classification, routing, entity extraction</li><li>only use big models for synthesis</li></ul><h3>T — Triage (routing by risk and complexity)</h3><p>Route requests:</p><ul><li>Low-risk + simple → smaller/cheaper model</li><li>High-risk + compliance → stronger model + stricter gating</li><li>If low-confidence output → escalate to bigger model</li></ul><p><strong>A practical routing rule set</strong></p><ul><li>If retrieval coverage &lt; threshold → ask clarification/refuse (don’t spend tokens)</li><li>If task type = extraction/classification → small model</li><li>If task type = multi-doc synthesis → larger model</li><li>If user wants “fast answer” mode → cheaper model</li><li>If regulated workflow → safe mode (bigger model + stronger checks)</li></ul><h3>Cost-safe architecture patterns</h3><h3>Pattern 1 — Two-pass answering</h3><ul><li>Pass 1: concise answer with minimal citations</li><li>Pass 2: deeper explanation only if user requests</li></ul><p>This often halves output tokens.</p><h3>Pattern 2 — Evidence-first summarization cache</h3><p>For stable policies:</p><ul><li>generate a “policy summary” once</li><li>store with version + effective date</li><li>reuse in answers, cite original doc</li></ul><h3>Pattern 3 — Chunk budgeting</h3><p>Instead of “top K,” use a token budget:</p><ul><li>retrieve until budget reached</li><li>rerank and select best within budget</li></ul><p><strong>Closing:</strong> Cost is a product constraint. Mature GenAI systems treat tokens like CPU — metered, optimized, and budgeted.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8baa21670587" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Most Dangerous RAG Failure Isn’t Hallucination — It’s Retrieval Contamination]]></title>
            <link>https://medium.com/@kimibulia/the-most-dangerous-rag-failure-isnt-hallucination-it-s-retrieval-contamination-7cc0902cdee5?source=rss-3d082fc94e40------2</link>
            <guid isPermaLink="false">https://medium.com/p/7cc0902cdee5</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[retrieval-contamination]]></category>
            <category><![CDATA[genai]]></category>
            <dc:creator><![CDATA[Kimi Pawar]]></dc:creator>
            <pubDate>Mon, 16 Mar 2026 00:21:33 GMT</pubDate>
            <atom:updated>2026-03-16T00:21:33.030Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why “having citations” isn’t enough in regulated environments — and how to prevent evidence leakage.</h3><p><strong>TL;DR</strong><br> In enterprise GenAI, the biggest risk often isn’t hallucination. It’s when the model uses <em>real evidence from the wrong scope</em> (wrong policy version, wrong region, wrong business unit, or wrong tenant). This article introduces <strong>Retrieval Contamination</strong>, a practical prevention framework (<strong>CAGE</strong>), and a measurable metric (<strong>Contamination Rate, CR</strong>) that teams can track before regulators or customers find the problem for them.</p><p>Most teams treat hallucination as the primary risk in production GenAI. In regulated enterprises, that’s incomplete.</p><p>Some of the most damaging failures don’t look like “the model made something up.” They look like high-quality answers — complete with citations and grounded references. The issue is that the system used <strong>real evidence from the wrong scope</strong>:</p><ul><li>the right policy, wrong <strong>jurisdiction</strong></li><li>the right metric name, wrong <strong>definition/version</strong></li><li>the right process, wrong <strong>business unit</strong></li><li>the right document type, wrong <strong>tenant/customer</strong></li></ul><p>This isn’t hallucination. It’s <strong>Retrieval Contamination</strong> — and it requires a different design and evaluation approach.</p><h3>What is Retrieval Contamination?</h3><p><strong>Retrieval Contamination</strong> happens when a Retrieval-Augmented Generation (RAG) system grounds its response on authentic content that is semantically related but <strong>governance-incompatible</strong> with the user’s context.</p><p>Think of it like this:</p><ul><li><strong>Hallucination:</strong> unsupported claim</li><li><strong>Contamination:</strong> supported claim, wrong scope</li></ul><p>Hallucination can be reduced by requiring citations.<br>Contamination passes that check because it <em>has</em> citations.</p><p>That’s why contamination is so tricky: the system appears more trustworthy precisely when it’s failing in the most dangerous way.</p><h3>Why this is the most dangerous failure mode</h3><p>In regulated domains, “being right” isn’t enough. You must be right <strong>using approved evidence</strong> for the correct scope.</p><p>When contamination happens, consequences are amplified because:</p><ol><li><strong>It’s harder to detect.</strong> The answer looks credible.</li><li><strong>It breaks auditability.</strong> You can’t defend “why this evidence was valid for this user.”</li><li><strong>It’s a governance breach.</strong> In the worst cases, it becomes cross-tenant leakage or policy misuse.</li></ol><p>In other words, contamination is not only a quality issue. It’s an <strong>authorization and provenance</strong> issue.</p><h3>Three contamination patterns that show up in real enterprises</h3><ol><li><strong>Version collision:</strong> policy and KPI definitions change, but older versions stay indexed and keep getting retrieved.</li><li><strong>Jurisdiction mismatch:</strong> similar policies across regions lead retrieval to pick the wrong one (US vs EU vs APAC).</li><li><strong>Domain bleed:</strong> shared terminology across business units (e.g., “net revenue,” “dispute window,” “active merchant”) causes the system to cite the wrong domain’s definition.</li></ol><p>These failures persist because vector similarity optimizes for semantic closeness — not compliance correctness.</p><h3>A practical framework: CAGE</h3><p>To reduce contamination, you need more than prompt instructions. You need an operating model. Here’s a framework that works in practice: <strong>CAGE — Containment, Attribution, Guardrails, Evaluation.</strong></p><h3>1) Containment: keep retrieval inside the correct trust boundary</h3><p>Every query should carry a <strong>context envelope</strong>: a structured set of constraints that retrieval must obey.</p><p>Example envelope fields:</p><ul><li>business unit / product line</li><li>jurisdiction / region</li><li>tenant/customer ID</li><li>data classification (public/internal/confidential)</li><li>effective date / policy version baseline</li></ul><p><strong>Hard truth:</strong> embeddings optimize for meaning similarity, not compliance boundaries.<br> If you don’t implement containment, you’re optimizing the wrong objective.</p><p><strong>Implementation that works:</strong></p><ul><li>Tag documents with mandatory metadata (scope labels).</li><li>Apply <strong>metadata filters before vector retrieval</strong> (pre-filter).</li><li>If you can’t pre-filter, post-filter aggressively, and <strong>refuse</strong> if eligible evidence is empty.</li></ul><p>“Closest match” is not acceptable in regulated systems.<br> When scope can’t be satisfied, the correct behavior is to clarify or refuse.</p><h3>2) Attribution: provenance should be auditable, not decorative</h3><p>Most citation implementations today are UI theater: a few links placed at the bottom.</p><p>Compliance-grade attribution needs:</p><ul><li>document ID, version, and effective date</li><li>scope tags (region, BU, tenant, data class)</li><li>chunk coordinates (or stable references)</li><li>retrieval query + applied filters</li><li>minimal explanation of why each source was selected</li></ul><p>If you can’t reconstruct the evidence chain later, you don’t have provenance.<br> Treat each response like a financial transaction: it must leave an <strong>audit trail</strong>.</p><h3>3) Guardrails: constrain behavior, not just content</h3><p>Content moderation guardrails won’t stop contamination. You need <strong>behavioral guardrails</strong>:</p><ul><li><strong>Retrieval Gate:</strong> blocks out-of-scope documents at retrieval time</li><li><strong>Citation Gate:</strong> validates that citations match the context envelope</li><li><strong>Response Gate:</strong> refuses if provenance is incomplete or scope cannot be satisfied</li></ul><p>The key capability is the system’s ability to say:</p><blockquote><em>“I can’t answer within your permitted scope. Here’s what I need.”</em></blockquote><p>Refusal isn’t a failure in regulated environments. It’s evidence of governance.</p><h3>4) Evaluation: measure contamination directly</h3><p>Most teams evaluate RAG with “did it answer correctly?”</p><p>That’s necessary — but not sufficient.</p><p>You need a metric that directly captures governance violations:</p><p><strong>Contamination Rate (CR)</strong><br> = % of responses where <strong>at least one cited chunk violates the context envelope</strong></p><p>CR is powerful because it’s:</p><ul><li>simple to explain to risk/compliance leadership</li><li>measurable and trendable</li><li>actionable (you can map CR to specific causes: version, region, domain, tenant)</li></ul><h4>How to measure CR without a huge labeling program</h4><p>Build an <strong>adversarial test set</strong> using “near twins”:</p><ul><li>Policy A (US) vs Policy A (EU)</li><li>KPI definition v1 vs v2</li><li>Procedure BU1 vs BU2</li><li>Tenant X vs Tenant Y (for multi-tenant systems)</li></ul><p>Then ask questions that are likely to confuse retrieval:</p><ul><li>“What is the dispute window for EU?”</li><li>“Define Net Revenue effective Q3 2024.”</li><li>“What are the termination terms for Vendor X in Texas?”</li></ul><p>For each test question:</p><ol><li>attach the envelope constraints (expected scope)</li><li>run retrieval</li><li>verify doc tags match envelope</li><li>compute CR</li></ol><p>Notice what’s happening: you don’t need to judge prose correctness first. You check whether the <em>evidence</em> is compliant. That’s often the highest-leverage move.</p><h3>One architecture pattern that reduces contamination immediately</h3><p>If you implement only one change, implement <strong>two-stage retrieval</strong>:</p><h3>Stage 1: Eligibility retrieval (strict scope filtering)</h3><ul><li>Apply envelope metadata filters.</li><li>Retrieve a small set of eligible candidates.</li></ul><h3>Stage 2: Relevance rerank (quality within eligible set)</h3><ul><li>Rerank using a cross-encoder, LLM scorer, or hybrid BM25+vector.</li></ul><p>If Stage 1 yields zero candidates:</p><ul><li>ask a clarification question, or</li><li>refuse with a reason</li></ul><p>Do not guess. Do not broaden scope silently.</p><p>This pattern gives you:</p><ul><li>scope safety first</li><li>relevance quality second</li></ul><h3>Why “this” is the enterprise RAG maturity curve</h3><p>Early RAG systems optimize for “answer quality.” Mature enterprise RAG systems optimize for:</p><ul><li><strong>scope correctness</strong></li><li><strong>auditability</strong></li><li><strong>change management (versioning)</strong></li><li><strong>repeatable evaluation (CR trends)</strong></li></ul><p>If you want to build GenAI that survives real scrutiny, contamination must be a first-class quality dimension — separate from hallucination.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7cc0902cdee5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>