<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tanmoy Dasgupta</title>
    <description>The latest articles on DEV Community by Tanmoy Dasgupta (@tanmoy_dasgupta).</description>
    <link>https://dev.to/tanmoy_dasgupta</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4203531%2F7a5ab292-a06f-41b3-8507-0f4dafd84844.png</url>
      <title>DEV Community: Tanmoy Dasgupta</title>
      <link>https://dev.to/tanmoy_dasgupta</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tanmoy_dasgupta"/>
    <language>en</language>
    <item>
      <title>Your RAG chatbot confidently answers questions about docs that don't exist in production. How to fix.</title>
      <dc:creator>Tanmoy Dasgupta</dc:creator>
      <pubDate>Sun, 08 Nov 2026 15:27:15 +0000</pubDate>
      <link>https://dev.to/tanmoy_dasgupta/your-rag-chatbot-confidently-answers-questions-about-docs-that-dont-exist-in-production-how-to-3o2f</link>
      <guid>https://dev.to/tanmoy_dasgupta/your-rag-chatbot-confidently-answers-questions-about-docs-that-dont-exist-in-production-how-to-3o2f</guid>
      <description>&lt;p&gt;You built a RAG system. It scores say 0.91 faithfulness on your eval set. You deploy it. A user asks about a return policy that isn't in your knowledge base. The chatbot answers confidently, fluently, and completely wrong. Sounds familiar right !!&lt;/p&gt;

&lt;p&gt;This isn't a prompt engineering problem. It's a retrieval architecture bug that almost every RAG tutorial skips.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What actually happens&lt;/strong&gt;&lt;br&gt;
When a user query has no good match in your vector store, cosine similarity doesn't return "nothing found." It returns &lt;em&gt;the least-bad chunk&lt;/em&gt;, whatever is closest in embedding space, even if it's completely irrelevant. Your reranker then picks the best of these bad candidates. The LLM receives context that's wrong-but-plausible and does exactly what it's trained to do: generate a fluent, coherent answer. No hallucination flag. Just wrong.&lt;/p&gt;

&lt;p&gt;Your eval set never caught this because you built it from documents  &lt;em&gt;in&lt;/em&gt; your knowledge base. Every golden query always had a valid retrieval match. The failure mode only surfaces on out-of-distribution queries — which is most of production traffic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fix: similarity thresholding before generation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;vectorstore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;similarity_search_with_score&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;top_score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;  &lt;span class="c1"&gt;# cosine similarity of best match
&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;top_score&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mf"&gt;0.72&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# calibrate this on your domain
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I couldn&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;t find information about this in our knowledge base.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;doc&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.65&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The threshold isn't universal, i.e 0.72 is a starting point. Calibrate it by running your golden eval set and finding the score below which faithfulness drops sharply. For most general-purpose corpora it's between 0.65–0.78.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why this matters for interviews too&lt;/strong&gt;&lt;br&gt;
This exact scenario "your RAG system hallucinates on queries about content not in the knowledge base, how do you fix it?" Well, shows up verbatim in AI engineering interview loops at companies building production RAG systems. The answer they're looking for isn't "better prompting." It's similarity thresholding, out-of-distribution detection, and a graceful fallback path.&lt;/p&gt;

&lt;p&gt;If you're prepping for AI engineering roles, the full RAG system design question set (including this one) is covered in depth on KnowEaseAI (&lt;a href="https://knoweaseai.com/blog/rag-system-design-interview-questions" rel="noopener noreferrer"&gt;https://knoweaseai.com/blog/rag-system-design-interview-questions&lt;/a&gt;)&lt;br&gt;
— with the production failure modes that actually show up in interviews, not just the happy path.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>python</category>
      <category>rag</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
