A retrieval that returns no chunks is not a rare edge case: it happens when the question uses words the documents never use, when the filter is too strict, or when the knowledge base simply lacks the topic. The wrong response is to send an empty context to the model and let it answer from its own knowledge, because the user then gets a confident answer with no grounding. The right response is to detect the empty result, say the knowledge base has no answer, and log the question so the gap can be fixed.
What you need
- A RAG pipeline that can report an empty retrieval
- A fallback message that says the knowledge base has no answer
- A log where unanswered questions are recorded
Step 1: Detect the empty result before generation
Check the retriever result count before building the prompt. Zero chunks is a distinct state from a few weak chunks, and it needs its own handling.
Step 2: Answer honestly instead of generating
Reply that the knowledge base has no matching content for the question, and offer the closest topic it does cover, if any. Do not send an empty context to the model and present the guess as a grounded answer.
Step 3: Log the question and check the cause
Record the question, then check whether the cause was wording, a filter, or a real gap in the documents. A wording problem needs query rewriting; a real gap needs new content.
Worked example: synthetic empty retrieval handling
The table below is a synthetic example. It shows the expected result of handling an empty retrieval; no search was run.
| Question | Chunks returned | Response |
|---|---|---|
| Refund window | 3 | Answered from chunks |
| Office parking rules | 0 | No matching content – logged |
| Parking after filter fix | 2 | Answered from chunks |
| New topic | 0 | No matching content – logged |
Expected result (UNTESTED). questions with chunks are answered from them, and the two empty retrievals get an honest no-answer reply and are logged. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- An empty retrieval can be a filter problem: a tenant or date filter that is too strict returns nothing even when the content exists.
- Ground truth evaluations need a set of queries and their expected answers, including questions the base should not answer.
- A model told to say it does not know when the context lacks the answer is behaving correctly, not failing.
- If empty retrievals are common, the knowledge base or the query rewriting needs work, not the fallback message.
