# multimodal-rag-platform **Repository Path**: legend993/multimodal-rag-platform ## Basic Information - **Project Name**: multimodal-rag-platform - **Description**: multimodal-rag-platform:企业文档多模态 RAG 平台:MinerU 解析 PDF/Word/图片 → 百炼 Embedding 向量化 → Milvus 语义检索 → 通义千问生成答案,Gradio 交互式问答界面。 - **Primary Language**: Python - **License**: MulanPSL-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2026-08-26 - **Last Updated**: 2026-10-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: RAG ## README # 企业文档多模态 RAG 平台 基于 MinerU + 百炼 AI + Milvus Lite + Gradio 的本地优先多模态 RAG 系统,支持企业文档(PDF/Word/图片)的智能问答。 ## 功能特性 - 📄 **文档解析**:基于 MinerU 引擎,支持 PDF、DOCX、PNG、JPG 格式,提取文本、表格和图片 - 🔢 **向量化索引**:百炼 text-embedding-v3 文本向量化,qwen3.7-plus 图片描述生成,Milvus Lite 本地存储 - 🔍 **语义检索**:基于 1024 维向量的语义搜索,支持按文档和内容类型过滤 - 🤖 **智能问答**:百炼通义千问 LLM 生成答案,附带来源引用,拒绝编造 - 🌐 **Web 界面**:Gradio Tab 式布局(文档上传 / 智能问答 / 知识库管理) ## 系统架构 ``` ┌─────────────────────────────────────────────────────┐ │ Gradio Web UI │ │ 📤 上传 │ 🔍 问答 │ 📊 知识库 │ └────────────────────────┬────────────────────────────┘ │ ┌────────────────────────▼────────────────────────────┐ │ RAG Pipeline │ │ 查询 → 检索 → 上下文拼接 → LLM 生成 → 答案+来源 │ └──────┬──────────────────────────────────┬───────────┘ │ │ ┌──────▼──────────┐ ┌───────▼───────────┐ │ Milvus Lite │ │ 百炼 API Cloud │ │ 向量存储 │◄─────────────│ • Embedding v3 │ │ (本地 SQLite) │ │ • VL qwen3.7-plus │ └──────▲──────────┘ │ • LLM 通义千问 │ │ └───────────────────┘ ┌──────┴──────────┐ │ MinerU 引擎 │ │ 文档解析 │ │ (PDF/Word/图片) │ └─────────────────┘ ``` ## 环境要求 - **操作系统**:macOS(Apple M4 推荐) - **内存**:16GB 统一内存 - **Python**:3.10+ - **MinerU**:需单独安装(`pip install mineru`,2.x 起命令行更名为 `mineru`) ## 快速开始 ### 1. 克隆项目 ```bash cd multimodal-rag-platform ``` ### 2. 安装依赖 ```bash pip install -r requirements.txt # 安装 MinerU(文档解析引擎,可选,requirements.txt 已包含) # pip install mineru==2.6.8 mineru_vl_utils==0.1.19 ``` ### 3. 配置环境变量 ```bash cp .env.example .env # 编辑 .env 文件,填入百炼 API Key # OPENAI_API_KEY=your-bailian-api-key ``` 在[阿里云百炼平台](https://bailian.console.aliyun.com/) 获取 API Key。 ### 4. 启动应用 ```bash python main.py ``` 访问 http://localhost:7860 ## 使用流程 1. **上传文档**:在「文档上传」Tab 上传 PDF/Word/图片,系统自动解析并建立索引 2. **智能问答**:在「智能问答」Tab 输入问题,系统基于知识库生成答案 3. **管理知识库**:在「知识库管理」Tab 查看/删除已索引的文档 ## 项目结构 ``` multimodal-rag-platform/ ├── main.py # 应用入口 ├── config.py # 全局配置(Pydantic Settings) ├── requirements.txt # 依赖清单 ├── .env.example # 环境变量模板 ├── README.md ├── src/ │ ├── parser/ # 文档解析模块 │ │ ├── mineru.py # MinerU CLI 封装 │ │ └── chunker.py # 解析结果结构化 │ ├── embedder/ # 向量化模块 │ │ ├── embedding.py # 百炼 text-embedding-v3 │ │ └── vl.py # 百炼 VL 图片描述 │ ├── store/ # 向量存储模块 │ │ ├── milvus.py # Milvus Lite 封装 │ │ └── indexer.py # 索引编排管线 │ ├── retriever/ # 检索与生成模块 │ │ ├── search.py # 语义检索服务 │ │ ├── prompt.py # 上下文拼接与 Prompt │ │ ├── llm.py # 百炼 LLM 封装 │ │ └── pipeline.py # 完整 RAG 管线 │ └── ui/ # Gradio 界面 │ ├── app.py # 应用入口 │ └── tabs/ # Tab 页面 ├── data/ # 数据目录 │ ├── parsed/ # MinerU 解析输出 │ ├── milvus.db # Milvus 向量数据库 │ └── test_docs/ # 测试文档集 └── tests/ # 测试 ├── test_parser.py ├── test_store.py ├── test_retriever.py └── test_e2e.py ``` ## 运行测试 ```bash # 单元测试 pytest tests/test_parser.py tests/test_store.py tests/test_retriever.py -v # 端到端测试(需要 MinerU 和百炼 API 环境) RUN_E2E_TESTS=1 pytest tests/test_e2e.py -v ``` ## 配置说明 | 环境变量 | 说明 | 默认值 | |---------|------|--------| | `OPENAI_API_KEY` | 百炼 API Key | - | | `OPENAI_BASE_URL` | 百炼 Base URL | `https://dashscope.aliyuncs.com/compatible-mode/v1` | | `EMBEDDING_MODEL` | Embedding 模型 | `text-embedding-v3` | | `VL_MODEL` | VL 图片描述模型 | `qwen3.7-plus` | | `LLM_MODEL` | LLM 生成模型 | `qwen3.7-max-preview` | | `MINERU_MODEL_SOURCE` | MinerU 模型来源 | `modelscope` | | `MILVUS_DB_PATH` | 向量库路径 | `data/milvus.db` | | `RETRIEVAL_TOP_K` | 检索返回数 | `5` | | `MAX_CONTEXT_TOKENS` | 上下文最大 Token | `4000` | ## 技术栈 - **文档解析**:[MinerU](https://github.com/opendatalab/MinerU) (mineru CLI) - **向量化**:[百炼 DashScope](https://bailian.console.aliyun.com/) text-embedding-v3 - **图片理解**:百炼 qwen3.7-plus(多模态) - **LLM**:百炼通义千问(OpenAI 兼容协议) - **向量数据库**:[Milvus Lite](https://milvus.io/) (pymilvus 嵌入式模式) - **Web UI**:[Gradio](https://www.gradio.app/) - **配置管理**:Pydantic Settings + python-dotenv ## License Mulan Permissive Software License v2