<?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: Infrixo Systems</title>
    <description>The latest articles on DEV Community by Infrixo Systems (@infrixo).</description>
    <link>https://dev.to/infrixo</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%2F4220277%2F5cddbd82-2a86-47d8-9a74-5826745fdfdf.png</url>
      <title>DEV Community: Infrixo Systems</title>
      <link>https://dev.to/infrixo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/infrixo"/>
    <language>en</language>
    <item>
      <title>How Unanswerable Questions Can Inflate RAG Recall@K</title>
      <dc:creator>Infrixo Systems</dc:creator>
      <pubDate>Sun, 01 Nov 2026 09:27:51 +0000</pubDate>
      <link>https://dev.to/infrixo/how-unanswerable-questions-can-inflate-rag-recallk-25h8</link>
      <guid>https://dev.to/infrixo/how-unanswerable-questions-can-inflate-rag-recallk-25h8</guid>
      <description>&lt;p&gt;Retrieval evaluation is one of the first things we measure when building a Retrieval-Augmented Generation (RAG) pipeline.&lt;/p&gt;

&lt;p&gt;Metrics like Recall@K help answer a straightforward question:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Did the retriever return the documents needed to answer the question?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But there's an edge case that can make your evaluation results misleading: &lt;strong&gt;questions for which no relevant document exists.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;Suppose you're evaluating a RAG pipeline using a golden dataset containing eight questions.&lt;/p&gt;

&lt;p&gt;Seven questions are answerable from the document corpus. One is intentionally unanswerable.&lt;/p&gt;

&lt;p&gt;For the unanswerable question, the golden dataset correctly contains no expected source documents.&lt;/p&gt;

&lt;p&gt;A naive implementation of Recall@K might look like this:&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;recall_at_k&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retrieved_ids&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected_ids&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;expected_ids&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retrieved_ids&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;expected_ids&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;expected_ids&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problem is this condition:&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="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;expected_ids&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It awards perfect retrieval recall when there are no relevant documents to retrieve.&lt;/p&gt;

&lt;p&gt;That doesn't demonstrate successful retrieval. It means the retrieval metric is &lt;strong&gt;not applicable&lt;/strong&gt; to that question.&lt;/p&gt;

&lt;h2&gt;
  
  
  How this changes the evaluation score
&lt;/h2&gt;

&lt;p&gt;Consider the following example:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Question&lt;/th&gt;
&lt;th&gt;Answerable?&lt;/th&gt;
&lt;th&gt;Recall@K&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Q1&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;1.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Q2&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;1.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Q3&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;0.5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Q4&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;1.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Q5&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Q6&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;0.5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Q7&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;1.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Q8&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If we incorrectly award the unanswerable question a recall score of 1.0:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Naive mean Recall@K = 0.750&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If we exclude that question from the retrieval recall calculation:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Corrected mean Recall@K ≈ 0.714&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The retriever hasn't changed.&lt;/p&gt;

&lt;p&gt;The retrieved documents haven't changed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Only the evaluation logic changed.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A small difference in this example, but one that can become more significant when a dataset contains a larger proportion of unanswerable questions.&lt;/p&gt;

&lt;h2&gt;
  
  
  A better approach
&lt;/h2&gt;

&lt;p&gt;Instead of treating missing expected documents as perfect retrieval, return a non-applicable result.&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;recall_at_k&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retrieved_ids&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected_ids&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;expected_ids&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;

    &lt;span class="n"&gt;expected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;expected_ids&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;retrieved&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retrieved_ids&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retrieved&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When aggregating scores, exclude &lt;code&gt;None&lt;/code&gt; values from the mean and report how many questions were eligible.&lt;/p&gt;

&lt;p&gt;This is important because an empty expected-document set can represent different situations.&lt;/p&gt;

&lt;p&gt;For a deliberately unanswerable question, retrieval recall is not applicable.&lt;/p&gt;

&lt;p&gt;For a question whose relevance annotations are incomplete or missing, the evaluation dataset itself may need correction.&lt;/p&gt;

&lt;p&gt;Ideally, your golden dataset should explicitly distinguish these cases rather than infer answerability solely from an empty source list.&lt;/p&gt;

&lt;h2&gt;
  
  
  But unanswerable questions still matter
&lt;/h2&gt;

&lt;p&gt;Excluding unanswerable questions from retrieval recall doesn't mean excluding them from evaluation altogether.&lt;/p&gt;

&lt;p&gt;They test a different capability:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can the RAG system recognize insufficient evidence and avoid generating an unsupported answer?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That deserves a separate evaluation of abstention behavior.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Did the system correctly indicate that the available documents don't support an answer?&lt;/li&gt;
&lt;li&gt;Did it generate an answer despite insufficient evidence?&lt;/li&gt;
&lt;li&gt;Did it incorrectly refuse an answerable question?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Retrieval recall and abstention correctness answer different questions. Combining them into a single retrieval score can hide important failure modes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters in production
&lt;/h2&gt;

&lt;p&gt;RAG evaluation is often used to compare chunking strategies, embedding models, retrievers and rerankers.&lt;/p&gt;

&lt;p&gt;But before interpreting a score improvement, we need to trust the measurement itself.&lt;/p&gt;

&lt;p&gt;A change in dataset composition, answerability labels or metric aggregation can make a system look better without any actual improvement in retrieval.&lt;/p&gt;

&lt;p&gt;That's why I prefer reporting both the mean retrieval score and the number of eligible questions, while evaluating unanswerable cases separately.&lt;/p&gt;

&lt;h2&gt;
  
  
  Open-source implementation
&lt;/h2&gt;

&lt;p&gt;We encountered this issue while working on an open-source RAG evaluation starter and updated its handling of unanswerable golden-set questions.&lt;/p&gt;

&lt;p&gt;The project includes retrieval evaluation, answer-quality metrics, and optional LLM-based judging. Core metrics run locally without an API key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/infrixo-systems/rag-evaluation-starter" rel="noopener noreferrer"&gt;https://github.com/infrixo-systems/rag-evaluation-starter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm interested in how others handle this in their evaluation pipelines.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do you explicitly label unanswerable questions in your golden datasets, and how do you evaluate abstention separately from retrieval quality?&lt;/strong&gt;&lt;/p&gt;

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