rag-frameworks

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

RAG Frameworks

RAG框架

Frameworks for building retrieval-augmented generation applications.
用于构建检索增强生成(RAG)应用的框架。

Comparison

对比

FrameworkBest ForLearning CurveFlexibility
LangChainAgents, chains, toolsSteeperHighest
LlamaIndexData indexing, simple RAGGentleMedium
Sentence TransformersCustom embeddingsLowHigh

框架最适用场景学习曲线灵活性
LangChainAgent、链、工具开发较陡最高
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:
ModelDimensionsQualitySpeed
all-MiniLM-L6-v2384GoodFast
all-mpnet-base-v2768BetterMedium
e5-large-v21024BestSlow
Key concept: Bi-encoder architecture - encode query and documents separately, compare with cosine similarity.

用于生成高质量Embeddings以实现语义相似度计算。
热门模型:
模型维度质量速度
all-MiniLM-L6-v2384良好
all-mpnet-base-v2768更好中等
e5-large-v21024最佳
核心概念:双编码器架构——分别编码查询与文档,通过余弦相似度进行比较。

RAG Architecture Patterns

RAG架构模式

PatternDescriptionWhen to Use
Naive RAGRetrieve top-k, stuff in promptSimple QA
Parent-ChildRetrieve chunks, return parent docsContext preservation
Hybrid SearchVector + keyword searchBetter recall
Re-rankingRetrieve many, re-rank with cross-encoderHigher precision
Query ExpansionGenerate variations of queryAmbiguous queries

模式描述适用场景
基础RAG检索Top-K结果,填入提示词简单问答
父-子文档检索片段,返回父文档上下文保留
混合搜索向量+关键词搜索更好的召回率
重排序检索大量结果,使用交叉编码器重排序更高的精度
查询扩展生成查询的变体模糊查询

Decision Guide

决策指南

ScenarioRecommendation
Simple document QALlamaIndex
Complex agents/toolsLangChain
Custom embedding pipelineSentence Transformers
Production RAGLangChain or custom
Quick prototypeLlamaIndex
Maximum controlBuild custom with Sentence Transformers
场景推荐方案
简单文档问答LlamaIndex
复杂Agent/工具LangChain
自定义Embeddings流水线Sentence Transformers
生产级RAGLangChain或自定义实现
快速原型开发LlamaIndex
最大控制权基于Sentence Transformers自定义构建

Resources

资源