# 0226_deepresearch **Repository Path**: rickey96/0226_deepresearch ## Basic Information - **Project Name**: 0226_deepresearch - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 5 - **Created**: 2026-07-30 - **Last Updated**: 2026-08-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Deep Research 教学项目 本项目用于教学演示多智能体研究报告生成流程,重点覆盖 DeepAgents、文件系统上下文管理、任务拆分、Celery 异步任务、MongoDB 持久化和确定性 HTML 渲染。 ## 1. 本地依赖 - Python 3.12+ - Docker - Docker Compose - 可用的大模型 API Key - 可选:Tavily API Key - 可选:RAGFlow 服务和有效 API Key ## 2. 选择基础设施启动模式 仓库中有两套 Compose: | Compose 文件 | 服务 | 用途 | | --- | --- | --- | | 根目录 `docker-compose.yml` | MongoDB、Redis | DeepResearch 持久化和 Celery broker | | `ragflow-docker/docker-compose.yml` | RAGFlow、MySQL、Elasticsearch、MinIO、Redis、TEI | 本地 RAGFlow 知识库 | 两套 Compose 默认都会把 Redis 发布到宿主机的 `6379`,因此不能同时启动两个 Redis。请根据是否启用 RAGFlow,在下面两种模式中选择一种,不要混用启动命令。 首次配置时复制环境变量模板: ```bash cp .env.example .env ``` ### 模式 A:不使用 RAGFlow 在根目录 `.env` 中关闭 RAGFlow: ```env ENABLE_RAGFLOW=false MONGODB_URI=mongodb://deepresearch:deepresearch_dev@localhost:27017/deep_research?authSource=deep_research MONGODB_DATABASE=deep_research REDIS_URL=redis://:infini_rag_flow@localhost:6379/0 CELERY_BROKER_URL=redis://:infini_rag_flow@localhost:6379/0 ``` `RAGFLOW_BASE_URL`、`RAGFLOW_API_KEY` 和 `RAGFLOW_DEFAULT_DATASET_IDS` 可以不配置。 如果此前启动过 RAGFlow,先停止它以释放 `6379`: ```bash docker compose -f ragflow-docker/docker-compose.yml stop ``` 然后启动根目录 Compose 中的 MongoDB 和 Redis: ```bash docker compose up -d mongo redis docker compose ps ``` 此模式下: - `deep-research-mongo` 使用 `27017`。 - `deep-research-redis` 使用 `6379`,作为 Celery broker。 - DeepResearch 不注册 `ragflow_search` 工具,也不会请求 RAGFlow。 ### 模式 B:使用 RAGFlow 在根目录 `.env` 中启用并配置 RAGFlow: ```env ENABLE_RAGFLOW=true RAGFLOW_BASE_URL=http://localhost:9380 RAGFLOW_API_KEY=ragflow-xxxxxxxxxxxxxxxxxxxxxxxx RAGFLOW_DEFAULT_DATASET_IDS=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx MONGODB_URI=mongodb://deepresearch:deepresearch_dev@localhost:27017/deep_research?authSource=deep_research MONGODB_DATABASE=deep_research REDIS_URL=redis://:infini_rag_flow@localhost:6379/0 CELERY_BROKER_URL=redis://:infini_rag_flow@localhost:6379/0 ``` 配置值说明: - `RAGFLOW_API_KEY`:登录 RAGFlow 后,在 API Key 管理页面创建。 - `RAGFLOW_DEFAULT_DATASET_IDS`:需要检索的知识库 ID;多个 ID 用英文逗号分隔。 - `RAGFLOW_BASE_URL`:当前本地 Compose 的 API 地址是 `http://localhost:9380`。 使用 RAGFlow 时,由 RAGFlow Compose 提供宿主机 `6379` 上的 Redis。DeepResearch 使用 Redis DB 0,RAGFlow 内部使用 DB 1,两者数据隔离。两边 Redis 密码必须一致; 当前默认密码都是 `infini_rag_flow`。 如果根目录的 Redis 正在运行,先停止它: ```bash docker compose stop redis ``` 启动完整 RAGFlow,再只启动 DeepResearch 的 MongoDB。不要再次启动根目录的 `redis` 服务: ```bash docker compose -f ragflow-docker/docker-compose.yml up -d docker compose up -d mongo ./ragflow-docker/classroom-check.sh ``` RAGFlow Web 地址是 `http://127.0.0.1/`,API 版本接口是 `http://127.0.0.1:9380/api/v1/system/version`。 #### 根据显卡选择 TEI 镜像 在 `ragflow-docker/.env` 中通过 `TEI_IMAGE_BLACKWELL` 设置 TEI 镜像。这个变量名 是当前部署文件的历史命名;即使使用的不是 Blackwell 显卡,也需要修改这个变量。 当前教学机器是 RTX 5070 Ti(Blackwell、SM 120),已经验证可用: ```env TEI_IMAGE_BLACKWELL=hotchpotch/tei-blackwell-testing ``` 这是为 RTX 50 系列构建的第三方测试镜像,不应在其他架构显卡上使用。新部署也可以 选择 Hugging Face 官方的 SM 120 镜像: ```env TEI_IMAGE_BLACKWELL=ghcr.io/huggingface/text-embeddings-inference:120-1.9 ``` 非 RTX 50 显卡没有一个通用镜像,必须按 GPU 架构选择: | GPU 架构/示例 | 计算能力 | `TEI_IMAGE_BLACKWELL` | | --- | --- | --- | | Turing:T4、RTX 20 系列 | SM 75 | `ghcr.io/huggingface/text-embeddings-inference:turing-1.9` | | Ampere:A100、A30 | SM 80 | `ghcr.io/huggingface/text-embeddings-inference:1.9` | | Ampere:A10、A40、RTX 30 系列 | SM 86 | `ghcr.io/huggingface/text-embeddings-inference:86-1.9` | | Ada Lovelace:RTX 40 系列 | SM 89 | `ghcr.io/huggingface/text-embeddings-inference:89-1.9` | | Hopper:H100 | SM 90 | `ghcr.io/huggingface/text-embeddings-inference:hopper-1.9` | | Blackwell:B200、GB200 | SM 100 | `ghcr.io/huggingface/text-embeddings-inference:100-1.9` | | Blackwell:RTX 50 系列 | SM 120 | `ghcr.io/huggingface/text-embeddings-inference:120-1.9` | | Blackwell:DGX Spark GB10 | SM 121 | `ghcr.io/huggingface/text-embeddings-inference:121-1.9` | 计算能力低于 7.5 的 NVIDIA GPU 不在当前 TEI 官方支持范围内。镜像选择以 [Hugging Face TEI 官方镜像表](https://github.com/huggingface/text-embeddings-inference#docker-images) 为准。修改镜像后重新创建 TEI: ```bash docker compose -f ragflow-docker/docker-compose.yml up -d --force-recreate tei curl -i http://127.0.0.1:6380/health ``` 更完整的 RAGFlow 启停和排障方法见 [ragflow-docker/README.md](ragflow-docker/README.md)。 ### 已有同名容器时 如果 `docker compose up` 提示 `deep-research-mongo` 或 `deep-research-redis` 容器名 已被占用,先检查现有容器: ```bash docker ps -a --filter name=deep-research-mongo docker ps -a --filter name=deep-research-redis ``` 容器已经正常运行时不需要重复创建。历史容器没有 Compose 标签时,根目录 `docker compose ps` 可能看不到它们,但仍会占用容器名和端口;应先确认其中的数据, 再决定复用还是迁移,不要直接删除持久化容器。 ### MongoDB 初始化账号 MongoDB 首次启动时会执行 [mongo/init-mongo.js](mongo/init-mongo.js),创建应用数据库用户: ```text database: deep_research username: deepresearch password: deepresearch_dev ``` ## 3. 配置大模型和搜索服务 无论是否启用 RAGFlow,都需要配置报告生成使用的大模型。Tavily 是可选的外部搜索: ```env LLM_PROVIDER=deepseek LLM_MODEL_NAME=deepseek-chat DEEPSEEK_API_BASE=https://api.deepseek.com DEEPSEEK_API_KEY=sk-xxxx TAVILY_API_KEY=tvly-xxxx ``` ## 4. 启动应用 启动 FastAPI: ```bash .venv/bin/python -m uvicorn app.main:app --host 127.0.0.1 --port 8000 ``` 启动 Celery worker: ```bash .venv/bin/celery -A app.celery_app:celery_app worker -l INFO -P solo ``` 访问地址: ```text http://127.0.0.1:8000 http://127.0.0.1:8000/api/v1/docs ``` 健康检查: ```bash curl http://127.0.0.1:8000/health ``` ## 5. 验证 运行静态检查和测试: ```bash .venv/bin/python -m ruff check app tests .venv/bin/python -m pytest -q .venv/bin/python -m compileall -q app tests ``` 完整端到端流程: ```text 创建研究项目 -> 等待 brief/outline 任务完成 -> 获取大纲 -> 确认大纲 -> 提交报告生成任务 -> 等待报告任务完成 -> 获取 latest report ``` 核心接口: | 接口 | 方法 | 作用 | | --- | --- | --- | | `/health` | `GET` | 健康检查 | | `/api/v1/research-projects` | `POST` | 创建研究项目 | | `/api/v1/tasks/{task_id}` | `GET` | 查询任务状态 | | `/api/v1/research-projects/{project_id}/outline` | `GET` | 获取大纲 | | `/api/v1/research-projects/{project_id}/outline` | `PUT` | 确认或修改大纲 | | `/api/v1/research-projects/{project_id}/report-tasks` | `POST` | 生成研究报告 | | `/api/v1/research-projects/{project_id}/report-render-tasks` | `POST` | 基于已有章节重新渲染报告 | | `/api/v1/research-projects/{project_id}/reports/latest` | `GET` | 获取最新报告 |