RAG 三大范式与技术体系论文解读

文章系统解读了 RAG 综述论文,梳理了从 Naive RAG、Advanced RAG 到 Modular RAG 的三大范式演进,并深入解析检索、生成与增强三大核心技术,帮助读者理解 RAG 如何缓解 LLM 幻觉与知识滞后问题,构建更可信的知识密集型应用。

A
AGISeed Team
AGISeed 作者

Retrieval-Augmented Generation for Large Language Models: A Survey

Figure 1:Technology tree of RAG research. The stages of invo Figure 1:Technology tree of RAG research. The stages of involving RAG mainly include pre-training, fine-tuning, and inference. With the emergence of LLMs, research on RAG initially focused on leveraging the powerful in context learning abilities of LLMs, primarily concentrating on the inference stage. Subsequent research has delved deeper, gradually integrating more with the fine-tuning of LLMs. Researchers have also been exploring ways to enhance language models in the pre-training stage through retrieval-augmented techniques.

一、RAG 的背景与发展历程

近年来,大型语言模型(Large Language Models, LLMs)在自然语言处理领域取得了显著进展,但在处理领域特定或知识密集型任务时,仍面临若干固有局限。首先,LLMs 容易产生“幻觉”(hallucination),即生成与事实不符的内容;其次,训练数据存在截止日期,导致模型知识陈旧;此外,其推理过程往往缺乏透明度,难以追溯来源。这些问题限制了 LLMs 在真实场景中的可信应用。

为克服上述局限,检索增强生成(Retrieval-Augmented Generation, RAG)应运而生。其核心思想是:在 LLM 生成答案之前,先从外部知识库中检索与查询相关的文档片段,并将这些外部知识融入生成过程。通过引用外部知识,RAG 能够有效降低事实性错误,提升知识密集型任务的准确性与可信度,同时支持知识的持续更新以及领域特定信息的灵活集成。

从技术演进角度看,RAG 的发展贯穿了预训练(pre-training)、微调(fine-tuning)和推理(inference)三个阶段。早期研究主要关注如何通过预训练模型(Pre-trained Models, PTMs)引入额外知识,以改进预训练技术;随着 ChatGPT 等 LLM 的兴起,研究重点转向利用 LLM 强大的上下文学习(in-context learning, ICL)能力,在推理阶段为模型提供更丰富的上下文信息;随后,研究者开始将 RAG 与 LLM 微调技术更深入地结合,推动了 RAG 方法的快速发展。

二、RAG 的三大范式:从 Naive RAG 到 Modular RAG

Figure 3:Comparison between the three paradigms of RAG. (Lef Figure 3:Comparison between the three paradigms of RAG. (Left) Naive RAG mainly consists of three parts: indexing, retrieval and generation. (Middle) Advanced RAG proposes multiple optimization strategies around pre-retrieval and post-retrieval, with a process similar to the Naive RAG, still following a chain-like structure. (Right) Modular RAG inherits and develops from the previous paradigm, showcasing greater flexibility overall. This is evident in the introduction of multiple specific functional modules and the replacement of existing modules. The overall process is not limited to sequential retrieval and generation; it includes methods such as iterative and adaptive retrieval.

Figure 4:RAG compared with other model optimization methods Figure 4:RAG compared with other model optimization methods in the aspects of “External Knowledge Required” and “Model Adaption Required”. Prompt Engineering requires low modifications to the model and external knowledge, focusing on harnessing the capabilities of LLMs themselves. Fine-tuning, on the other hand, involves further training the model. In the early stages of RAG (Naive RAG), there is a low demand for model modifications. As research progresses, Modular RAG has become more integrated with fine-tuning techniques.

2.1 Naive RAG

Naive RAG 是最早被广泛应用的研究范式,遵循“索引(indexing)—检索(retrieval)—生成(generation)”的基础流程,也被称为 “Retrieve-Read” 框架。

  • Indexing:将原始数据清洗、提取并转换为统一文本格式,再切分为适合模型上下文限制的 chunk,通过 embedding 模型编码为向量,存储于向量数据库(vector database)中。
  • Retrieval:将用户查询编码为向量,计算其与索引语料中各 chunk 的相似度,返回 top-k 最相关的 chunk 作为扩展上下文。
  • Generation:将查询与检索到的文档合成为 prompt,输入 LLM 生成最终答案。

Naive RAG 存在明显局限:检索阶段常面临精度与召回率不足的问题,容易返回不相关内容或遗漏关键信息;生成阶段可能出现幻觉、输出不相关、有毒或带有偏见的内容;增强阶段则存在上下文融合生硬、信息冗余、风格不一致等问题,且单次检索往往难以满足复杂问题的信息需求。

2.2 Advanced RAG

针对 Naive RAG 的上述缺陷,Advanced RAG 引入了一系列改进策略,重点提升检索质量,并在检索前后分别进行优化。

  • Pre-retrieval 优化:改进索引结构(如提升数据粒度、添加 metadata、对齐优化、混合检索等),并对原始查询进行改写、扩展或重写,使其更适合检索任务。
  • Post-retrieval 优化:通过 reranking 重新排序检索结果,将最相关内容置于 prompt 的关键位置;通过 context compressing 减少信息过载,突出关键信息。

这些改进在 LlamaIndex、LangChain、HayStack 等框架中均有体现,有效缓解了 Naive RAG 在检索精度与上下文利用方面的不足。

2.3 Modular RAG

Modular RAG 进一步提升了架构的灵活性与可扩展性,采用模块化、可插拔的设计,支持检索、生成、增强等组件的灵活组合与动态调度。其主要创新体现在:

  • 新模块:如 Search 模块(支持搜索引擎、数据库、知识图谱等多源检索)、RAG-Fusion(多查询扩展与智能重排序)、Memory 模块(利用 LLM 记忆引导检索)、Routing(选择最佳检索路径)、Predict 模块(通过 LLM 生成上下文以减少噪声)、Task Adapter(适配不同下游任务)等。
  • 新模式:支持 Rewrite-Retrieve-Read、Generate-Read、Recite-Read 等流程,以及迭代检索(iterative retrieval)、递归检索(recursive retrieval)、自适应检索(adaptive retrieval)等动态调度方式。Modular RAG 还可与 fine-tuning、reinforcement learning 等技术协同,实现 retriever、generator 等组件的联合优化。

三、RAG 的核心技术:检索、生成与增强

Figure 5:In addition to the most common once retrieval, RAG Figure 5:In addition to the most common once retrieval, RAG also includes three types of retrieval augmentation processes. (left) Iterative retrieval involves alternating between retrieval and generation, allowing for richer and more targeted context from the knowledge base at each step. (Middle) Recursive retrieval involves gradually refining the user query and breaking down the problem into sub-problems, then continuously solving complex problems through retrieval and generation. (Right) Adaptive retrieval focuses on enabling the RAG system to autonomously determine whether external knowledge retrieval is necessary and when to stop retrieval and generation, often utilizing LLM-generated special tokens for control.

3.1 检索优化(Retrieval)

检索源(Retrieval Source):RAG 的检索源已从纯文本扩展到半结构化数据(如 PDF)和结构化数据(如 Knowledge Graph, KG),近年来还出现了利用 LLM 自身生成内容作为检索源的研究。

检索粒度(Retrieval Granularity):文本层面可从 token、phrase、sentence、proposition、chunk 到 document 不等;KG 层面则包括 entity、triplet、sub-graph 等。选择合适的检索粒度是提升检索效果的重要策略。

索引优化(Indexing Optimization)

  • Chunking 策略:固定 token 数量的分块方式最为常见,但需权衡上下文完整性与噪声。Recursive splitting、sliding window、Small2Big 等方法被提出以改善语义完整性。
  • Metadata 附加:为 chunk 添加页码、文件名、作者、时间戳等 metadata,可支持过滤和时序感知检索(time-aware RAG)。
  • 结构化索引:层次化索引(hierarchical index)和知识图谱索引(KG index)有助于维护概念间关系,减少幻觉并提升多文档检索与推理能力。

查询优化(Query Optimization)

  • Query Expansion:通过 multi-query、sub-query、Chain-of-Verification(CoVe)等方式扩展和验证查询。
  • Query Transformation:包括 query rewrite、HyDE(Hypothetical Document Embeddings)、step-back prompting 等,将原始查询转换为更利于检索的形式。
  • Query Routing:根据查询特征路由到不同的 RAG 流水线,可分为 metadata router/filter 和 semantic router。

Embedding 优化

  • 使用稀疏编码器(如 BM25)与稠密检索器(如基于 BERT 的模型)相结合的混合检索(hybrid retrieval)。
  • 在领域数据上 fine-tuning embedding 模型,以缓解领域术语偏差;LSR(LM-supervised Retriever)、PROMPTAGATOR、REPLUG 等方法利用 LLM 信号监督检索器训练。
  • 通过 Adapter(如 UPRISE、AAR、PRCA、BGM 等)在不直接微调模型的情况下增强对齐效果。

3.2 生成优化(Generation)

上下文整理(Context Curation)

  • Reranking:对检索结果重新排序,突出最相关文档,常用方法包括基于规则的策略(diversity、relevance、MRR 等)和基于模型的方法(如 BERT 系列、Cohere rerank、bge-reranker-large、GPT 等)。
  • Context Selection / Compression:通过 LLMLingua、LongLLMLingua、PRCA、RECOMP 等方法压缩 prompt,减少冗余信息,缓解 “Lost in the Middle” 问题;也可通过 LLM 自评估过滤低相关文档。

LLM Fine-tuning

  • 针对特定领域或数据格式微调 LLM,使其适应特定输出风格和数据结构。
  • 通过 reinforcement learning 对齐人类偏好或检索器偏好。
  • 与 retriever 协同微调,如 RA-DIT 通过 KL divergence 对齐 retriever 与 generator 的评分函数。

3.3 增强技术(Augmentation)

增强技术贯穿检索前、检索中、检索后三个阶段,实现检索结果与生成过程的深度融合:

  • Iterative Retrieval:在生成过程中交替进行检索与生成,逐步补充上下文。ITER-RETGEN 是代表性方法。
  • Recursive Retrieval:基于前一次检索结果迭代优化查询,逐步收敛到最相关信息。IRCoT、ToC 等方法是典型代表。
  • Adaptive Retrieval:由 LLM 自主判断是否需要检索以及何时停止检索。FLARE 通过监控生成置信度触发检索;Self-RAG 引入 “reflection tokens” 实现检索、生成与自我评判的协同。

四、RAG 的评估体系与基准

Figure 2:A representative instance of the RAG process applie Figure 2:A representative instance of the RAG process applied to question answering. It mainly consists of 3 steps. 1) Indexing. Documents are split into chunks, encoded into vectors, and stored in a vector database. 2) Retrieval. Retrieve the Top k chunks most relevant to the question based on semantic similarity. 3) Generation. Input the original question and the retrieved chunks together into LLM to generate the final answer.

4.1 下游任务

RAG 的核心任务仍然是 Question Answering(QA),包括单跳/多跳 QA、选择题、领域特定 QA 和长文本 QA 等。除此之外,RAG 已扩展至信息抽取(IE)、对话生成、代码搜索、事实核查、文本摘要、推理等多种下游任务。该综述指出,RAG 覆盖了约 26 类典型应用场景。

4.2 评估目标

  • 检索质量(Retrieval Quality):衡量 retriever 获取相关上下文的能力,常用指标包括 Hit Rate、MRR、NDCG 等。
  • 生成质量(Generation Quality):衡量 generator 基于检索上下文生成连贯、相关答案的能力。无标注内容侧重 faithfulness、relevance、non-harmfulness;有标注内容侧重准确性。

4.3 评估维度

RAG 评估强调三类质量分数和四项关键能力:

  • 质量分数:Context Relevance、Answer Faithfulness、Answer Relevance。
  • 关键能力:Noise Robustness(噪声鲁棒性)、Negative Rejection(拒绝回答无知识支撑的问题)、Information Integration(多文档信息整合)、Counterfactual Robustness(反事实鲁棒性)。

4.4 评估基准与工具

该综述提到,RAG 评估涉及近 50 个数据集。代表性基准包括 RGB、RECALL、CRUD 等;自动化评估工具有 RAGAS、ARES、TruLens 等,它们利用 LLM 对质量分数进行评判。系统化的评估方法对于衡量 RAG 的检索质量、生成质量与整体可靠性至关重要。

五、RAG 的挑战与未来研究方向

5.1 当前核心挑战

当前 RAG 仍面临检索召回与精确率瓶颈、生成可控性、多源信息融合等核心挑战。具体包括:

  • 检索结果中噪声或矛盾信息会显著影响输出质量,即 “misinformation can be worse than no information at all”;
  • 如何平衡检索粒度、上下文长度与生成质量;
  • 如何提升 RAG 对对抗性输入和反事实信息的鲁棒性;
  • 工程层面需解决检索效率、大规模知识库下的文档召回、数据安全等问题。

5.2 未来研究方向

  • 更高效的检索机制:结合超长上下文能力,探索 chunk 检索与长上下文输入的协同,提升推理效率与可解释性。
  • 自适应 RAG(Adaptive RAG):让 LLM 自主决定何时、何地、如何检索。
  • RAG 与 Fine-tuning 的混合:探索顺序、交替或端到端联合训练等最优集成方式,发挥参数化与非参数化优势。
  • 多模态 RAG(Multi-modal RAG):将 RAG 思想扩展至图像、音频、视频、代码等多种模态数据。
  • Production-Ready RAG:发展更完善的 RAG 技术栈与生态(如 LangChain、LlamaIndex、HayStack 等),推动定制化、简化和专业化。

5.3 结语

RAG 通过将 LLM 的参数化知识与外部知识库中的非参数化数据相结合,显著提升了 LLM 在知识密集型任务中的准确性、可信度和可更新性。从 Naive RAG 到 Advanced RAG,再到 Modular RAG,其技术范式不断演进;检索、生成与增强三大核心技术也在持续优化。尽管仍面临诸多挑战,RAG 将持续推动大语言模型在真实场景中的可信应用与知识更新能力。


原文来源:Gao Y, Xiong Y, Gao X, et al. Retrieval-Augmented Generation for Large Language Models: A Survey. arXiv preprint arXiv:2312.10997, 2023. Resources available at https://github.com/Tongji-KGLLM/RAG-Survey.

原文链接

https://arxiv.org/html/2312.10997

相关文章

RAG 与知识库

RAG 入门:让 AI 读懂你的数据

RAG入门到精通:向量检索、Embedding、知识图谱等核心技术原理与实战部署指南。

阅读更多
RAG 与知识库

LangGraph 多 Agent RAG 框架实战

本文介绍 LangGraph 这一面向长周期、有状态智能体的低级别编排框架,通过 StateGraph 构建“检索→相关性判断→生成答案”的多 Agent RAG 工作流,并提供可直接运行的完整代码示例,帮助开发者理解如何在复杂检索场景中实现持久执行、人机回环与生产化部署。

阅读更多
RAG 与知识库

Chroma 快速入门与双栈实战指南

本文是一份 Chroma 向量数据库的入门实战指南,面向 RAG 与知识库场景,介绍 Python 与 JavaScript 双栈的安装部署、核心 API(collection 增删改查、add/query)、数据写入与检索过滤,并简要说明本地部署迁移到 Chroma Cloud 的方法,帮助开发者快速上手搭建语义检索能力。

阅读更多