A Practical Introduction to Retrieval-Augmented Generation
A tutorial explains retrieval-augmented generation as three steps: retrieving relevant passages from a knowledge base, injecting them into the model context, and generating an answer from them. Using a refund-policy question as an example, it covers document chunking, dense and sparse retrieval, hybrid retrieval with reciprocal rank fusion, neural reranking, and evaluation with recall@k, MRR, and nDCG.
The tutorial provides an implementation-oriented overview of connecting a language model to external, potentially current knowledge, with concrete guidance spanning document preparation, retrieval, reranking, and evaluation.
原文:mp.weixin.qq.com/s/XlJoIj-Tx…(2026年10月02日)
前两篇讲的是“怎么记”。可记忆和知识一旦多起来,新的难题就冒出来了:需要的时候,怎么快速找到相关的那几条?
你大概遇到过这种情况:大模型知识渊博,却不知道你公司这周刚更新的退款政策;它的训练数据停在某个日期,而现实一直在变。解决办法叫 RAG(Retrieval-Augmented Generation,检索增强生成)——把模型的思考能力,和外挂知识库的广度、时效结合起来。下面,就把它拆开看。
一、RAG 的三步:检索 → 增强 → 生成
先看它最朴素的样子。用户问:“我买的东西想退款,流程是什么?”系统大致做三件事:从知识库里检索出相关片段,把这些片段注入模型的上下文,让模型基于片段生成答案。
#Retrieval-Augmented Generation#BERT#BGE-M3#ANNOY#HNSW#BM25#Reciprocal Rank Fusion#OpenViking