feat(phase1): 支持上传时指定文档类别
功能增强: - DocumentController 新增 category 参数 POST /api/documents/upload?category=api - DocumentUploadRequest 新增 category 字段 - 支持用户指定:api、domain、troubleshoot 等 - 默认值:upload(未指定时) - VectorIndexService.indexDocumentChunks 接收 category - 将用户指定的类别存入 Milvus metadata - metadata.category = 用户指定值 或 "upload" 使用示例: ```bash # 上传 API 文档 curl -X POST /api/documents/upload \ -F "file=@redis-api.md" \ -F "category=api" # 上传领域知识文档 curl -X POST /api/documents/upload \ -F "file=@cache-theory.md" \ -F "category=domain" # 检索时按类别过滤 searchSimilarDocuments("Redis接口", 5, "api") ``` 完整流程: 1. 文件索引:自动从路径提取(aiops-docs/api/ → "api") 2. 用户上传:从接口参数获取(category=api) 3. 检索时:可按类别过滤(category 参数) 编译验证:BUILD SUCCESS
This commit is contained in:
@@ -110,11 +110,15 @@ public class DocumentManagementService {
|
||||
|
||||
// 6. 向量化并索引
|
||||
try {
|
||||
vectorIndexService.indexDocumentChunks(docId, chunks);
|
||||
String category = request.getCategory();
|
||||
if (category == null || category.isBlank()) {
|
||||
category = "upload"; // 默认类别
|
||||
}
|
||||
vectorIndexService.indexDocumentChunks(docId, chunks, category);
|
||||
document.setStatus("INDEXED");
|
||||
document.setIndexedAt(LocalDateTime.now());
|
||||
apiDocumentRepository.save(document);
|
||||
log.info("文档索引完成,docId: {}", docId);
|
||||
log.info("文档索引完成,docId: {}, 类别: {}", docId, category);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("文档索引失败,docId: {}", docId, e);
|
||||
|
||||
Reference in New Issue
Block a user