“RAG”的版本间的差异
| 第1行: | 第1行: | ||
| − | <div | + | <div style="padding: 0 4%; line-height: 1.8; color: #1e293b; font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', Arial, sans-serif; background-color: #ffffff; max-width: 1200px; margin: auto;"> |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | <div style=" | + | <div style="margin-bottom: 30px; border-bottom: 1.2px solid #e2e8f0; padding-bottom: 25px;"> |
| − | + | <p style="font-size: 1.1em; margin: 10px 0; color: #334155; text-align: justify;"> | |
| − | + | <strong>RAG</strong>(Retrieval-Augmented Generation,检索增强生成)是一种将预训练大语言模型(LLM)与外部知识检索系统相结合的混合 AI 架构。它由 Meta AI 的 Patrick Lewis 等人于 2020 年正式提出。传统的 LLM(如 ChatGPT)像是一个<strong>“闭卷考试”</strong>的学生,依靠记忆(预训练权重)作答,容易产生<strong>幻觉 (Hallucination)</strong> 且无法获取最新信息;而 RAG 则赋予了模型<strong>“开卷考试”</strong>的能力——在回答问题前,先从外部知识库(如企业文档、互联网、医学指南)中检索相关信息,作为“参考资料”喂给模型,从而生成准确、可溯源且实时的回答。目前,RAG 已成为构建垂直领域 AI 应用(如法律、医疗助手)的主流范式。 | |
| − | + | </p> | |
| − | + | </div> | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | </div> | ||
| − | + | <div class="medical-infobox mw-collapsible mw-collapsed" style="width: 100%; max-width: 320px; margin: 0 auto 35px auto; border: 1.2px solid #bae6fd; border-radius: 12px; background-color: #ffffff; box-shadow: 0 8px 20px rgba(0,0,0,0.05); overflow: hidden;"> | |
| + | |||
| + | <div style="padding: 15px; color: #1e40af; background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%); text-align: center; cursor: pointer;"> | ||
| + | <div style="font-size: 1.2em; font-weight: bold; letter-spacing: 1.2px;">RAG</div> | ||
| + | <div style="font-size: 0.7em; opacity: 0.85; margin-top: 4px; white-space: nowrap;">Retrieval-Augmented Generation (点击展开)</div> | ||
| + | </div> | ||
| + | |||
| + | <div class="mw-collapsible-content"> | ||
| + | <div style="padding: 25px; text-align: center; background-color: #f8fafc;"> | ||
| + | <div style="width: 100px; height: 100px; background-color: #e2e8f0; border-radius: 50%; margin: 0 auto; display: flex; align-items: center; justify-content: center; color: #94a3b8; font-size: 0.8em;"> | ||
| + | |||
| + | </div> | ||
| + | <div style="font-size: 0.8em; color: #64748b; margin-top: 12px; font-weight: 600;">核心:检索 + 生成</div> | ||
| + | </div> | ||
| + | <table style="width: 100%; border-spacing: 0; border-collapse: collapse; font-size: 0.85em;"> | ||
| + | <tr> | ||
| + | <th colspan="2" style="padding: 8px 12px; background-color: #e0f2fe; color: #1e40af; text-align: left; font-size: 0.9em; border-top: 1px solid #bae6fd;">技术参数</th> | ||
| + | </tr> | ||
| + | <tr> | ||
| + | <th style="text-align: left; padding: 6px 12px; background-color: #f8fafc; color: #475569; border-bottom: 1px solid #e2e8f0; width: 40%;">提出时间</th> | ||
| + | <td style="padding: 6px 12px; border-bottom: 1px solid #e2e8f0; color: #0f172a;">2020 年 (NeurIPS)</td> | ||
| + | </tr> | ||
| + | <tr> | ||
| + | <th style="text-align: left; padding: 6px 12px; background-color: #f8fafc; color: #475569; border-bottom: 1px solid #e2e8f0;">核心组件</th> | ||
| + | <td style="padding: 6px 12px; border-bottom: 1px solid #e2e8f0; color: #0f172a;">向量数据库, LLM</td> | ||
| + | </tr> | ||
| + | <tr> | ||
| + | <th style="text-align: left; padding: 6px 12px; background-color: #f8fafc; color: #475569; border-bottom: 1px solid #e2e8f0;">解决痛点</th> | ||
| + | <td style="padding: 6px 12px; border-bottom: 1px solid #e2e8f0; color: #16a34a;"><strong>幻觉, 知识过时</strong></td> | ||
| + | </tr> | ||
| + | <tr> | ||
| + | <th style="text-align: left; padding: 6px 12px; background-color: #f8fafc; color: #475569; border-bottom: 1px solid #e2e8f0;">关键技术</th> | ||
| + | <td style="padding: 6px 12px; border-bottom: 1px solid #e2e8f0; color: #0f172a;">Vector Embeddings (嵌入)</td> | ||
| + | </tr> | ||
| + | <tr> | ||
| + | <th style="text-align: left; padding: 6px 12px; background-color: #f8fafc; color: #475569;">典型应用</th> | ||
| + | <td style="padding: 6px 12px; color: #1e40af;">Open Evidence, Bing Chat</td> | ||
| + | </tr> | ||
| + | </table> | ||
| + | </div> | ||
| + | </div> | ||
| + | <h2 style="background: #f1f5f9; color: #0f172a; padding: 10px 18px; border-radius: 0 6px 6px 0; font-size: 1.25em; margin-top: 40px; border-left: 6px solid #0f172a; font-weight: bold;">工作原理:三步走战略</h2> | ||
| + | |||
| + | <p style="margin: 15px 0; text-align: justify;"> | ||
| + | RAG 的运行流程可以形象地比喻为“先查资料,再写论文”。其标准流程包含三个核心阶段: | ||
| + | </p> | ||
| − | + | <div style="background-color: #f8fafc; border: 1px solid #e2e8f0; padding: 15px; border-radius: 8px; font-size: 0.95em;"> | |
| + | <ol style="margin: 0; padding-left: 20px; color: #334155;"> | ||
| + | <li style="margin-bottom: 10px;"><strong>检索 (Retrieval):</strong> 当用户提问时,系统首先将问题转化为<strong>向量 (Vector)</strong>,然后在外部知识库(向量数据库)中搜索语义最相似的文档片段。</li> | ||
| + | <li style="margin-bottom: 10px;"><strong>增强 (Augmentation):</strong> 将检索到的“事实片段”与用户的原始问题拼接在一起,构建一个包含上下文的 Prompt(提示词)。 | ||
| + | <br><span style="color: #64748b; font-size: 0.9em;"> ➤ 提示词示例:<em>"基于以下参考资料:[资料A, 资料B...],请回答用户的问题:[用户提问]"</em></span> | ||
| + | </li> | ||
| + | <li><strong>生成 (Generation):</strong> LLM 接收到这个增强后的提示词,像做阅读理解题一样生成答案,并注明引用来源。</li> | ||
| + | </ol> | ||
| + | </div> | ||
| − | == | + | <h2 style="background: #f1f5f9; color: #0f172a; padding: 10px 18px; border-radius: 0 6px 6px 0; font-size: 1.25em; margin-top: 40px; border-left: 6px solid #0f172a; font-weight: bold;">技术路线之争:RAG vs. Fine-tuning</h2> |
| − | RAG | + | |
| + | <div style="background-color: #fff7ed; border-left: 5px solid #ea580c; padding: 15px 20px; margin: 20px 0; border-radius: 4px;"> | ||
| + | <p style="margin: 0; text-align: justify; font-size: 0.95em; color: #334155;"> | ||
| + | <strong>选型指南:</strong> 如果你需要模型学习一种“新的说话风格”或“特定任务格式”,用 <strong>Fine-tuning (微调)</strong>;如果你需要模型掌握“海量的新知识”或“实时更新的事实”,必须用 <strong>RAG</strong>。 | ||
| + | </p> | ||
| + | </div> | ||
| − | <div style=" | + | <div style="overflow-x: auto; margin: 20px auto;"> |
| − | + | <table style="width: 100%; border-collapse: collapse; border: 1.2px solid #cbd5e1; font-size: 0.9em; text-align: left;"> | |
| − | + | <tr style="background-color: #f1f5f9; border-bottom: 2px solid #0f172a;"> | |
| − | + | <th style="padding: 12px; border: 1px solid #cbd5e1; color: #0f172a; width: 25%;">维度</th> | |
| − | + | <th style="padding: 12px; border: 1px solid #cbd5e1; color: #1e40af; width: 35%;">RAG (外挂知识库)</th> | |
| − | + | <th style="padding: 12px; border: 1px solid #cbd5e1; color: #475569;">Fine-tuning (微调模型)</th> | |
| − | </div> | + | </tr> |
| + | <tr> | ||
| + | <td style="padding: 10px; border: 1px solid #cbd5e1; font-weight: 600;">知识更新</td> | ||
| + | <td style="padding: 10px; border: 1px solid #cbd5e1; color: #16a34a;"><strong>实时 (Real-time)</strong><br>只需更新数据库,无需重训。</td> | ||
| + | <td style="padding: 10px; border: 1px solid #cbd5e1; color: #e11d48;"><strong>静态 (Static)</strong><br>知识固化在权重中,更新需重训。</td> | ||
| + | </tr> | ||
| + | <tr> | ||
| + | <td style="padding: 10px; border: 1px solid #cbd5e1; font-weight: 600;">可解释性</td> | ||
| + | <td style="padding: 10px; border: 1px solid #cbd5e1; color: #16a34a;"><strong>高 (Verifiable)</strong><br>可提供引用来源,便于核查。</td> | ||
| + | <td style="padding: 10px; border: 1px solid #cbd5e1;">低 (Black Box)<br>无法准确知道知识来自哪。</td> | ||
| + | </tr> | ||
| + | <tr> | ||
| + | <td style="padding: 10px; border: 1px solid #cbd5e1; font-weight: 600;">幻觉问题</td> | ||
| + | <td style="padding: 10px; border: 1px solid #cbd5e1; color: #16a34a;">大幅降低</td> | ||
| + | <td style="padding: 10px; border: 1px solid #cbd5e1;">依然存在</td> | ||
| + | </tr> | ||
| + | <tr> | ||
| + | <td style="padding: 10px; border: 1px solid #cbd5e1; font-weight: 600; background-color: #eff6ff;">成本</td> | ||
| + | <td style="padding: 10px; border: 1px solid #cbd5e1; background-color: #eff6ff;">较低 (架构搭建)</td> | ||
| + | <td style="padding: 10px; border: 1px solid #cbd5e1; background-color: #eff6ff;">较高 (算力消耗)</td> | ||
| + | </tr> | ||
| + | </table> | ||
| + | </div> | ||
| − | == | + | <h2 style="background: #f1f5f9; color: #0f172a; padding: 10px 18px; border-radius: 0 6px 6px 0; font-size: 1.25em; margin-top: 40px; border-left: 6px solid #0f172a; font-weight: bold;">生态系统:向量数据库的崛起</h2> |
| − | + | ||
| + | <div style="display: flex; flex-wrap: wrap; gap: 20px; margin: 20px 0;"> | ||
| + | <div style="flex: 1; min-width: 280px; background-color: #f0f9ff; border-left: 5px solid #1e40af; padding: 15px; border-radius: 4px;"> | ||
| + | <h3 style="margin-top: 0; color: #1e40af; font-size: 1.1em;">Vector Database (向量数据库)</h3> | ||
| + | <p style="margin-bottom: 0; text-align: justify; font-size: 0.9em; color: #334155;"> | ||
| + | RAG 的兴起直接带火了向量数据库赛道(如 Pinecone, Milvus, Chroma)。因为 RAG 的核心在于“检索”,而传统的关键词匹配(Keyword Match)无法理解语义,只有通过<strong>Embeddings (向量嵌入)</strong> 才能实现“意图理解”。 | ||
| + | </p> | ||
| + | </div> | ||
| + | </div> | ||
| − | <div style=" | + | <div style="font-size: 0.92em; line-height: 1.6; color: #1e293b; margin-top: 50px; border-top: 2px solid #0f172a; padding: 15px 25px; background-color: #f8fafc; border-radius: 0 0 10px 10px;"> |
| − | + | <span style="color: #0f172a; font-weight: bold; font-size: 1.05em; display: inline-block; margin-bottom: 15px;">学术参考文献 [Academic Review]</span> | |
| − | + | ||
| − | + | <p style="margin: 12px 0; border-bottom: 1px solid #e2e8f0; padding-bottom: 10px;"> | |
| − | + | [1] <strong>Lewis P, et al. (2020).</strong> <em>Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks.</em> <strong>[[NeurIPS]]</strong>. <br> | |
| − | + | <span style="color: #475569;">[点评]:RAG 的奠基之作。文章首次提出将参数化记忆(Generator)与非参数化记忆(Retriever)结合,刷新了多项 QA 任务的 SOTA。</span> | |
| − | + | </p> | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | </ | ||
| − | = | + | <p style="margin: 12px 0; border-bottom: 1px solid #e2e8f0; padding-bottom: 10px;"> |
| − | + | [2] <strong>Gao Y, et al. (2023).</strong> <em>Retrieval-Augmented Generation for Large Language Models: A Survey.</em> <strong>[[arXiv preprint]]</strong>. <br> | |
| − | + | <span style="color: #475569;">[点评]:全面综述了 RAG 的进化路线,包括 Naive RAG, Advanced RAG 和 Modular RAG 等变体。</span> | |
| − | + | </p> | |
| − | |||
| − | = | + | <p style="margin: 12px 0;"> |
| − | + | [3] <strong>Kandpal N, et al. (2023).</strong> <em>Large Language Models Struggle to Learn Long-Tail Knowledge.</em> <strong>[[ICML]]</strong>. <br> | |
| − | + | <span style="color: #475569;">[点评]:研究指出 LLM 很难记住长尾(罕见)知识,从理论上证明了外挂知识库(RAG)对专业领域的必要性。</span> | |
| − | + | </p> | |
| − | + | </div> | |
| − | |||
| − | + | <div style="margin: 40px 0; border: 1px solid #e2e8f0; border-radius: 8px; overflow: hidden; font-family: 'Helvetica Neue', Arial, sans-serif; font-size: 0.9em;"> | |
| + | <div style="background-color: #eff6ff; color: #1e40af; padding: 8px 15px; font-weight: bold; text-align: center; border-bottom: 1px solid #dbeafe;"> | ||
| + | AI 架构 · 知识图谱 | ||
| + | </div> | ||
| + | <table style="width: 100%; border-collapse: collapse; background-color: #ffffff;"> | ||
| + | <tr style="border-bottom: 1px solid #f1f5f9;"> | ||
| + | <td style="width: 85px; background-color: #f8fafc; color: #334155; font-weight: 600; padding: 10px 12px; text-align: right; vertical-align: middle;">核心组件</td> | ||
| + | <td style="padding: 10px 15px; color: #334155;">[[Vector Database]] (向量库) • [[Embeddings]] (嵌入) • [[Prompt Engineering]]</td> | ||
| + | </tr> | ||
| + | <tr style="border-bottom: 1px solid #f1f5f9;"> | ||
| + | <td style="width: 85px; background-color: #f8fafc; color: #334155; font-weight: 600; padding: 10px 12px; text-align: right; vertical-align: middle;">竞争路线</td> | ||
| + | <td style="padding: 10px 15px; color: #334155;">[[Fine-tuning]] (微调) • [[Long Context Window]] (长上下文)</td> | ||
| + | </tr> | ||
| + | <tr> | ||
| + | <td style="width: 85px; background-color: #f8fafc; color: #334155; font-weight: 600; padding: 10px 12px; text-align: right; vertical-align: middle;">应用实例</td> | ||
| + | <td style="padding: 10px 15px; color: #334155;">[[Open Evidence]] (医疗) • [[Perplexity]] (搜索) • [[Chat with PDF]]</td> | ||
| + | </tr> | ||
| + | </table> | ||
| + | </div> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
</div> | </div> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
2026年2月3日 (二) 07:38的最新版本
RAG(Retrieval-Augmented Generation,检索增强生成)是一种将预训练大语言模型(LLM)与外部知识检索系统相结合的混合 AI 架构。它由 Meta AI 的 Patrick Lewis 等人于 2020 年正式提出。传统的 LLM(如 ChatGPT)像是一个“闭卷考试”的学生,依靠记忆(预训练权重)作答,容易产生幻觉 (Hallucination) 且无法获取最新信息;而 RAG 则赋予了模型“开卷考试”的能力——在回答问题前,先从外部知识库(如企业文档、互联网、医学指南)中检索相关信息,作为“参考资料”喂给模型,从而生成准确、可溯源且实时的回答。目前,RAG 已成为构建垂直领域 AI 应用(如法律、医疗助手)的主流范式。
工作原理:三步走战略
RAG 的运行流程可以形象地比喻为“先查资料,再写论文”。其标准流程包含三个核心阶段:
- 检索 (Retrieval): 当用户提问时,系统首先将问题转化为向量 (Vector),然后在外部知识库(向量数据库)中搜索语义最相似的文档片段。
- 增强 (Augmentation): 将检索到的“事实片段”与用户的原始问题拼接在一起,构建一个包含上下文的 Prompt(提示词)。
➤ 提示词示例:"基于以下参考资料:[资料A, 资料B...],请回答用户的问题:[用户提问]" - 生成 (Generation): LLM 接收到这个增强后的提示词,像做阅读理解题一样生成答案,并注明引用来源。
技术路线之争:RAG vs. Fine-tuning
选型指南: 如果你需要模型学习一种“新的说话风格”或“特定任务格式”,用 Fine-tuning (微调);如果你需要模型掌握“海量的新知识”或“实时更新的事实”,必须用 RAG。
| 维度 | RAG (外挂知识库) | Fine-tuning (微调模型) |
|---|---|---|
| 知识更新 | 实时 (Real-time) 只需更新数据库,无需重训。 |
静态 (Static) 知识固化在权重中,更新需重训。 |
| 可解释性 | 高 (Verifiable) 可提供引用来源,便于核查。 |
低 (Black Box) 无法准确知道知识来自哪。 |
| 幻觉问题 | 大幅降低 | 依然存在 |
| 成本 | 较低 (架构搭建) | 较高 (算力消耗) |
生态系统:向量数据库的崛起
Vector Database (向量数据库)
RAG 的兴起直接带火了向量数据库赛道(如 Pinecone, Milvus, Chroma)。因为 RAG 的核心在于“检索”,而传统的关键词匹配(Keyword Match)无法理解语义,只有通过Embeddings (向量嵌入) 才能实现“意图理解”。
学术参考文献 [Academic Review]
[1] Lewis P, et al. (2020). Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. NeurIPS.
[点评]:RAG 的奠基之作。文章首次提出将参数化记忆(Generator)与非参数化记忆(Retriever)结合,刷新了多项 QA 任务的 SOTA。
[2] Gao Y, et al. (2023). Retrieval-Augmented Generation for Large Language Models: A Survey. arXiv preprint.
[点评]:全面综述了 RAG 的进化路线,包括 Naive RAG, Advanced RAG 和 Modular RAG 等变体。
[3] Kandpal N, et al. (2023). Large Language Models Struggle to Learn Long-Tail Knowledge. ICML.
[点评]:研究指出 LLM 很难记住长尾(罕见)知识,从理论上证明了外挂知识库(RAG)对专业领域的必要性。