RAG相关综述
最近团队里阅读了一些 RAG 相关的 Survey paper。
4 篇经典的 survey:
- [2402.19473] Retrieval-Augmented Generation for AI-Generated Content: A Survey
- [2405.06211] A Survey on RAG Meeting LLMs: Towards Retrieval-Augmented Large Language Models
- [2410.12837] A Comprehensive Survey of Retrieval-Augmented Generation (RAG): Evolution, Current Landscape and Future Directions
- [2501.09136] Agentic Retrieval-Augmented Generation: A Survey on Agentic RAG
《A Survey on RAG Meeting LLMs》
A Survey on RAG Meeting LLMs: Towards Retrieval-Augmented Large Language Models
鉴于在 RAG 技术推动下 LLMs 取得的显著进展,有必要对检索增强的大型语言模型(RA-LLM)的最新进展进行系统性综述。Retrieval-Augmented Large Language Models(RA-LLMs)。
第 2 节中,对 LLMs 的背景知识进行简要介绍;第 3 节中,从检索、生成和增强的几个主要角度对 RA-LLMs 的现有研究进行回顾,并讨论了 RAG 中检索的必要性和应用频率;第 4 节中总结了 RA-LLMs 的主要训练技术;第 5 节中则介绍了各种 RA-LLMs 的应用;第 6 节中讨论了未来探索的关键挑战和潜在方向。
Background
LLM
- Encoder-only 模型:如 BERT 系列模型,通过将输入文本编码成高维空间来处理。Encoder-only 模型的关键特点是其双向性,意味着在编码时可以同时考虑每个标记的左右上下文。这种双向性使得 Encoder-only 模型能够更好地理解上下文中单词的含义,对于情感分析、评论阅读和文本分类等任务至关重要。
- Decoder-only 模型:以从左到右的方式生成文本。如 GPT,根据前面标记提供的上下文预测序列中的下一个标记。它们的架构使得它们在语言生成、代码生成和创造性写作等任务中特别有效。
- Encoder-Decoder 模型:如 T5,将各种 NLP 任务独特地转化为文本生成问题。更具体地说,T5 中的编码器处理输入序列以捕捉其意义,而解码器根据编码信息生成输出序列。这种 T5 架构非常适用于涉及将一个序列转换为另一个序列的任务,如机器翻译、摘要和对话回复生成。
Prompt Learning
- Prompt Engineering:像 BERT 这样的 Encoder-only 模型通常采用填充提示,因为它们与预训练任务的形式非常相似。对于其他模型,如 GPT,前缀提示往往更加适合,因为它们与生成任务相吻合。Soft prompt tuning 是另一种方式,它是 trainable continuous prompt embeddings,比如 Prefix-Tuning,就是在 prompt 里加入一段 embedding,这段 embedding 就是 soft prompt,不是真正的文本。
- ICL:尽管 ICL 非常有效,但它通常严重依赖于提供的示例质量,这可能导致生成次优的输出。更糟糕的是,ICL 可能没有足够的必要信息或先前知识来指导 LLMs 生成准确的响应。为了解决 ICL 的上述局限性,最近的研究引入了检索增强生成(RAG)技术。
RA-LLMs

Retrieval
检索的关键组件是检索器。
- 检索器类型:
- Sparse Retrieval:word-based,只能用于文本,比如 TF-IDF。不需要训练,检索性能依赖数据库和 query 的质量,而且只能支持文本相似性检索。
- Dense Retrieval:将 query 和 database 都嵌入进向量空间,可以用于各种数据格式。可以支持语义相似性检索,也可以训练。Embedding 怎么训练?
- 简单做法是 directly use a part of the generation model as the embedding layer of the retriever,这样检索和生成更容易对齐。
- One common retriever design in RAG is to construct two-stream encoders with the BERT structure (one encoder for the query and the other for the documents), which is also called bi-encoder。这种 bi-encoder 可以在不同的数据集做 pre-train 和 fine-tune。
- Another stream of dense retrievers having been widely applied in RA-LLMs uses one encoder only。这种一般是通用检索器,但效果一般不如微调后的 bi-encoder。
- 检索粒度:
- Retrieval granularity denotes the retrieval unit in which the corpus is indexed。索引单元,比如文档、段落、token、entity。检索粒度的选择可以显著影响模型的整体性能,包括效果和效率,因为它们决定了数据库的存储空间和搜索的计算成本。
- Token retrieval, instead can be done with faster searching but will bring more burden for the database saving。
- Chunk retrieval (also called passages) is common, which has been used in both traditional and LLM-based RAG models such as REALM。Text chunk may contain compact and complete information with less redundancy and irrelevancy, therefore becoming the mainstream retrieval text granularity in RAG。
-
Entity retrieval 是从知识而不是语言角度设计的,更细粒度还有 mention retrieval。这些更适合以实体为中心的任务,比 token retrieval 在空间上更高效。
-
预检索和后检索增强:
- 预检索:
- Query expansion:对 query 通过 LLM 做一个拓展,improve the query disambiguation and guide the retrievers。
- Query rewrite:将原始问题重新表述成更有利于检索的版本。动机是在新查询中明确检索需求,以减轻检索函数理解输入和增强输出的负担。
- Query augmentation:将原始查询和初步生成的输出组合成一个新的查询,进一步用于从外部数据库中检索相关信息。
-
后检索增强:
- 将检索器提取的前 k 个文档输入生成器之前,对它们进行处理,以实现检索和生成阶段之间更好的对齐。
- 方法有很多,不赘述,比如将检索的文档先变成一个摘要,然后再去生成。
-
数据库:
- 外部知识库有开源和闭源两种。闭源的一般是 KV 形式。Key 用于做相似性匹配,可以是 sparse 的,也可以是 embedding;value 一般是原始文本。开源的一般就是互联网搜索。
Generation
- 生成器的设计取决于下游任务,主要有黑盒和白盒两种。
- White-box generators allow parameter optimization, which can be trained to adapt to different retrieval and augmentation approaches for a better performance of generation.
- Black-box generators focus more on the retrieval and augmentation processes, trying to enhance the generator by augmenting the input (also called prompt in the context of LLMs) with better knowledge, guidance, or examples for the generation.
Retrieval Integration for Generation Augmentation
Augmentation:将检索和生成部分进行整合的技术过程,这是 RA-LLMs 的核心部分。
- 输入层整合:将检索到的信息/文档与原始输入/查询结合,并一起传递给生成器。
- 输出层整合:将检索和生成的结果结合起来,一起放到生成模型最后的 logit 层。Output-layer linear integration is flexible to apply since it can be plugged into most generation models without additional training。
- 中间层整合:即对检索出来的结果通过 transformer 放入模型中间层,具体怎么放不同模型也不一样,然后联合训练。中间层集成需要对生成模型有高度的访问权限,而对于大多数只能通过推理 API 访问的 LLMs 来说,这是不可行的。
大多数现有的方法根据 LLMs 的初步答案或其内部推理结果来确定检索的必要性。
Training
有两个分类,train-free 和 training-based。
- Train-free:推理时直接用检索到的知识,无需通过将检索到的文本插入提示中引入额外训练。这样可以基于 PE 来应用检索的信息。
- Training-based:对于 train-free,one potential challenge is that the retriever and generator components are not specifically optimized for downstream tasks。这里我理解的 downstream task 不是本身文本的生成,而是后续再下游的任务,比如推荐。
- Independent:将检索器和 LLMs 作为完全独立的过程进行训练,通过训练 LLMs 利用检索到的知识或训练检索器来弥合信息检索和语言生成之间的差距。
- Joint:端到端的范式同时优化检索器和生成器。
- Sequential:先训练检索器,再训练 LLMs,或者反过来。先被训练的在二阶段都是 frozen 的。
Applications
