<?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 Amr Koura on Medium]]></title>
        <description><![CDATA[Stories by Amr Koura on Medium]]></description>
        <link>https://medium.com/@amrqura?source=rss-f8d321bd6883------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*u292ye97xjImCaE-</url>
            <title>Stories by Amr Koura on Medium</title>
            <link>https://medium.com/@amrqura?source=rss-f8d321bd6883------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 18:07:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amrqura/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[Building a Production-Grade RAG System for Claims Processing — Part 2: Multi-Agent Architecture for…]]></title>
            <link>https://medium.com/@amrqura/building-a-production-grade-rag-system-for-claims-processing-part-2-multi-agent-architecture-for-d60155aad315?source=rss-f8d321bd6883------2</link>
            <guid isPermaLink="false">https://medium.com/p/d60155aad315</guid>
            <category><![CDATA[agentic-workflow]]></category>
            <category><![CDATA[reliable-ai]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[multi-agent]]></category>
            <category><![CDATA[rags]]></category>
            <dc:creator><![CDATA[Amr Koura]]></dc:creator>
            <pubDate>Sun, 26 Apr 2026 09:46:13 GMT</pubDate>
            <atom:updated>2026-04-26T09:46:13.232Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Production-Grade RAG System for Claims Processing — Part 2: Multi-Agent Architecture for Reliable AI</h3><h3>From Retrieval to Decision: Designing a Multi-Agent Architecture for Reliable AI</h3><h3>Introduction</h3><p>In <a href="https://medium.com/@amrqura/building-a-production-grade-rag-system-for-claims-processing-part-1-6e9fff0cab40">Part 1</a>, we focused on retrieval.</p><p>We saw why vector search alone is not enough, and how to build a <strong>hierarchical hybrid retrieval pipeline</strong> that:</p><ul><li>combines semantic search and keyword search</li><li>resolves policy precedence using a knowledge graph</li><li>builds a clean, authoritative evidence set</li></ul><p>👉 But even with perfect retrieval, the system can still fail.</p><p>Because claims processing is not just about finding information.</p><blockquote><em>It is about making </em><strong><em>correct, safe, and explainable decisions</em></strong></blockquote><h3>Why Retrieval Alone Is Not Enough</h3><p>Even if the system retrieves the right evidence, a single LLM step can still:</p><ul><li>misinterpret policy language</li><li>ignore missing context</li><li>overstate conclusions</li><li>mix conflicting rules</li><li>answer when it should ask or refuse</li></ul><p>And in claims processing:</p><blockquote><em>A “mostly correct” answer is still a failure.</em></blockquote><h3>The Shift: From RAG to Decision Systems</h3><p>Most RAG systems follow this pattern:</p><blockquote><em>Retrieve → Generate</em></blockquote><p>In production, that’s not enough.</p><p>We need:</p><blockquote><em>Route → Retrieve → Curate → Compose → Verify → Decide</em></blockquote><p>This is where <strong>multi-agent architecture</strong> becomes essential.</p><h3>🧩 System Requirements</h3><p>From the problem definition in Part 1, the system must:</p><ul><li>✅ Provide <strong>clear and actionable answers</strong></li><li>✅ Include <strong>citations (document, section, context)</strong></li><li>✅ Return <strong>confidence with explanation</strong></li><li>❓ Ask <strong>follow-up questions</strong> when information is missing</li><li>❌ Refuse when evidence is insufficient</li><li>⚖️ Handle <strong>policy conflicts and precedence</strong></li><li>🔍 Maintain <strong>auditability and traceability</strong></li></ul><p>These requirements directly shape the architecture.</p><h3>🏗️ Architecture Overview</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CBDiIgiW5E9cc_lwJPvfBg.jpeg" /><figcaption>Claim processing mutli agents architecture</figcaption></figure><p>At a high level, the system consists of:</p><ul><li><strong>Routing layer</strong> → understands the query</li><li><strong>Retrieval layer</strong> → (from <a href="https://medium.com/@amrqura/building-a-production-grade-rag-system-for-claims-processing-part-1-6e9fff0cab40">Part 1</a>)</li><li><strong>Reasoning agents</strong> → process and validate the answer</li><li><strong>Safety layer</strong> → prevents unsafe outputs</li><li><strong>Caching layer</strong> → improves latency</li></ul><h3>Why Multi-Agent Architecture?</h3><p>Instead of relying on one large prompt, we split the system into specialized agents.</p><p>Each agent has <strong>one responsibility</strong>.</p><p>This improves:</p><ul><li>reliability</li><li>control</li><li>debuggability</li><li>safety</li></ul><p>And most importantly:</p><blockquote><em>It allows us to enforce correctness at every step</em></blockquote><h3>The Shared State</h3><p>All agents operate on a shared state object.</p><pre>class State:<br>    def __init__(self):<br>        self.query = None<br>        self.intent = None<br>        self.evidence = []<br>        self.draft = None<br>        self.missing_facts = []<br>        self.risk = None<br>        self.confidence = None</pre><p>This makes the system:</p><ul><li>structured</li><li>traceable</li><li>easy to debug</li></ul><h3>🔍 The Core Agents</h3><h3>1. Router Agent</h3><h4>What it does</h4><p>The Router:</p><ul><li>understands the query</li><li>extracts intent</li><li>detects missing information</li></ul><h4>Prompt</h4><pre>You are a claims processing router.<br>Extract:<br>- intent<br>- claim type<br>- region<br>- missing information</pre><pre>Do not answer the question.<br>Return structured output only.</pre><h4>Code</h4><pre>def router_agent(state, llm):<br>    result = llm.structured_generate(state.query)<br>    state.intent = result[&quot;intent&quot;]<br>    state.missing_facts = result.get(&quot;missing_facts&quot;, [])<br>    return state</pre><h4>Why it matters</h4><p>This is the first safety layer.</p><p>If key information is missing, the system should not proceed blindly.</p><h3>2. Retriever Agent</h3><h4>What it does</h4><p>This agent connects directly to <a href="https://medium.com/@amrqura/building-a-production-grade-rag-system-for-claims-processing-part-1-6e9fff0cab40">Part 1</a>.</p><p>It:</p><ul><li>runs hierarchical hybrid retrieval</li><li>queries vector DB, SQL, documents, and graph</li><li>returns candidate evidence</li></ul><h4>Prompt</h4><pre>Retrieve evidence for this claim query.<br>Use:<br>- semantic similarity<br>- keyword matching<br>- structured rules<br>- policy precedence</pre><pre>Return only evidence, not answers.</pre><h4>Code</h4><pre>def retriever_agent(state, retrieval_service):<br>    state.evidence = retrieval_service.retrieve(<br>        query=state.query,<br>        intent=state.intent<br>    )<br>    return state</pre><h4>Why it matters</h4><blockquote><em>Retrieval finds candidates. It does not decide correctness.</em></blockquote><h3>3. Evidence Curator</h3><h4>What it does</h4><p>Filters and ranks evidence:</p><ul><li>removes duplicates</li><li>resolves conflicts</li><li>prioritizes authoritative sources</li></ul><h4>Prompt</h4><pre>Select the best evidence for answering the query.<br>Rules:<br>- prefer newer policies<br>- prefer region-specific rules<br>- respect overrides<br>- remove duplicates</pre><pre>Do not answer the question.</pre><h4>Code</h4><pre>def curate_evidence(state, reranker):<br>    ranked = reranker.rank(state.query, state.evidence)<br>    state.evidence = ranked[:5]<br>    return state</pre><h4>Why it matters</h4><p>Bad context → bad answers</p><p>This agent ensures the model sees only <strong>high-quality evidence</strong></p><blockquote><em>Retrieval is not only about finding relevant documents — it is about eliminating incorrect ones.</em></blockquote><h3>4. Answer Composer</h3><h4>What it does</h4><p>Generates the first draft answer.</p><h4>Prompt</h4><pre>Answer the question using ONLY the provided evidence.<br>Rules:<br>- cite every claim<br>- do not use outside knowledge<br>- if evidence is insufficient, say so</pre><h4>Code</h4><pre>def compose_answer(state, llm):<br>    prompt = build_prompt(state.query, state.evidence)<br>    state.draft = llm.generate(prompt)<br>    return state</pre><h4>Why it matters</h4><blockquote><em>The model is not allowed to guess</em></blockquote><h3>5. Verifier Agent</h3><h4>What it does</h4><p>Checks whether the answer is grounded.</p><h4>Prompt</h4><pre>Verify that all claims in the answer are supported by the evidence.<br>Return:<br>- pass/fail<br>- unsupported claims<br>- citation coverage</pre><h4>Code</h4><pre>def verify(state, llm):<br>    report = llm.structured_generate(state.draft)<br>    if not report[&quot;passed&quot;]:<br>        state.action = &quot;REFUSE&quot;<br>    return state</pre><h4>Why it matters</h4><p>This is the <strong>core hallucination control layer</strong></p><blockquote><em>No evidence → no answer</em></blockquote><h3>6. Risk &amp; Decision Agent</h3><h4>What it does</h4><p>Decides what to do next:</p><ul><li>answer</li><li>ask follow-up</li><li>refuse</li><li>escalate</li></ul><h4>Prompt</h4><pre>Decide the safest action:<br>Options:<br>- ANSWER<br>- FOLLOW_UP<br>- REFUSE<br>- ESCALATE</pre><pre>Consider:<br>- missing facts<br>- verification results<br>- risk level</pre><h4>Code</h4><pre>def risk_agent(state, llm):<br>    decision = llm.structured_generate(state)<br>    state.action = decision[&quot;action&quot;]<br>    return state</pre><h4>Why it matters</h4><p>Sometimes the correct answer is:</p><blockquote><em>“I need more information”</em></blockquote><p>or</p><blockquote><em>“This should be escalated”</em></blockquote><h3>⚡ Semantic Caching (Reducing Latency)</h3><p>Multi-agent systems are powerful — but slower.</p><p>So we introduce <strong>semantic caching</strong>.</p><h4>How it works</h4><p>Before running the pipeline:</p><ul><li>normalize the query</li><li>generate embedding</li><li>check cache</li></ul><h4>Code</h4><pre>def semantic_cache_lookup(query, cache, embed):<br>    key = embed(query)<br>    return cache.get(key)</pre><h4>Important detail</h4><p>Cache keys should include:</p><ul><li>query</li><li>region</li><li>policy type</li><li>version</li></ul><h4>Why it matters</h4><ul><li>reduces latency</li><li>reduces cost</li><li>reuses verified answers</li></ul><h4>Cache Invalidation (Critical for Production)</h4><p>Semantic caching is powerful, but dangerous if used incorrectly.</p><p>A cached answer may become invalid when:</p><ul><li>policies are updated</li><li>new rules override previous ones</li><li>regional rules change</li><li>exceptions are introduced</li></ul><p>Without proper invalidation:</p><blockquote><em>The system may return correct-looking but outdated answers.</em></blockquote><pre>def invalidate_cache(policy_id, cache):<br>    keys = cache.find_by_policy(policy_id)<br>    for k in keys:<br>        cache.delete(k)</pre><h3>🔄 Full Workflow</h3><pre>def workflow(query):<br>    state = State()<br>    state.query = query<br>    state = router_agent(state)<br>    if state.missing_facts:<br>        return ask_follow_up(state)<br>    state = retriever_agent(state)<br>    state = curate_evidence(state)<br>    state = compose_answer(state)<br>    state = verify(state)<br>    state = risk_agent(state)<br>    return finalize(state)</pre><h3>How This Reduces Hallucination</h3><p>This system reduces hallucination through structure:</p><ul><li>controlled retrieval</li><li>curated evidence</li><li>grounded generation</li><li>verification layer</li><li>risk-based decisions</li></ul><blockquote><em>Hallucination is not solved by prompting.<br> It is reduced by architecture.</em></blockquote><h3>Final Thought</h3><p>In <a href="https://medium.com/@amrqura/building-a-production-grade-rag-system-for-claims-processing-part-1-6e9fff0cab40">Part 1</a>, we fixed retrieval.</p><p>In Part 2, we fixed reasoning and decision-making.</p><p>Now the system:</p><ul><li>answers only when confident</li><li>asks when needed</li><li>refuses when unsafe</li></ul><h3>What’s Next (Part 3)</h3><p>In the next article, we’ll go deeper into:</p><ul><li>observability and audit logs</li><li>human-in-the-loop workflows</li><li>evaluation and metrics</li><li>hallucination monitoring in production</li></ul><blockquote>If your system cannot explain why an answer is correct — and why others are wrong — then it is not ready for production.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d60155aad315" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Production-Grade RAG System for Claims Processing (Part 1)]]></title>
            <link>https://medium.com/@amrqura/building-a-production-grade-rag-system-for-claims-processing-part-1-6e9fff0cab40?source=rss-f8d321bd6883------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e9fff0cab40</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[production-rag]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[agentic-rag]]></category>
            <dc:creator><![CDATA[Amr Koura]]></dc:creator>
            <pubDate>Thu, 26 Mar 2026 16:21:09 GMT</pubDate>
            <atom:updated>2026-03-26T16:21:09.130Z</atom:updated>
            <content:encoded><![CDATA[<h4>Why vector search alone is not enough — and what it actually takes to build a reliable system</h4><h3>Introduction</h3><p>Over the past year, Retrieval-Augmented Generation (RAG) has become the default pattern for building AI assistants on top of internal knowledge.</p><p>Most demos look like this:</p><blockquote><em>User question → vector search → LLM → answer</em></blockquote><p>And honestly, that works… <strong>until it doesn’t</strong>.</p><p>The moment you move into <strong>high-stakes domains</strong> — like claims processing, insurance policies, or financial rules — this simple pipeline starts to break:</p><ul><li>The model gives <strong>confident but incomplete answers</strong></li><li>It mixes <strong>outdated and current policies</strong></li><li>It ignores <strong>exceptions and overrides</strong></li><li>And worst of all… it answers when it <strong>shouldn’t</strong></li></ul><p>So in this article, I’ll walk through how to design a <strong>production-grade RAG system for claims processing</strong>, with strict requirements:</p><ul><li>✅ Every answer must include <strong>proper citations</strong></li><li>❌ The system must <strong>refuse to answer</strong> if evidence is insufficient</li><li>❓ It should <strong>ask follow-up questions</strong> when key information is missing</li><li>⚖️ It must handle <strong>policy precedence and overrides</strong></li><li>🔍 It must be <strong>auditable and explainable</strong></li></ul><p>And most importantly:</p><blockquote><em>We’ll see why </em><strong><em>vector search alone is not enough</em></strong><em>, and how to build a </em><strong><em>hierarchical hybrid retrieval system</em></strong><em> instead.</em></blockquote><h3>🧩 Understanding the Problem: What is Claims Processing?</h3><p>Before diving into architecture, let’s define the problem.</p><h4>What is a “claim”?</h4><p>A claim is a <strong>request for coverage or reimbursement</strong> based on a policy.</p><p>Examples:</p><ul><li>“Is this treatment covered?”</li><li>“Can this expense be reimbursed?”</li><li>“Does this case qualify under the policy?”</li></ul><p>This is not just a retrieval problem.</p><blockquote><em>It is a </em><strong><em>decision-making problem</em></strong><em>.</em></blockquote><h4>Claims Processing vs Compliance</h4><p>It’s important to distinguish:</p><ul><li><strong>Compliance systems</strong> answer:</li></ul><blockquote>“What are the rules?”</blockquote><ul><li><strong>Claims systems</strong> answer:</li></ul><blockquote>“Does this specific case satisfy the rules?”</blockquote><p>Claims processing is harder because it requires:</p><ul><li>applying rules</li><li>handling conditions</li><li>resolving conflicts</li><li>making decisions</li></ul><h3>Why This is Hard</h3><h3>1. Context is critical</h3><p>The answer depends on:</p><ul><li>policy type</li><li>region</li><li>dates</li><li>conditions</li></ul><p>Missing one variable → wrong answer.</p><h4>2. Policies are hierarchical</h4><p>Rules are layered:</p><ul><li>global rules</li><li>regional overrides</li><li>special clauses</li><li>updated versions</li></ul><p>👉 The system must understand: <strong><em>Which rule wins</em></strong></p><h4>3. Sources may conflict</h4><p>The system may retrieve:</p><ul><li>a general rule</li><li>an exception</li><li>an outdated version</li></ul><p>All relevant — only one correct.</p><h4>4. The cost of being wrong is high</h4><p>This is not a chatbot.</p><ul><li>wrong answers = financial loss</li><li>wrong interpretation = legal risk</li></ul><p>So the system must be: <strong><em>accurate, safe, and explainable</em></strong></p><h3>The Problem with “Vector Search + LLM”</h3><p>Vector search is powerful.</p><p>But:</p><blockquote><em>It retrieves what is </em><strong><em>similar</em></strong><em>, not what is </em><strong><em>correct</em></strong></blockquote><h4>Example</h4><p>“Is this claim covered?”</p><p>Vector search may return:</p><ul><li>general policy</li><li>exception</li><li>outdated rule</li></ul><p>The LLM:</p><ul><li>merges them</li><li>ignores precedence</li><li>hallucinates</li></ul><p>That’s unacceptable.</p><h3>Production Requirements (What Changes Everything)</h3><p><em>To make this system reliable in production, we enforce a few strict constraints.</em></p><h4>1. Grounded answers only</h4><p>Every claim must have a citation.</p><blockquote><em>No citation → no answer</em></blockquote><h4>2. Refusal is required</h4><p>If evidence is insufficient:</p><blockquote><em>The system must refuse</em></blockquote><h4>3. Ask when context is missing</h4><blockquote>No guessing allowed.</blockquote><h4>4. Precedence must be enforced</h4><p>The system must know:</p><blockquote><strong><em>Which rule overrides which</em></strong></blockquote><h3>The Role of the Data Layer</h3><p>To support this, we use a <strong>multi-store architecture</strong>:</p><ul><li><strong>Vector Store</strong> → semantic retrieval</li><li><strong>Relational DB</strong> → structured rules (limits, thresholds)</li><li><strong>Document Store</strong> → full policies</li><li><strong>Graph DB (Knowledge Graph)</strong> → relationships &amp; precedence</li></ul><figure><img alt="Production RAG data layer" src="https://cdn-images-1.medium.com/max/1024/1*_GYSE8ZtQW6Fuzp6DorkbA.png" /></figure><h3>Why the Graph Database Matters</h3><p>Vector search retrieves candidates.</p><blockquote><em>The graph decides which ones are allowed to be true.</em></blockquote><p>It models:</p><ul><li>overrides</li><li>supersedes</li><li>dependencies</li><li>conditions</li></ul><p>So we move from:</p><blockquote><em>“What is similar?”</em></blockquote><p>to:</p><blockquote><em>“What is authoritative?”</em></blockquote><h3>Why Vector Search Alone Fails</h3><p>Vector search gives:</p><ul><li>similarity</li><li>recall</li></ul><p>But not:</p><ul><li>hierarchy</li><li>precedence</li><li>correctness</li></ul><p>So you get:</p><blockquote><em>A </em><strong><em>best-guess system</em></strong><em>, not a reliable one</em></blockquote><h3>The Solution: Hierarchical Hybrid Retrieval</h3><p>Instead of a single retrieval step, we design a <strong>multi-stage pipeline</strong>.</p><p>The following pipeline shows how retrieval moves from coarse section-level search to precedence-aware ranking and finally chunk-level evidence selection.</p><figure><img alt="Hierarchical Hybrid Retrieval" src="https://cdn-images-1.medium.com/max/375/1*fID-c713IVMCxOHGXwKBbA.jpeg" /></figure><h3>Step 1: Hybrid Retrieval (Semantic + BM25)</h3><p>We combine:</p><ul><li>embeddings (semantic)</li><li>BM25 (keyword)</li></ul><h4>💻Code Example: Hybrid Score</h4><blockquote><em>At the first retrieval stage, we combine semantic similarity with lexical relevance so we can capture both meaning and exact policy wording.</em></blockquote><blockquote><em>The following snippets illustrate how this retrieval pipeline can be implemented in practice.</em></blockquote><pre>def hybrid_score(query_embedding, doc_embedding, bm25_score, alpha=0.7):<br>    semantic_score = cosine_similarity(query_embedding, doc_embedding)<br>    return alpha * semantic_score + (1 - alpha) * bm25_score</pre><blockquote><em>This simple scoring layer is often enough to outperform pure vector search in rule-heavy domains.</em></blockquote><h3>Step 2: Retrieve Sections First</h3><p>Instead of retrieving chunks directly:</p><ul><li>retrieve top sections</li><li>then drill down</li></ul><h4>💻 Code Example: Section Retrieval</h4><blockquote><em>Instead of retrieving all chunks directly, we first retrieve the most relevant sections to narrow down the search space.</em></blockquote><pre>def retrieve_sections(query, sections, bm25_index, top_k=5):<br>    query_emb = embed(query)<br>    scored = []<br><br>    for sec in sections:<br>        semantic = cosine_similarity(query_emb, sec[&quot;embedding&quot;])<br>        keyword = bm25_index.get_score(query, sec[&quot;text&quot;])<br>        score = hybrid_score(query_emb, sec[&quot;embedding&quot;], keyword)<br><br>        scored.append((sec, score))<br><br>    return sorted(scored, key=lambda x: x[1], reverse=True)[:top_k]</pre><blockquote><em>This step reduces noise and ensures that the system focuses only on the most relevant parts of the policy before drilling down further.</em></blockquote><h3>Step 3: Precedence Boosting (Graph DB)</h3><p>We adjust scores using the graph.</p><h4>💻 Code Example: Graph Boost</h4><blockquote><em>After retrieving candidate sections, we adjust their ranking based on policy precedence using the knowledge graph.</em></blockquote><pre>def apply_precedence_boost(section, score, graph):<br>    priority = graph.get_priority(section[&quot;id&quot;])<br>    return score * (1 + 0.1 * priority)</pre><blockquote><em>This ensures that authoritative rules — such as overrides or newer policies — are ranked higher than more general or outdated ones.</em></blockquote><h3>Step 4: Drill Down to Chunks</h3><p>After selecting sections:</p><ul><li>retrieve chunks within them</li><li>apply hybrid scoring again</li></ul><h4>💻 Code Example: Chunk Retrieval</h4><blockquote><em>Once the top sections are selected, we drill down and retrieve the most relevant chunks within those sections.</em></blockquote><pre>def retrieve_chunks(query, sections, chunk_store, bm25_index, top_k=5):<br>    query_emb = embed(query)<br>    results = []<br><br>    for sec in sections:<br>        chunks = chunk_store.get(sec[&quot;id&quot;])<br><br>        for chunk in chunks:<br>            semantic = cosine_similarity(query_emb, chunk[&quot;embedding&quot;])<br>            keyword = bm25_index.get_score(query, chunk[&quot;text&quot;])<br>            score = hybrid_score(query_emb, chunk[&quot;embedding&quot;], keyword)<br><br>            results.append((chunk, score))<br><br>    return sorted(results, key=lambda x: x[1], reverse=True)[:top_k]</pre><blockquote><em>By limiting chunk retrieval to selected sections, we significantly improve precision and reduce irrelevant results.</em></blockquote><h3>Step 5: Build Evidence Pack</h3><p>We select:</p><ul><li>top chunks</li><li>remove duplicates</li><li>ensure consistency</li></ul><h4>💻 Code Example: Evidence Selection</h4><blockquote><em>Finally, we construct a clean and deduplicated set of evidence that will be used to generate the final answer.</em></blockquote><pre>def build_evidence(chunks):<br>    seen = set()<br>    evidence = []<br><br>    for chunk, _ in chunks:<br>        if chunk[&quot;id&quot;] not in seen:<br>            evidence.append(chunk)<br>            seen.add(chunk[&quot;id&quot;])<br><br>    return evidence</pre><blockquote><em>This evidence set becomes the only source of truth, ensuring that every generated answer is grounded and traceable.</em></blockquote><h3>What This Changes</h3><p>We move from:</p><blockquote><em>Retrieval → Generation</em></blockquote><p>to:</p><blockquote><em>Retrieval → Ranking → Precedence → Validation → Generation</em></blockquote><p>It is very important to remeber:</p><blockquote><em>Retrieval is not only about finding relevant documents. It is also about excluding the wrong ones.</em></blockquote><h3>Final Thought</h3><blockquote><em>RAG is not a feature. It’s a system.</em></blockquote><p>And systems require:</p><ul><li>structure</li><li>control</li><li>discipline</li></ul><blockquote><em>If your system cannot explain why an answer is correct — and why others are wrong — then it’s not ready for production.</em></blockquote><h3>What’s Next (Part 2)</h3><p>In Part 2, we’ll cover:</p><ul><li>multi-agent orchestration</li><li>verification &amp; risk layers</li><li>refusal &amp; escalation</li><li>evaluation strategies</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e9fff0cab40" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>