huangjia2019/rag-in-action
About
End-to-end RAG system design, evaluation, and optimization. A Geek Time RAG training camp covering the comprehensive breakdown of RAG’s 10 major components and four hands-on projects to master the entire RAG workflow. Putting RAG into practice usually means building RAG for business needs, not building business around RAG. That is why different scenarios and problems require targeted adjustments, optimization, and customization. The devil is in the details, so we explore them in depth.
AI & Machine LearningMeasured star growth
- in 24h
- 0
- in 7 days
- +2
- in 15 days
- +5
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalRAG (Retrieval-Augmented Generation) 系统研发实战
本项目是一个基于 DeepSeek 的 RAG 系统实战课程的代码仓库,实现了一个完整的检索增强生成系统。
课程地址:RAG系统研发实战
技术框架


配套书籍《RAG实战课》已经重磅出版!(人民邮电出版社)
项目架构
项目采用模块化设计,每个模块负责 RAG 系统的不同方面:
| 模块 | 功能 | 技术栈 | 依赖 |
|---|---|---|---|
00-简单RAG-SimpleRAG |
基础 RAG 系统实现 | LangChain/LlamaIndex | 基础环境 |
01-数据导入-DataLoading |
数据加载和预处理 | pandas, PyPDF2 | 文档解析库 |
02-文本切块-DocChunking |
文档分块策略 | LangChain Splitters | NLP 工具 |
03-向量嵌入-Embedding |
文本向量化 | HuggingFace, BGE | GPU 支持(可选) |
04-向量存储-VectorDB |
向量数据库操作 | Milvus, Chroma | 向量数据库 |
05-检索前处理-PreRetrieval |
检索优化 | Query Expansion | NLP 工具 |
06-索引优化-Indexing |
索引构建和优化 | 层次索引, 关键词索引 | 搜索引擎 |
07-检索后处理-PostRetrieval |
检索结果优化 | 重排序, 过滤 | ML 模型 |
08-响应生成-Generation |
答案生成 | LLM 集成 | GPU 推荐 |
09-系统评估-Evaluation |
系统性能评估 | RAGAS, TruLens | 评估框架 |
10-高级RAG-AdvanceRAG |
高级 RAG 技术实现 | Graph RAG, Multi-Agent | 高级框架 |
环境要求
硬件要求
GPU 版本
- NVIDIA GPU (建议 >= 8GB 显存)
- CUDA 11.8 或更高版本
- cuDNN 8.0 或更高版本
CPU 版本
- 建议 >= 16GB RAM
- 多核处理器(建议 >= 4 核)
软件要求
操作系统支持
- **Ubuntu **
- 推荐使用 22.04 LTS
MacOS (Intel/Apple Silicon)
- Apple Silicon 可以使用 MPS 加速
Windows 10/11
- 推荐使用 WSL2 + Ubuntu
框架选择
Python:3.10+
LangChain 框架
- 基础版:
requirements_langchain_简单RAG(后续模块还要安装其它包).txt - 完整版(GPU):
requirements_langchain_20250413(Ubuntu-with-GPU).txt - 完整版(CPU):
requirements_langchain_无GPU版(Mac,Win).txt
- 基础版:
LlamaIndex 框架
- 基础版:
requirements_llamaindex_简单RAG(后续模块还要安装其它包).txt - 完整版(GPU):
requirements_llamaindex_20250413(Ubuntu-with-GPU).txt - 完整版(CPU):
requirements_llamaindex_无GPU版(Mac,Win).txt
- 基础版:
环境配置
Ubuntu (GPU 版本+LangChain框架)
# 创建虚拟环境
python -m venv venv-rag-langchain
source venv-rag-langchain/bin/activate
## 或者使用conda
conda create -n venv-rag-langchain python=3.10.12
conda activate venv-rag-langchain
# 安装依赖
pip install -r 91-环境-Environment/requirements_langchain_20250413_Ubuntu-with-GPU.txt
Ubuntu (CPU 版本+LangChain框架)
# 创建虚拟环境
python -m venv venv-rag-langchain
source venv-rag-langchain/bin/activate
## 或者使用conda
conda create -n venv-rag-langchain python=3.10.12
conda activate venv-rag-langchain
# 安装依赖
pip install -r 91-环境-Environment/requirements_langchain_Ubuntu-with-CPU.txt
MacOS/Windows(CPU 版本+LangChain框架)
# 创建虚拟环境
python -m venv venv-rag-langchain
# Windows
.\venv-rag-langchain\Scripts\activate
# MacOS
source venv-rag-langchain/bin/activate
## 或者使用conda
conda create -n venv-rag-langchain python=3.10.12
conda activate venv-rag-langchain
# 安装依赖
pip install -r 91-环境-Environment/requirements_langchain_无GPU版_Mac-Win.txt
Ubuntu (GPU 版本+LlamaIndex框架)
# 创建虚拟环境
python -m venv venv-rag-llamaindex
source venv-rag-llamaindex/bin/activate
## 或者使用conda
conda create -n venv-rag-llamaindex python=3.10.12
conda activate venv-rag-lanllamaindexgchain
# 安装依赖
pip install -r 91-环境-Environment/requirements_llamaindex_20250413_Ubuntu-with-GPU.txt
Ubuntu (CPU 版本+LlamaIndex框架)
# 创建虚拟环境
python -m venv venv-rag-llamaindex
source venv-rag-llamaindex/bin/activate
## 或者使用conda
conda create -n venv-rag-llamaindex python=3.10.12
conda activate venv-rag-llamaindex
# 安装依赖
pip install -r 91-环境-Environment/requirements_llamaindex_Ubuntu-with-CPU.txt
MacOS/Windows(CPU 版本+LlamaIndex框架)
# 创建虚拟环境
python -m venv venv-rag-llamaindex
# Windows
.\venv-rag-llamaindex\Scripts\activate
# MacOS
source venv-rag-llamaindex/bin/activate
## 或者使用conda
conda create -n venv-rag-llamaindex python=3.10.12
conda activate venv-rag-llamaindex
# 安装依赖
pip install -r 91-环境-Environment/requirements_llamaindex_无GPU版_Mac-Win.txt
特殊依赖说明
PDF 处理相关:
- 使用
requirements_camelot_20250413.txt安装 PDF 处理相关依赖 - 可能需要额外安装系统级依赖:
- Ubuntu:
sudo apt-get install ghostscript python3-tk - MacOS:
brew install ghostscript tcl-tk - Windows: 需要手动安装 Ghostscript
- Ubuntu:
- 使用
标注工具相关:
- 使用
requirements_marker_20250413.txt安装标注工具相关依赖
- 使用
使用说明
- 选择合适的环境配置文件并安装依赖
- 按照模块顺序逐步学习和实践
- 每个模块都包含独立的示例和说明文档
- 建议先从
00-简单RAG-SimpleRAG开始,逐步深入
注意事项
- GPU 版本需要确保 CUDA 环境配置正确
- 不同操作系统可能需要额外的系统级依赖
- 建议使用虚拟环境管理依赖
- 部分模块可能需要额外的模型下载或 API 密钥配置
常见问题
- CUDA 相关错误:检查 NVIDIA 驱动和 CUDA 版本是否匹配
- 内存不足:调整批处理大小或使用 CPU 版本
- 依赖冲突:使用虚拟环境并严格按照 requirements 文件安装
贡献指南
欢迎提交 Issue 和 Pull Request 来帮助改进项目。
许可证
本项目采用 MIT 许可证。
Explore related projects
Loading…