rag-frameworks
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRAG Frameworks
RAG框架
Frameworks for building retrieval-augmented generation applications.
用于构建检索增强生成(RAG)应用的框架。
Comparison
对比
| Framework | Best For | Learning Curve | Flexibility |
|---|---|---|---|
| LangChain | Agents, chains, tools | Steeper | Highest |
| LlamaIndex | Data indexing, simple RAG | Gentle | Medium |
| Sentence Transformers | Custom embeddings | Low | High |
| 框架 | 最适用场景 | 学习曲线 | 灵活性 |
|---|---|---|---|
| LangChain | Agent、链、工具开发 | 较陡 | 最高 |
| LlamaIndex | 数据索引、简单RAG实现 | 平缓 | 中等 |
| Sentence Transformers | 自定义Embeddings | 低 | 高 |
LangChain
LangChain
Orchestration framework for building complex LLM applications.
Core concepts:
- Chains: Sequential operations (retrieve → prompt → generate)
- Agents: LLM decides which tools to use
- LCEL: Declarative pipeline syntax with operator
| - Retrievers: Abstract interface to vector stores
Strengths: Rich ecosystem, many integrations, agent capabilities
Limitations: Abstractions can be confusing, rapid API changes
Key concept: LCEL (LangChain Expression Language) for composable pipelines.
用于构建复杂LLM应用的编排框架。
核心概念:
- Chains(链):顺序操作(检索 → 提示 → 生成)
- Agents:由LLM决定使用哪些工具
- LCEL:使用运算符的声明式流水线语法
| - Retrievers(检索器):向量存储的抽象接口
优势:生态丰富、集成众多、具备Agent能力
局限性:抽象概念较难理解、API更新频繁
核心概念:LCEL(LangChain表达式语言)用于构建可组合的流水线。
LlamaIndex
LlamaIndex
Data framework focused on connecting LLMs to external data.
Core concepts:
- Documents → Nodes: Automatic chunking and indexing
- Index types: Vector, keyword, tree, knowledge graph
- Query engines: Retrieve and synthesize answers
- Chat engines: Stateful conversation over data
Strengths: Simple API, great for document QA, data connectors
Limitations: Less flexible for complex agent workflows
Key concept: "Load data, index it, query it" - simpler mental model than LangChain.
专注于将LLM与外部数据连接的数据框架。
核心概念:
- 文档→节点:自动分块与索引
- 索引类型:向量索引、关键词索引、树形索引、知识图谱索引
- 查询引擎:检索并合成答案
- 对话引擎:基于数据的有状态对话
优势:API简洁、适用于文档问答、具备数据连接器
局限性:在复杂Agent工作流方面灵活性不足
核心概念:“加载数据、建立索引、查询数据”——相比LangChain,心智模型更简单。
Sentence Transformers
Sentence Transformers
Generate high-quality embeddings for semantic similarity.
Popular models:
| Model | Dimensions | Quality | Speed |
|---|---|---|---|
| all-MiniLM-L6-v2 | 384 | Good | Fast |
| all-mpnet-base-v2 | 768 | Better | Medium |
| e5-large-v2 | 1024 | Best | Slow |
Key concept: Bi-encoder architecture - encode query and documents separately, compare with cosine similarity.
用于生成高质量Embeddings以实现语义相似度计算。
热门模型:
| 模型 | 维度 | 质量 | 速度 |
|---|---|---|---|
| all-MiniLM-L6-v2 | 384 | 良好 | 快 |
| all-mpnet-base-v2 | 768 | 更好 | 中等 |
| e5-large-v2 | 1024 | 最佳 | 慢 |
核心概念:双编码器架构——分别编码查询与文档,通过余弦相似度进行比较。
RAG Architecture Patterns
RAG架构模式
| Pattern | Description | When to Use |
|---|---|---|
| Naive RAG | Retrieve top-k, stuff in prompt | Simple QA |
| Parent-Child | Retrieve chunks, return parent docs | Context preservation |
| Hybrid Search | Vector + keyword search | Better recall |
| Re-ranking | Retrieve many, re-rank with cross-encoder | Higher precision |
| Query Expansion | Generate variations of query | Ambiguous queries |
| 模式 | 描述 | 适用场景 |
|---|---|---|
| 基础RAG | 检索Top-K结果,填入提示词 | 简单问答 |
| 父-子文档 | 检索片段,返回父文档 | 上下文保留 |
| 混合搜索 | 向量+关键词搜索 | 更好的召回率 |
| 重排序 | 检索大量结果,使用交叉编码器重排序 | 更高的精度 |
| 查询扩展 | 生成查询的变体 | 模糊查询 |
Decision Guide
决策指南
| Scenario | Recommendation |
|---|---|
| Simple document QA | LlamaIndex |
| Complex agents/tools | LangChain |
| Custom embedding pipeline | Sentence Transformers |
| Production RAG | LangChain or custom |
| Quick prototype | LlamaIndex |
| Maximum control | Build custom with Sentence Transformers |
| 场景 | 推荐方案 |
|---|---|
| 简单文档问答 | LlamaIndex |
| 复杂Agent/工具 | LangChain |
| 自定义Embeddings流水线 | Sentence Transformers |
| 生产级RAG | LangChain或自定义实现 |
| 快速原型开发 | LlamaIndex |
| 最大控制权 | 基于Sentence Transformers自定义构建 |
Resources
资源
- LangChain: https://python.langchain.com
- LlamaIndex: https://docs.llamaindex.ai
- Sentence Transformers: https://sbert.net
- LangChain: https://python.langchain.com
- LlamaIndex: https://docs.llamaindex.ai
- Sentence Transformers: https://sbert.net