Files
SuperBizAgent-java/openspec/changes/phase-1-infrastructure/tasks.md
T
zhuyongxin 4ef8d87961 feat(phase1): 实现文档分块向量化索引
Task 5.6: 向量化索引实现
- VectorIndexService 新增方法:
  - indexDocumentChunks(docId, chunks): 索引文档分块到 Milvus
  - deleteDocumentChunks(docId): 删除文档的所有向量
  - buildDocumentMetadata(): 构建文档元数据(区分文件索引)

核心流程:
1. 上传时:文本提取 → 分块 → 向量化 → 存入 Milvus + MySQL
2. 检索时:问题向量化 → Milvus 语义检索 → 返回相似文档
3. 删除时:删除元数据 + 删除向量索引

实现细节:
- 复用 indexSingleFile 的向量化逻辑
- metadata.docId 标识文档来源(区分 upload: 和 file:)
- 删除表达式:metadata["docId"] == "xxx"
- 自动去重:上传前删除旧向量数据

DocumentManagementService 完整实现:
- uploadDocument: 完整向量化流程(移除 TODO)
- deleteDocument: 同步删除向量索引(移除 TODO)

编译验证:BUILD SUCCESS

Progress: 32/34 tasks completed (94%)
2026-06-23 16:08:50 +08:00

54 lines
2.5 KiB
Markdown

# Phase 1 Infrastructure - Tasks
## 1. 数据库与依赖
- [x] 1.1 添加依赖到 pom.xml (spring-boot-starter-data-jpa, mysql-connector-j, flyway-core, spring-boot-starter-data-redis)
- [x] 1.2 创建 Flyway 迁移脚本 V001__create_diagnosis_record.sql
- [x] 1.3 创建 Flyway 迁移脚本 V002__create_case_library.sql
- [x] 1.4 创建 Flyway 迁移脚本 V003__create_api_document.sql
- [x] 1.5 配置 MySQL + Redis + Flyway (application.yml)
## 2. JPA 实体与 Repository
- [x] 2.1 创建 JPA 实体类 DiagnosisRecord
- [x] 2.2 创建 JPA 实体类 CaseLibrary
- [x] 2.3 创建 JPA 实体类 ApiDocument
- [x] 2.4 创建 DiagnosisRecordRepository 接口
- [x] 2.5 创建 CaseLibraryRepository 接口
- [x] 2.6 创建 ApiDocumentRepository 接口
- [x] 2.7 Repository 单元测试 (DiagnosisRecordRepositoryTest)
- [x] 2.8 Repository 单元测试 (CaseLibraryRepositoryTest)
- [x] 2.9 Repository 单元测试 (ApiDocumentRepositoryTest)
## 3. 会话管理
- [x] 3.1 创建 SessionManager 接口
- [x] 3.2 创建 SessionContext 数据类
- [x] 3.3 创建 ToolCall 数据类
- [x] 3.4 创建 RedisSessionManager 实现
- [x] 3.5 创建 SessionConfiguration 配置类
- [x] 3.6 Redis 会话管理单元测试 (RedisSessionManagerTest)
## 4. 代码结构重构
- [x] 4.1 包名重构 (org.example → com.superbiz.agent)
- [x] 4.2 分层结构优化 (controller/service/repository/domain/tool/config/exception)
- [x] 4.3 创建 DTO 类 (DiagnosisRequest, DiagnosisResponse, DocumentUploadRequest, DocumentQueryResponse, Result)
## 5. 文档管理服务
- [x] 5.1 创建 TextExtractor 服务 (仅支持 .md 和 .txt,其他格式通过外部转换服务)
- [x] 5.2 文档分块服务 (DocumentChunkService 已存在,已适配新 DTO)
- [x] 5.3 文档上传接口 (DocumentController#upload, DocumentManagementService#uploadDocument)
- [x] 5.4 文档查询接口 (DocumentController#query, DocumentService#queryDocuments)
- [x] 5.5 文档删除接口 (DocumentController#delete, DocumentService#deleteDocument)
- [x] 5.6 向量化索引 (VectorIndexService#indexDocumentChunks, 实现分块级别索引)
- [ ] 5.7 混合检索工具 (DocumentSearchTool: 精确匹配 + 语义检索 + RRF 融合)
- [ ] 5.8 文档管理集成测试 (DocumentIntegrationTest)
## 6. 全局完善
- [x] 6.1 统一异常处理 (GlobalExceptionHandler, SessionNotFoundException, DocumentProcessException)
- [x] 6.2 Docker Compose 配置 (MySQL + Redis + Milvus)
- [x] 6.3 更新 README.md (Phase 1 安装说明与本地开发指南)