Skip to content

gaopengbin/simple-rag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple RAG — 双版本知识库系统

基于 FastAPI + Celery + Redis + Chroma + Ollama 实现的 RAG(检索增强生成)系统,提供原版和 LangChain 版两套后端实现,前端共用。

📦 项目结构

simple-rag/
├── backend/          # 原版后端(FastAPI :8000,手写实现)
├── backend-lc/       # LangChain 版后端(FastAPI :8001,LangChain + LangSmith)
├── frontend/         # React + shadcn/ui 前端(Nginx :3000 / :3001)
└── docker-compose.yml

🔑 两版本对比

维度 原版 backend LangChain 版 backend-lc
端口 8000 8001
分块 固定窗口(500字/50重叠) RecursiveCharacterTextSplitter
Embedding requests 调 Ollama OllamaEmbeddings(区分 query/doc)
向量库 chromadb 原生 langchain-chroma 封装
LLM 调用 requests 拼 Prompt LCEL:PromptTemplate | ChatOllama | StrOutputParser
可观测 日志 LangSmith 追踪
前端接口 4 个端点 完全兼容,零改动

🚀 快速启动

前提

  • 安装并运行 Ollama
  • 拉取模型:ollama pull nomic-embed-text && ollama pull qwen2.5:7b

Docker 一键启动(推荐)

# 启动所有服务(两版本同时运行)
docker compose up -d

# 只启动 LangChain 版
docker compose up -d redis backend-lc celery-lc frontend-lc
服务 地址
原版前端 http://localhost:3000
LangChain 版前端 http://localhost:3001
原版 API 文档 http://localhost:8000/docs
LangChain 版 API 文档 http://localhost:8001/docs

LangSmith 配置(可选)

cp backend-lc/.env.example backend-lc/.env
# 编辑 backend-lc/.env,填入 LANGCHAIN_API_KEY
docker compose up -d --build backend-lc celery-lc

⚙️ Redis 端口分配

db 用途
0 原版 Celery broker
1 原版 Celery backend
2 原版业务缓存
3 LangChain 版 Celery broker
4 LangChain 版 Celery backend
5 LangChain 版业务缓存

🛠 本地开发

# 原版后端
cd backend && pip install -r requirements.txt
python -m uvicorn main:app --reload --port 8000

# LangChain 版后端
cd backend-lc && pip install -r requirements.txt
uvicorn main:app --reload --port 8001

# 前端
cd frontend && npm install && npm run dev

About

RAG knowledge base system with dual backends: original implementation + LangChain+LangSmith version. FastAPI + Celery + Redis + Chroma + Ollama + React.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors