fix: honor required retrieval for evidence requests - #950
Draft
hedhoud wants to merge 1 commit into
Draft
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
OpenRAG's chat pipeline asks the query contextualizer whether a message needs document retrieval before it searches the selected partition. That decision is appropriate for greetings and casual conversation, but it is unsafe for evidence evaluation: a scientific claim can be sent as a statement with no question mark, and the classifier can label it conversational.
In the SciFact evaluation on September 10, 2026, this caused 71 of 300 claim requests to return no retrieved sources. The requests completed without HTTP or chat errors, so the failure was silent. Direct vector search had candidates for all 71; for 55 claims a gold document was in the top 50, including the expected document at rank 1 for 31 claims.
The failure occurs before vector search and reranking. When the classifier returns
requires_retrieval: falseandquery_list: [],QueryServicebuilds a direct answer with an empty context. The original evaluation did not record the classifier decision, but replaying the affected claims ondevelopreproduced this behavior for 70 of 71 claims. Calling retrieval directly with the same original claims returned 10 chunks each time.For example, the claim
Albendazole is used to treat lymphatic filariasis.had gold document1215116. Direct search ranked1215116first, while the chat request returnedall_retrieved_sources: []and no error because retrieval was skipped.Solution
This change adds the opt-in request metadata flag
require_retrieval. When it is exactly JSONtrue, partition-backed chat, streaming chat, and text completions must attempt retrieval even if the contextualizer says to skip. If the classifier returns no query, the service searches the original user input. Existing partition, workspace, attachment, and temporal-filter restrictions remain in effect. The default remainsfalse, so normal casual conversation keeps its current behavior.The contextualizer prompt also explicitly identifies factual and scientific claims as retrieval requests. The prompt improvement helps ordinary clients, while
require_retrievalprovides a deterministic contract for evaluations and evidence-verification workflows.The option guarantees an attempted search, not a relevant result or a correct answer. The response can still contain no matching evidence, and retrieval relevance and citation generation remain separate metrics.
Example
Request:
{ "model": "openrag-scifact", "messages": [ {"role": "user", "content": "Albendazole is used to treat lymphatic filariasis."} ], "metadata": { "require_retrieval": true } }With the option enabled, a
requires_retrieval: falseclassifier response no longer ends the request. OpenRAG falls back to the claim itself, searches thescifactpartition, and exposes the retrieved sources to the answer pipeline.Validation
require_retrieval: trueattempted retrieval for 300/300 requests, returned sources for 300/300, and recovered sources for all 71 previously empty cases.Fixes #949.