40 lines
2.2 KiB
Markdown
40 lines
2.2 KiB
Markdown
---
|
||
title: "LangChain"
|
||
type: entity
|
||
tags: [llm, framework, python, rag, ai]
|
||
last_updated: 2025-01-16
|
||
---
|
||
|
||
## Definition
|
||
LangChain 是一个用于构建 LLM 应用的 Python/JavaScript 框架,提供模块化组件抽象(Document Loader、Text Splitter、Embedding、Vector Store、Retriever、Chain、PromptTemplate 等),大幅简化 RAG、Agent 等 LLM 应用的开发。
|
||
|
||
## Type
|
||
- **Category**: AI Framework / 开发框架
|
||
- **Website**: python.langchain.com
|
||
- **Language**: Python, JavaScript/TypeScript
|
||
|
||
## Core Components
|
||
1. **Document Loader**:从 160+ 不同来源(网页/PDF/Notion/Slack 等)加载文档
|
||
2. **Text Splitter**:将长文档切分为满足 Embedding Context Window 的小片段(Split)
|
||
3. **Embedding**:集成多种 Embedding Provider(BAAI/BGE、OpenAI、Cohere 等)
|
||
4. **Vector Store**:集成多种向量数据库(Qdrant、Pinecone、Chroma、FAISS 等)
|
||
5. **Retriever**:基于向量相似度的文档检索接口
|
||
6. **Chain**:将多个步骤串联执行的抽象,最关键的是 RAG Chain(RetrievalQA Chain)
|
||
7. **PromptTemplate**:将变量、上下文、用户问题组装为 LLM 输入 Prompt 的模板引擎
|
||
8. **Memory**:为 Agent 提供对话历史记忆能力
|
||
|
||
## Key Value
|
||
- **降低 RAG 开发门槛**:将 Indexing-Retrieval-Generation 三阶段封装为可复用的组件,开发者无需从零实现向量化和相似度检索
|
||
- **Chain 抽象**:通过 LCEL(LangChain Expression Language)声明式组合各组件,支持 RAG Chain、Conversation Chain 等开箱即用模式
|
||
- **工具生态**:与 LangSmith(监控)、LangServe(部署)构成完整应用生命周期支持
|
||
|
||
## In RAG Context
|
||
- [[rag从入门到精通系列1-基础rag]] 中作为核心工具链组件,负责 Indexing 阶段的文档加载/切分/向量化入库,以及 Retrieval + Generation 阶段的 Chain 编排
|
||
|
||
## Related Concepts
|
||
- [[RAG]] — LangChain 的核心应用场景
|
||
- [[Indexing]] — LangChain 封装的关键阶段
|
||
- [[Retrieval]] — LangChain 的 Retriever 组件
|
||
- [[Generation]] — LangChain 的 Chain + PromptTemplate 组件
|
||
- [[LlamaIndex]] — 同类竞品框架,各有侧重
|