# EcqaLangchainRAG **Repository Path**: skyfen/ecqalangchain ## Basic Information - **Project Name**: EcqaLangchainRAG - **Description**: VibeCoding编写LangChain RAG 电商知识库平台 应用ChromaDB向量库,AI大模型Langchain,RAG,LLM,Agent,Skills落地了的 电商知识库平台。 闭环全链路:用户提问 → 查询重写(HyDE) → 多路召回 → 重排序 → 上下文压缩 → LLM生成 → 流式输出。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-13 - **Last Updated**: 2026-08-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 📚 RAG 知识库问答系统 基于 **LangChain** 框架开发的企业级 RAG(检索增强生成)知识库问答系统,面向电商商品知识库场景。 ## 功能特性 - ✅ **知识库管理** — 支持 PDF/Word/Excel/TXT/Markdown/CSV 文档上传,自动解析索引 - ✅ **智能问答** — 基于 LangChain RAG Pipeline:查询重写 → 多路召回(向量+BM25) → RRF 融合 → 重排序 → 流式生成 - ✅ **多用户多会话** — 用户独立会话管理,历史记录持久化 - ✅ **来源引用** — 每个回答附带知识库引用片段,可追溯来源 - ✅ **用户系统** — 注册/登录/JWT认证/角色权限 - ✅ **反馈机制** — 👍/👎 评价回答质量 - ✅ **对话导出** — 导出会话为 Markdown 文件 - ✅ **系统监控** — 用户数/文档数/问答量/好评率 Dashboard - ✅ **流式输出** — SSE 逐字流式渲染,低延迟体验 ## 技术栈 | 层级 | 技术 | |------|------| | 后端框架 | Python 3.11+ / FastAPI | | RAG 框架 | LangChain + LangGraph | | LLM | 阿里云百炼 — 通义千问 Qwen-Max | | Embedding | 阿里云百炼 — text-embedding-v3 | | Reranker | 阿里云百炼 — gte-rerank | | 向量数据库 | ChromaDB (持久化模式) | | 关系数据库 | SQLite + SQLAlchemy 2.0 (async) | | 缓存 | cachetools (内存) + diskcache (磁盘) | | 前端 | React 18 + TypeScript + Ant Design 5 | ## 快速启动 ### 前置依赖 - **Python 3.11+** — [python.org](https://www.python.org/downloads/) - **Node.js 18+** — [nodejs.org](https://nodejs.org/) - **阿里云百炼 API Key** — [bailian.console.aliyun.com](https://bailian.console.aliyun.com/) 免费注册获取 ### 1. 启动后端 ```powershell cd backend python -m venv venv venv\Scripts\activate pip install -r requirements.txt copy .env.example .env # 编辑 .env 文件,填入你的 DASHSCOPE_API_KEY python run.py ``` 后端启动在 `http://localhost:8000`,API 文档在 `http://localhost:8000/docs` ### 2. 启动前端 ```powershell cd frontend npm install npm run dev ``` 前端启动在 `http://localhost:5173` ### 3. 开始使用 1. 浏览器访问 `http://localhost:5173` 2. 使用管理员账号 `admin / 123456` 登录 3. 进入「知识库管理」上传文档 4. 返回「知识库问答」开始提问 ## 预设账号 | 角色 | 用户名 | 密码 | |------|--------|------| | 管理员 | admin | 123456 | | 普通用户 | 自行注册 | — | ## 项目结构 ``` LangChainRAG/ ├── backend/ # Python 后端 │ ├── app/ │ │ ├── main.py # FastAPI 入口 │ │ ├── config.py # 配置管理 │ │ ├── api/v1/ # API 路由 │ │ ├── core/ # JWT + 权限 │ │ ├── models/ # SQLAlchemy ORM │ │ ├── schemas/ # Pydantic Schema │ │ ├── services/ # 业务逻辑 │ │ ├── rag/ # LangChain RAG 引擎 │ │ └── utils/ # 日志/缓存/异常 │ ├── data/ # 运行时数据 (gitignore) │ ├── tests/ # 测试 │ └── requirements.txt ├── frontend/ # React 前端 │ ├── src/ │ │ ├── pages/ # 页面组件 │ │ ├── components/ # 通用组件 │ │ ├── hooks/ # 自定义 hooks │ │ ├── services/ # API 封装 │ │ ├── store/ # Zustand 状态 │ │ └── types/ # TS 类型 │ └── package.json ├── .env.example └── README.md ``` ## API 端点 | 方法 | 路径 | 说明 | |------|------|------| | POST | `/api/v1/auth/register` | 注册 | | POST | `/api/v1/auth/login` | 登录 | | POST | `/api/v1/auth/refresh` | 刷新 Token | | PUT | `/api/v1/auth/password` | 修改密码 | | GET | `/api/v1/conversations` | 会话列表 | | POST | `/api/v1/conversations` | 新建会话 | | DELETE | `/api/v1/conversations/{id}` | 删除会话 | | POST | `/api/v1/chat/{id}` | 问答 (SSE流式) | | GET | `/api/v1/chat/{id}/messages` | 历史消息 | | POST | `/api/v1/chat/messages/{id}/feedback` | 反馈 | | GET | `/api/v1/chat/{id}/export` | 导出为 MD | | POST | `/api/v1/admin/knowledge/upload` | 上传文档 | | GET | `/api/v1/admin/knowledge/documents` | 文档列表 | | DELETE | `/api/v1/admin/knowledge/{id}` | 删除文档 | | POST | `/api/v1/admin/knowledge/preview` | 检索预览 | | GET | `/api/v1/admin/dashboard/stats` | 系统统计 | | GET | `/api/v1/health` | 健康检查 |