Files
nexus/wiki/concepts/Generation.md

55 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Generation"
type: concept
tags: [RAG, LLM, 问答生成]
sources: [rag从入门到精通系列1-基础rag]
last_updated: 2025-01-16
---
## Definition
Generation生成阶段是 RAG 管道的第三阶段,将用户问题与检索到的相关文档块组合成 Prompt输入 LLM 生成带事实依据的答案。
## Core Process
```
问题 + Top-k 文档块 → PromptTemplate 组装 → LLM 生成 → 返回答案
```
1. **组装上下文**将问题Question和检索到的文档块Context放入预定义的字典结构
2. **Prompt 模板**:通过 PromptTemplate 将问题+上下文组合成完整的 Prompt String
3. **LLM 生成**:将 Prompt 输入 LLMLLM 基于检索到的知识生成回答
4. **可选链式组合**:使用 LangChain/LlamaIndex 的 Chain 将 Retrieval 和 Generation 串联为统一管道
## Key Prompt Pattern
```
你是一个问答助手。请根据以下参考资料回答用户问题。
如果参考资料中没有相关信息,请如实说明。
参考资料:
{context}
用户问题:{question}
回答:
```
## LangChain Chain
LangChain 和 LlamaIndex 提供了 `RetrievalQA Chain` 等开箱即用的链,可将检索和生成过程自动化串联,避免手动拼装 Prompt。
## Connections
- [[Generation]] ← part_of ← [[RAG]]
- [[Generation]] ← receives_input ← [[Retrieval]]
- [[Generation]] ← uses ← [[Large-Language-Model]]
- [[Generation]] ← uses ← [[Prompt]]
## Aliases
- Answer Generation
- RAG Generation
- LLM Response Generation
- 答案生成