概述
这很重要,因为标准RAG会将检索到的任何内容直接传递给模型,而无关或误导性的文档是导致错误且自信回答的主要原因。
深入探讨
CRAG was introduced in the 2024 paper "Corrective Retrieval Augmented Generation" by Shi-Qi Yan and colleagues. It targets a basic weakness of standard RAG: the generator trusts the retriever. If the top documents are off-topic, outdated or only loosely related, the model often answers anyway. The paper's design adds a lightweight retrieval evaluator, a fine-tuned T5-large model in the original work, which scores each retrieved document for relevance to the question. Based on those scores, the system picks one of three actions. If at least one document is judged clearly relevant, the action is Correct: the documents go through knowledge refinement, a decompose-then-recompose step that splits them into small strips, scores each strip, and keeps only the useful ones. If all documents score low, the action is Incorrect: the retrieved documents are discarded, the question is rewritten into search-engine-style keywords, and web search results are used instead, again refined. If the evaluator is unsure, the action is Ambiguous, and the system combines refined internal knowledge with web results. The authors presented CRAG as plug-and-play: it can wrap standard RAG or other methods such as Self-RAG, and they reported improvements on several short-form and long-form generation benchmarks. In practice, many teams implement CRAG-style pipelines without the original fine-tuned evaluator, using an LLM prompt to grade relevance and a graph or agent framework (LangGraph has a well-known CRAG tutorial) to route between steps. Common misconceptions: CRAG does not verify that the final answer is correct; it grades retrieval inputs. Web search is not automatically better, since it can bring in low-quality sources. And grading adds latency and cost to every query.
现实世界的实施
一家公司的帮助台机器人为关于育儿假问题检索了三段政策文本,评估者发现这些文本都不相关,系统于是重写查询并重新搜索,而不是从错误的政策中回答。
一款医疗信息助手对检索到的段落进行评估,只保留提及用户询问药物的句子,并在生成答案前丢弃关于其他药物的周边文本。
一款新闻问答工具检测到其内部档案中没有关于最近事件的报道,于是退回到网络搜索以获取最新文章。
一个法律研究原型在文档仅部分相关时将检索标记为模糊,并在回答前将精炼后的内部段落与最新的搜索结果相结合。
纠正性RAG(CRAG)的未来
CRAG 思想,即检查检索质量并相应调整路径,已成为代理式 RAG 系统中的常见模式,其中模型决定是否再次检索、在其他地方搜索或直接回答。未来工作可能会聚焦于更便宜、更好校准的相关性评估器,以及将输入检查与输出检查相结合,例如验证答案是否得到保留证据的支持。随着时间推移,具体的三动作方案可能不再像检索到的上下文应被评估而非自动信任这一更广泛原则那样重要。
付诸实践
为什么这很重要
- 成本与预算. 多年来,架构决策决定着性能和运营成本。
- 更清晰的判决. 技术教育帮助团队选择正确的堆栈,而不仅仅是最新的堆栈。
- 质量控制. 更好的工程选择可以减少生产中的可靠性事故。
留意
- 优化一项基准测试可以隐藏更广泛的系统弱点。
- 基础设施和维护成本常常被低估。
- 随着系统变得更加复杂,安全性和可观察性差距可能会扩大。
后续步骤
- 在实施之前定义延迟、质量和成本目标。
- 在实际负载和数据条件下进行基准测试。
- 仪器监控错误、漂移和用户影响。
- 在扩展之前准备回滚和事件响应路径。
不断探索
常见问题
什么是 Corrective RAG(CRAG)?
Corrective RAG(CRAG)是一种检索增强生成方法,在回答之前检查检索到的文档的相关性,并在检索看起来薄弱时采取纠正措施,例如细化文档、重写查询或搜索网络。它之所以重要,是因为标准 RAG 会将检索到的任何内容直接传递给模型,而无关或误导性的文档是产生错误且自信回答的主要原因。
CRAG 解决了标准 RAG 的哪一核心弱点?
标准 RAG 无论相关性如何都会将检索到的文档传递给模型,这可能导致自信的错误答案。CRAG 会先评估检索结果。
在原始 CRAG 论文中,哪种模型被用作检索评估器?
论文使用轻量级微调的 T5-large 模型来评分文档相关性。
当所有检索到的文档得分低时,CRAG 会做什么?
错误操作会丢弃这些文档,将问题改写为搜索查询,并依赖精炼后的网络结果。
分解‑然后‑重组步骤的目的是什么?
知识细化将文档拆分成小块,对其进行打分,并仅将有用的部分重新组合供生成器使用。
当评估者不确定相关性时,CRAG 会采取什么行动?
模糊行动将两种来源混合,以对评估者判断的不确定性进行对冲。