Files
nexus/wiki/concepts/RAG.md
2026-04-15 15:02:52 +08:00

44 lines
1.8 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: "RAG"
type: concept
tags: [rag, llm, retrieval-augmented-generation]
sources: ["RAG从入门到精通系列1基础RAG", "LLMs、RAG、AI Agent 三个到底什么区别?"]
last_updated: 2026-04-15
---
## Definition
Retrieval Augmented Generation检索增强生成一种将 LLM 与外部数据源(私有数据或最新数据)连接的通用方法。通过先检索后生成的模式,让 LLM 的回答有时事实依据。
## Architecture
三阶段管道:
1. **Indexing索引**:文档加载→文本切分→向量化→存入向量数据库
2. **Retrieval检索**:问题向量化→按相似度检索 Top-k 知识片段
3. **Generation生成**:问题+知识片段→PromptTemplate→LLM 生成答案
## Key Components
| 组件 | 作用 | 示例工具 |
|------|------|---------|
| Document Loader | 加载外部文档 | LangChain 160+ 加载器 |
| Text Splitter | 切分文档为 Split | RecursiveCharacterTextSplitter |
| Embedding Model | 文本→向量 | BAAI BGE 系列 |
| Vector Store | 存储+相似度检索 | Qdrant、Pinecone、Chroma |
| LLM | 答案生成 | GPT-4、Claude、Qwen |
## Technical Details
- Embedding Model Context Window 通常 512~8192 token需将长文档切分成满足长度限制的 Split
- 相似度衡量方法:余弦相似度、点积、欧氏距离等
- Retriever 可通过 LangChain 的 Retriever 接口统一抽象
## Related Concepts
- [[LLM]]RAG 的生成层载体
- [[Embedding]]RAG 的核心技术,将文本转为数值表示
- [[向量数据库]]RAG 的存储层
- [[AI知识库]]RAG 的上层应用形态
- [[Indexing]]RAG 第一阶段
- [[Retrieval]]RAG 第二阶段
- [[Generation]]RAG 第三阶段
## Sources
- [[RAG从入门到精通系列1基础RAG]]
- [[LLMs、RAG、AI Agent 三个到底什么区别?]]