RAG 全链路:从文档到答案RAG End to End: From Documents to Answers
微型指南 · 约 9 分钟Guide · about 9 min · 引用核验 2026-11-03(仅引用链接与日期) · refs checked 2026-11-03 (reference links and dates only)
分块、嵌入、检索、重排、生成、引用——RAG 的每一步都会单独失败;这篇把它们串成一条可排障的链路。Parsing, chunking, embedding, retrieval, reranking, generation and citation — every step fails on its own. This guide strings them into a debuggable pipeline.
文档解析与分块:先处理版式、表格与扫描件,再按语义边界切、保留标题与来源;解析错,后面全错。
嵌入与索引:记录模型版本与维度,换嵌入模型要重建索引。
检索:先召回足够多的候选,再用重排模型或规则收窄;只看 top-1 容易漏。
拼上下文:只放相关块,带来源标识;块之间去重,避免同一段重复占 token。
生成与引用:要求答案逐条对应来源;没有来源的句子标为「推断」。
Agentic RAG:让 agent 自己改 query、决定是否再检索、判断资料够不够;代价是步数与成本上升。
评测:分开测召回率、答案正确率与引用正确率,不要只测最终回答。
Document parsing and chunking: handle layout, tables and scans first, then cut on semantic boundaries and keep headings and provenance; parse wrong and everything downstream is wrong.
Embedding and index: record model version and dimensions; changing the embedding model means rebuilding the index.
Retrieval: recall enough candidates first, then narrow with a reranker or rules; top-1 alone misses too much.
Assemble context: include only relevant chunks with source labels; deduplicate chunks so the same passage does not consume tokens twice.
Generation and citation: require each answer sentence to map to a source; mark unsourced sentences as inference.
Agentic RAG: let the agent rewrite queries, decide whether to retrieve again and judge whether material is sufficient; the price is more steps and cost.
Evaluate separately: recall, answer correctness and citation correctness, not just the final answer.
例子与判断Example and interpretation
以下是教学情境,不是本站运行或实测记录。A teaching scenario, not a measured or executed site test.
取一份练习用报销政策,保留标题、版本和段落编号。用问题找到相关段落,再要求回答引用编号。最后逐句检查结论是否由该段落支持。这个练习的交付物是“问题—证据—回答”记录,不是一句“RAG 已跑通”。Use a sample reimbursement policy with title, version and paragraph IDs. Retrieve relevant paragraphs and request citations to them. Check support sentence by sentence. Deliver a question–evidence–answer record, rather than merely declaring the pipeline works.
联网 / 检索增强Retrieval-Augmented Generation, RAG 分块Chunking 向量 / 嵌入Embedding / Vector
怎么给文档做分块How to Chunk Documents for Retrieval · 怎么给检索结果重排How to Rerank Retrieval Results · 怎么做混合检索How to Do Hybrid Search · 怎么挑 embedding 模型How to Choose an Embedding Model