<?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 Yash Makkar on Medium]]></title>
        <description><![CDATA[Stories by Yash Makkar on Medium]]></description>
        <link>https://medium.com/@yash.makkar07?source=rss-a7154f2da6a5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Df64sMs3YgYdmZch</url>
            <title>Stories by Yash Makkar on Medium</title>
            <link>https://medium.com/@yash.makkar07?source=rss-a7154f2da6a5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 01:49:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yash.makkar07/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[Evaluating RAG Systems: A Practical Mental Model Beyond Metrics]]></title>
            <link>https://medium.com/@yash.makkar07/evaluating-rag-systems-a-practical-mental-model-beyond-metrics-5b701336e552?source=rss-a7154f2da6a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b701336e552</guid>
            <category><![CDATA[rag-evaluation]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[rag-metrics]]></category>
            <dc:creator><![CDATA[Yash Makkar]]></dc:creator>
            <pubDate>Sun, 31 May 2026 17:20:54 GMT</pubDate>
            <atom:updated>2026-05-31T17:20:54.285Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Why great AI engineers think in evaluation layers — not metric lists.</em></p><p>If you’ve built a Retrieval-Augmented Generation (RAG) system, you’ve probably experienced the same cycle.</p><p>The demo works beautifully.</p><p>Early testing looks promising.</p><p>Then real users arrive.</p><p>Suddenly, answers become inconsistent, retrieval quality varies across query types, and stakeholders start asking a deceptively simple question:</p><p><strong>“How do we know whether the system is actually improving?”</strong></p><p>Many teams respond by collecting metrics. Precision@K, Recall, BLEU, ROUGE, Faithfulness, Answer Relevance — the list grows quickly.</p><p>The problem is that metrics alone rarely provide clarity.</p><p>Strong evaluation begins with a mental model.</p><p>Before choosing metrics, you need to understand what you’re trying to measure.</p><h3>Three Questions Every Evaluation Strategy Must Answer</h3><p>Most evaluation efforts ultimately answer one of three questions:</p><h3>Is the answer correct?</h3><p>This includes factual accuracy, groundedness, and hallucination detection.</p><h3>Is the answer useful?</h3><p>This measures relevance, completeness, clarity, and whether the response solves the user’s problem.</p><h3>Is the system reliable?</h3><p>This includes retrieval quality, latency, cost, scalability, and consistency over time.</p><p>Almost every evaluation metric can be mapped back to one of these three concerns.</p><p>Once you view evaluation through this lens, individual metrics become easier to reason about.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3zyQCj0O8FwJe9xiv4ebBQ.png" /></figure><h3>Measuring Retrieval Quality: Did We Fetch the Right Information?</h3><p>Before evaluating the generated answer, it’s worth asking whether the model was given the right information in the first place.</p><p>Retrieval quality is often the largest determinant of downstream RAG performance.</p><h3>Precision@K</h3><p>Precision@K measures the proportion of retrieved documents that are actually relevant.</p><p>Suppose a retriever returns five chunks and three are relevant to the query.</p><p>Precision@5 = 3/5 = 0.6.</p><p>High precision means the model receives less irrelevant context, reducing prompt noise and improving efficiency.</p><h3>Recall@K</h3><p>Recall@K answers a different question:</p><p>Of all the relevant information available in the corpus, how much was retrieved?</p><p>If ten relevant chunks exist and six appear in the top results:</p><p>Recall@K = 6/10 = 0.6.</p><p>Recall becomes particularly important in domains where missing a single critical document can lead to an incorrect answer.</p><h3>The Precision–Recall Tradeoff</h3><p>Retrieval systems rarely maximize both precision and recall simultaneously.</p><p>Increasing the number of retrieved documents often improves recall because more relevant information is included. However, it also tends to introduce irrelevant content, reducing precision.</p><p>Choosing the right retrieval depth is therefore an engineering decision rather than a metric optimization exercise.</p><h3>Mean Reciprocal Rank (MRR)</h3><p>MRR focuses on where the first relevant result appears.</p><p>If the first relevant document is ranked:</p><ul><li>First → Score = 1.0</li><li>Second → Score = 0.5</li><li>Fifth → Score = 0.2</li></ul><p>This metric is particularly useful when users care primarily about the highest-ranked result rather than the entire retrieved set.</p><h3>nDCG (Normalized Discounted Cumulative Gain)</h3><p>nDCG is often considered one of the most informative retrieval metrics because it evaluates both relevance and ranking quality.</p><p>Unlike binary metrics, nDCG supports graded relevance. A document can be:</p><ul><li>Highly relevant</li><li>Moderately relevant</li><li>Marginally relevant</li></ul><p>The metric rewards systems that place the most useful information near the top of the ranking while penalizing poor ordering.</p><p>For search-heavy applications, nDCG frequently provides a more realistic picture of retrieval quality than precision or recall alone.</p><h3>Measuring Generation Quality: Did the Model Produce a Good Answer?</h3><p>Once retrieval succeeds, attention shifts to the generated response itself.</p><p>Generation evaluation generally falls into two categories: reference-based and reference-free evaluation.</p><h3>Reference-Based Evaluation</h3><p>Reference-based metrics compare a generated answer against a known ground-truth response.</p><h3>BLEU</h3><p>BLEU measures n-gram overlap between generated and reference text.</p><p>Because it evaluates lexical overlap, BLEU tends to reward responses that share similar phrasing with the reference answer. This worked well for machine translation, where acceptable outputs are often relatively constrained.</p><p>For open-ended LLM applications, however, BLEU can undervalue perfectly correct answers that use different wording.</p><h3>ROUGE-L</h3><p>ROUGE-L measures overlap using the longest common subsequence between generated and reference text.</p><p>It became popular in summarization tasks because it is somewhat more tolerant of wording variation than BLEU while still rewarding content overlap.</p><p>Like BLEU, however, it primarily evaluates surface-level similarity rather than semantic equivalence.</p><h3>BERTScore</h3><p>BERTScore addresses many of these limitations by comparing semantic similarity rather than exact lexical overlap.</p><p>Instead of asking whether two answers use the same words, it asks whether they convey the same meaning.</p><p>As a result, BERTScore often aligns more closely with human judgment in open-ended generation tasks, though it introduces additional computational cost.</p><h3>Reference-Free Evaluation: The Metrics That Matter in Production</h3><p>Production systems rarely have ground-truth answers available for every user query.</p><p>As a result, many modern evaluation pipelines rely heavily on reference-free evaluation.</p><h3>Faithfulness</h3><p>Faithfulness measures whether claims made in the answer are supported by the retrieved context.</p><p>A response may sound convincing and well-written while still inventing facts. Faithfulness attempts to quantify this risk.</p><p>For many RAG applications, it is one of the most important quality signals available.</p><h3>Answer Relevance</h3><p>Answer relevance evaluates whether the response actually addresses the user’s question.</p><p>A system can generate a perfectly grounded response that is still unhelpful if it answers a different question than the one being asked.</p><p>Correctness alone is not sufficient; usefulness matters as well.</p><h3>LLM-as-a-Judge</h3><p>In recent years, many teams have adopted some form of LLM-based evaluation to assess dimensions such as helpfulness, completeness, faithfulness, and reasoning quality.</p><p>The exact implementation varies, but the general idea is simple: a capable model evaluates another model’s output using a predefined rubric.</p><p>This approach scales human-like evaluation more effectively than manual review alone, although it introduces known biases, including:</p><ul><li>Position bias</li><li>Verbosity bias</li><li>Self-preference bias</li><li>Calibration inconsistency</li></ul><p>For that reason, LLM-based evaluation is often most effective when combined with traditional metrics and human review rather than replacing them entirely.</p><h3>Evaluating End-to-End RAG Systems</h3><p>Beyond individual metrics, several frameworks attempt to evaluate RAG systems holistically.</p><p>One commonly used approach evaluates four dimensions:</p><h3>Faithfulness</h3><p>Are claims in the answer supported by retrieved context?</p><h3>Answer Relevance</h3><p>Does the answer address the user’s question?</p><h3>Context Precision</h3><p>How much of the retrieved context was actually useful?</p><h3>Context Recall</h3><p>Did retrieval provide enough information to answer correctly?</p><p>The most important insight is not the framework itself but the tension between these dimensions.</p><p>For example, increasing retrieval depth often improves context recall because more information becomes available. At the same time, context precision may decrease because additional irrelevant material enters the prompt.</p><p>There is rarely a universally optimal setting. The appropriate balance depends on the application’s requirements and risk tolerance.</p><h3>Building Evaluation Datasets: The Difference Between Metrics and Measurement</h3><p>Metrics are only as useful as the datasets used to evaluate them.</p><p>This is where many evaluation strategies become fragile.</p><p>A team may spend weeks debating which metric to use while investing little effort in constructing representative evaluation data.</p><p>In practice, dataset quality often has a larger impact on evaluation quality than the choice between two similar metrics.</p><h3>Golden Datasets</h3><p>Golden datasets consist of manually curated examples containing:</p><ul><li>User question</li><li>Expected answer</li><li>Supporting source documents</li></ul><p>These datasets are expensive to create but provide high-confidence signals.</p><p>They serve as the foundation for regression testing. If a model upgrade causes previously successful examples to fail, the regression becomes immediately visible.</p><h3>Adversarial Datasets</h3><p>Adversarial datasets intentionally target known failure modes.</p><p>Examples include:</p><ul><li>Ambiguous queries</li><li>Contradictory documents</li><li>Multi-hop reasoning tasks</li><li>Missing-context scenarios</li><li>Near-boundary knowledge questions</li></ul><p>These datasets are particularly valuable because real-world failures often occur in edge cases rather than average cases.</p><h3>Synthetic Datasets</h3><p>Synthetic evaluation datasets use language models to generate question-answer pairs from existing corpora.</p><p>A common workflow involves:</p><ol><li>Selecting source documents.</li><li>Generating realistic user questions.</li><li>Producing expected answers.</li><li>Using those pairs as evaluation examples.</li></ol><p>Synthetic datasets provide scale and coverage quickly, although they can inherit biases from the generating model and should be validated periodically against human-created examples.</p><h3>Slice-Based Evaluation</h3><p>One of the most common mistakes in evaluation is relying exclusively on aggregate scores.</p><p>Consider a system with an overall faithfulness score of 0.85.</p><p>That single number does not reveal whether performance is consistent across different scenarios.</p><p>Breaking evaluation into slices often uncovers important patterns:</p><ul><li>Simple factual questions</li><li>Multi-hop reasoning tasks</li><li>Comparative analysis</li><li>Different languages</li><li>Different document lengths</li><li>Different domains</li></ul><p>Many production issues remain invisible until metrics are viewed through these slices.</p><h3>Offline Evaluation vs Online Evaluation</h3><p>A mature evaluation strategy combines both approaches.</p><h3>Offline Evaluation</h3><p>Offline evaluation runs against fixed datasets before deployment.</p><p>Its advantages include reproducibility, speed, and easy comparison across model versions.</p><p>Its limitation is that static datasets cannot fully represent evolving user behavior.</p><h3>Online Evaluation</h3><p>Online evaluation measures performance in production environments.</p><p>Common signals include:</p><ul><li>Faithfulness</li><li>Relevance</li><li>User feedback</li><li>Latency</li><li>Cost</li><li>Retrieval quality</li></ul><p>Online evaluation helps detect distribution shifts, retrieval drift, and quality regressions that may not appear in offline benchmarks.</p><p>The challenge is that production traffic rarely includes ground-truth answers, making reference-free evaluation increasingly important.</p><h3>Evaluation Is Ultimately About Trust</h3><p>The most common mistake in AI evaluation is treating it as a metric-selection exercise.</p><p>Evaluation is really about building confidence.</p><p>Confidence that answers are correct.</p><p>Confidence that users find them useful.</p><p>Confidence that the system remains reliable as data, models, and user behavior evolve.</p><p>Those three concerns — correctness, usefulness, and reliability — are the same questions we started with, and they remain the foundation of every effective evaluation strategy.</p><p>Metrics help answer those questions. Frameworks help organize them. Datasets help validate them.</p><p>Together, they transform evaluation from a reporting activity into an engineering discipline — one that often determines whether a GenAI system succeeds in production or remains an impressive prototype.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b701336e552" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design a RAG Pipeline for 10 Million Documents with Minimal Hallucination]]></title>
            <link>https://medium.com/@yash.makkar07/design-a-rag-pipeline-for-10-million-documents-with-minimal-hallucination-6951499f37a2?source=rss-a7154f2da6a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/6951499f37a2</guid>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <category><![CDATA[hallucinations]]></category>
            <dc:creator><![CDATA[Yash Makkar]]></dc:creator>
            <pubDate>Sat, 23 May 2026 07:25:13 GMT</pubDate>
            <atom:updated>2026-05-23T07:25:13.015Z</atom:updated>
            <content:encoded><![CDATA[<p>Retrieval-Augmented Generation (RAG) has become the standard architecture for enterprise AI systems. But building a RAG pipeline for a few thousand documents is very different from designing one that scales to <strong>10 million documents </strong>while maintaining:</p><ul><li>High retrieval accuracy</li><li>Low latency</li><li>Strong access control</li><li>Minimal hallucination</li><li>Operational reliability</li></ul><p>At scale, RAG is no longer just an LLM problem — it becomes a distributed systems and information retrieval problem.</p><p>Here’s a practical architecture for designing a production-grade RAG pipeline that remains grounded, explainable, and scalable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8RSGu61HSwudjzeF8XSr1g.png" /></figure><h3>1. Ingest and Normalize Documents</h3><p>A RAG system is only as good as its ingestion pipeline.</p><p>At enterprise scale, documents arrive from:</p><ul><li>PDFs</li><li>SharePoint</li><li>Wikis</li><li>Emails</li><li>Databases</li><li>Tickets</li><li>Internal portals</li></ul><p>The first challenge is turning all of them into a consistent representation.</p><h4>Deduplication</h4><p>Large organizations often store multiple copies of the same document across systems.</p><p>Without deduplication:</p><ul><li>Retrieval quality drops</li><li>Embedding storage increases unnecessarily</li><li>Ranking becomes noisy</li></ul><p>Use:</p><ul><li>Hash-based deduplication for exact copies</li><li>Semantic deduplication for near-identical content</li></ul><h4>Format Standardization</h4><p>Normalize all sources into a unified schema:</p><ul><li>Plain text</li><li>Tables</li><li>OCR outputs</li><li>Images (if multimodal retrieval is needed)</li><li>Structured metadata</li></ul><p>Consistency here improves downstream retrieval quality.</p><h4>Metadata Extraction</h4><p>Extract metadata such as:</p><ul><li>Author</li><li>Department</li><li>Creation date</li><li>Version</li><li>Tags</li><li>Access permissions</li></ul><p>Metadata later becomes critical for:</p><ul><li>Filtering</li><li>Ranking</li><li>Security enforcement</li><li>Freshness scoring</li></ul><h4>Versioning</h4><p>Documents evolve constantly.</p><p>A strong RAG pipeline tracks:</p><ul><li>Latest versions</li><li>Archived copies</li><li>Effective timestamps</li><li>Change history</li></ul><p>This prevents outdated answers from surfacing.</p><h3>2. Chunking Strategy (Most Important Step)</h3><p>Chunking is one of the highest-leverage decisions in any RAG system.</p><p>Even strong embeddings and rerankers fail if chunks are poorly designed.</p><h4>Why Chunking Matters</h4><p>Chunks that are:</p><ul><li>Too small lose context</li><li>Too large reduce retrieval precision</li><li>Poorly split break semantic continuity</li></ul><p>Bad chunking directly increases hallucination risk because the model receives incomplete evidence.</p><h4>Common Chunking Strategies</h4><h4>Fixed-size chunking</h4><p>Simple but often inefficient.</p><p>Example:</p><ul><li>512-token chunks</li><li>20% overlap</li></ul><h4>Semantic chunking</h4><p>Splits based on:</p><ul><li>Paragraphs</li><li>Headers</li><li>Sections</li><li>Topic boundaries</li></ul><p>Usually performs better for enterprise documents.</p><h4>Hierarchical chunking</h4><p>Useful for:</p><ul><li>Large manuals</li><li>Legal contracts</li><li>Technical documentation</li></ul><p>Allows retrieval at multiple granularities.</p><h4>Context Window Management</h4><p>At 10M-document scale, retrieving more chunks is not always better.</p><p>You must optimize:</p><ul><li>Chunk size</li><li>Overlap</li><li>Top-k retrieval count</li><li>Context compression</li></ul><p>to avoid overwhelming the LLM context window.</p><h3>3. Hybrid Retrieval (BM25 + Embeddings)</h3><p>Pure semantic search is not enough.</p><p>Enterprise systems require both:</p><ul><li>Keyword precision</li><li>Semantic understanding</li></ul><p>That’s why hybrid retrieval is now the standard approach.</p><h4>BM25 (Keyword Retrieval)</h4><p>BM25 performs extremely well for:</p><ul><li>Exact IDs</li><li>Error codes</li><li>Product names</li><li>Legal references</li><li>Configuration values</li></ul><p>Example:<br>Searching for ERR_CONN_RESET_504 is usually better handled by BM25 than embeddings.</p><h4>Embeddings (Semantic Retrieval)</h4><p>Embeddings help retrieve:</p><ul><li>Similar meaning</li><li>Intent</li><li>Natural language variations</li><li>Conceptual similarity</li></ul><p>Useful for queries like:</p><blockquote><em>“How do I reset VPN access?”</em></blockquote><p>even if the document wording differs.</p><h4>Merging Results with RRF</h4><p>The industry-standard way to combine keyword and semantic results is:<br><strong>Reciprocal Rank Fusion (RRF)</strong>.</p><p>RRF combines rankings from:</p><ul><li>BM25</li><li>Vector search</li></ul><p>without requiring manual score normalization.</p><p>This generally produces better retrieval quality than relying on either method alone.</p><h3>4. ANN Retrieval + Reranking (Two-Stage Retrieval)</h3><p>Searching across millions of chunks cannot rely on brute-force vector search.</p><p>Production systems use two-stage retrieval.</p><h4>ANN: Fast Candidate Retrieval</h4><p>Approximate Nearest Neighbor (ANN) methods allow fast retrieval across massive vector stores.</p><p>Common ANN index types include:</p><ul><li>HNSW</li><li>IVF</li><li>PQ</li></ul><p>Libraries such as:</p><ul><li>FAISS</li><li>ScaNN</li><li>Milvus</li></ul><p>implement these indexing strategies.</p><p>The ANN layer retrieves candidate chunks quickly.</p><h4>Reranking: Deep Semantic Scoring</h4><p>Initial ANN results are often noisy.</p><p>A reranker improves precision using deeper semantic understanding.</p><h4>Cross-Encoder Models</h4><p>Cross-encoders evaluate:</p><ul><li>Query + chunk together</li><li>Fine-grained semantic relevance</li><li>Contextual alignment</li></ul><p>Typical production flow:</p><ol><li>ANN retrieves top 100 chunks</li><li>Cross-encoder reranks them</li><li>Top 5–10 chunks go to the LLM</li></ol><p>This significantly improves grounding quality.</p><h3>5. Source Confidence Scoring</h3><p>Not all documents should be trusted equally.</p><p>A hallucination-resistant RAG system assigns confidence scores to retrieved sources before generation begins.</p><h4>Why Confidence Scoring Matters</h4><p>Even strong retrieval pipelines occasionally surface:</p><ul><li>Outdated chunks</li><li>Weak semantic matches</li><li>Contradictory sources</li><li>Low-authority content</li></ul><p>Confidence scoring acts as a filtering and gating layer before the LLM generates a response.</p><h4>Common Confidence Signals</h4><h4>Retrieval relevance</h4><p>Derived from:</p><ul><li>BM25 score</li><li>Vector similarity</li><li>Reranker score</li></ul><h4>Freshness score</h4><p>Recent documents often matter more for:</p><ul><li>Policies</li><li>Compliance rules</li><li>Incident procedures</li></ul><h4>Trust score</h4><p>Official repositories should rank higher than:</p><ul><li>Drafts</li><li>User-uploaded notes</li><li>Unverified documents</li></ul><h3>Retrieval consistency</h3><p>If multiple independent sources support the same answer, confidence increases substantially.</p><p>Consistency across documents is a strong grounding signal.</p><h4>Example Confidence Formula</h4><p>A production system may combine signals like:</p><pre>Final Confidence =<br>0.45 × Reranker Score +<br>0.25 × Vector Similarity +<br>0.20 × Trust Score +<br>0.10 × Freshness Score</pre><p>This score is then used for:</p><ul><li>Answer gating</li><li>Citation validation</li><li>Fallback triggering</li></ul><h4>Confidence Thresholds</h4><p>Example:</p><ul><li>Confidence &gt; 0.85 → Generate normally</li><li>Confidence between 0.65–0.85 → Generate cautiously with stronger citations</li><li>Confidence &lt; 0.65 → Refuse answer</li></ul><p>This dramatically reduces hallucination risk in enterprise systems.</p><h3>6. Constrained Generation</h3><p>This is one of the most important anti-hallucination layers.</p><p>The LLM should generate responses strictly from retrieved evidence.</p><h4>Only Retrieved Context</h4><p>The model must be instructed to answer only using supplied context.</p><p>No unsupported reasoning outside retrieved evidence.</p><h4>No External Knowledge</h4><p>Even if the model “knows” something from pretraining, it should avoid using it unless retrieved.</p><p>This is especially important in regulated enterprise environments.</p><h4>No Assumptions</h4><p>If information is missing:</p><ul><li>Do not infer</li><li>Do not fabricate</li><li>Do not guess</li></ul><p>Grounded incompleteness is safer than confident hallucination.</p><h4>Example System Prompt Pattern</h4><p>A common enterprise prompt pattern looks like this:</p><pre>You are an enterprise assistant.</pre><pre>Answer ONLY using the retrieved context provided below.</pre><pre>Rules:<br>- Do not use external knowledge<br>- Do not make assumptions<br>- If evidence is insufficient, reply:<br>  &quot;Insufficient evidence found.&quot;<br>- Every important claim must reference supporting citations<br>- If sources conflict, explicitly mention the conflict</pre><p>This simple constraint layer significantly improves factual grounding.</p><h4>Structured Generation</h4><p>Many production systems also force structured outputs such as:</p><ul><li>JSON</li><li>XML</li><li>Citation-tagged responses</li></ul><p>instead of free-form text generation.</p><p>This improves:</p><ul><li>Reliability</li><li>Validation</li><li>Downstream automation</li></ul><h3>7. Citation-Backed Responses</h3><p>Enterprise users trust systems that explain where answers came from.</p><p>Every response should include citations.</p><h4>Every Claim Linked</h4><p>Important claims should map back to:</p><ul><li>Source chunk</li><li>Document</li><li>Section</li></ul><h4>Include:</h4><ul><li>Document name</li><li>Page number</li><li>Timestamp</li><li>Section ID</li></ul><h4>Auditable Outputs</h4><p>Auditable systems become:</p><ul><li>Easier to debug</li><li>Easier to validate</li><li>Easier to trust</li></ul><p>This is critical in:</p><ul><li>Healthcare</li><li>Finance</li><li>Legal</li><li>Compliance-heavy industries</li></ul><h3>8. Hallucination Fallback Layer</h3><p>Sometimes the best answer is:</p><blockquote><em>“Insufficient evidence found.”</em></blockquote><p>A mature RAG pipeline includes fallback logic.</p><h4>Threshold Checks</h4><p>If:</p><ul><li>Retrieval confidence is weak</li><li>Sources conflict</li><li>Reranker scores are low</li><li>Citations are insufficient</li></ul><p>the system should avoid generating a confident response.</p><h4>Better No Answer Than Wrong Answer</h4><p>Enterprise AI systems usually fail because they provide incorrect answers confidently — not because they refuse too often.</p><p>A refusal mechanism is essential.</p><h3>9. Continuous Evaluation</h3><p>RAG quality is never “done.”</p><p>It requires ongoing evaluation pipelines.</p><h4>Retrieval Metrics</h4><p>Track:</p><ul><li>Recall@k</li><li>Precision</li><li>MRR</li><li>NDCG</li></ul><p>to measure retrieval quality consistently.</p><h4>Adversarial Testing</h4><p>Test edge cases like:</p><ul><li>Ambiguous queries</li><li>Contradictory documents</li><li>Missing context</li><li>Multi-hop reasoning failures</li></ul><p>Prompt injection testing should also be treated separately as a security evaluation layer rather than a retrieval-quality benchmark.</p><h4>Hallucination Tracking</h4><p>Monitor:</p><ul><li>Unsupported claims</li><li>Citation mismatches</li><li>Fabricated entities</li></ul><p>over time.</p><h4>Evaluation Frameworks</h4><p>Production teams commonly use frameworks like:</p><ul><li>RAGAS</li><li>TruLens</li><li>DeepEval</li></ul><p>to automate evaluation pipelines and monitor grounding quality.</p><h3>10. Caching, Security, and Observability</h3><p>At scale, operational maturity matters as much as retrieval quality.</p><h4>Exact-Match Query Cache</h4><p>Traditional caching stores responses for:</p><ul><li>Repeated queries</li><li>High-frequency prompts</li><li>Common enterprise workflows</li></ul><p>Examples:</p><ul><li>HR policies</li><li>VPN setup</li><li>Leave rules</li></ul><p>This reduces latency and inference cost.</p><h4>Semantic Cache</h4><p>At enterprise scale, exact query matching is insufficient.</p><p>Users may ask:</p><ul><li>“How do I reset VPN?”</li><li>“VPN access reset steps?”</li><li>“How can I regain VPN login access?”</li></ul><p>All three queries are semantically identical.</p><p>Semantic caching uses embedding similarity to retrieve cached responses for meaning-equivalent queries.</p><p>Frameworks like GPTCache implement this pattern.</p><p>This dramatically improves:</p><ul><li>Cache hit rates</li><li>Latency</li><li>Infrastructure cost</li></ul><h4>Retrieval Path Cache</h4><p>Caching:</p><ul><li>Retrieved chunks</li><li>Embedding queries</li><li>Reranker outputs</li></ul><p>can further reduce system load.</p><h4>Cache Invalidation</h4><p>Caching without invalidation becomes dangerous.</p><p>When documents change:</p><ul><li>Cached retrievals</li><li>Old embeddings</li><li>Stale answers</li></ul><p>must be refreshed properly.</p><h4>Access Control</h4><p>At enterprise scale, retrieval must enforce document-level permissions.</p><p>The system should never retrieve chunks users are not authorized to access.</p><p>This is one of the most overlooked production requirements.</p><h4>Embedding Drift</h4><p>Embedding models evolve over time.</p><p>Re-indexing strategies are necessary when:</p><ul><li>Embedding models change</li><li>Domain vocabulary evolves</li><li>Retrieval quality degrades</li></ul><h4>Observability</h4><p>Without observability, debugging RAG systems becomes extremely difficult.</p><p>Track:</p><ul><li>Retrieved chunks</li><li>ANN scores</li><li>Reranker scores</li><li>Final prompts</li><li>Latency bottlenecks</li><li>Failure patterns</li></ul><p>Strong observability turns RAG systems from demos into maintainable production platforms.</p><h3>Final Thoughts</h3><p>Designing a RAG pipeline for 10 million documents is not just about connecting an LLM to a vector database.</p><p>It requires:</p><ul><li>Retrieval engineering</li><li>Ranking optimization</li><li>Grounded generation</li><li>Security enforcement</li><li>Continuous evaluation</li><li>Operational observability</li></ul><p>The real objective is not simply generating answers.</p><p>It is generating answers that are:</p><ul><li>Accurate</li><li>Explainable</li><li>Auditable</li><li>Secure</li><li>Trustworthy</li></ul><p>Because in enterprise AI, reliability matters far more than creativity.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6951499f37a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>