Commit ebd93514b3cbb722dbb0a4f5b7c7490ffce0b417
1 parent
a998168b
【功能新增】AI:新增 document 向量的进度查询
Showing
8 changed files
with
73 additions
and
8 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeSegmentController.http
| ... | ... | @@ -2,4 +2,11 @@ |
| 2 | 2 | GET {{baseUrl}}/ai/knowledge/segment/split?url=https://static.iocoder.cn/README_yudao.md&segmentMaxTokens=800 |
| 3 | 3 | Content-Type: application/json |
| 4 | 4 | Authorization: Bearer {{token}} |
| 5 | -tenant-id: {{adminTenantId}} | |
| 6 | 5 | \ No newline at end of file |
| 6 | +tenant-id: {{adminTenantId}} | |
| 7 | + | |
| 8 | +### 获取文档处理列表 | |
| 9 | +GET {{baseUrl}}/ai/knowledge/segment/get-process-list?documentIds=1,2,3 | |
| 10 | +Content-Type: application/json | |
| 11 | +Authorization: Bearer {{token}} | |
| 12 | +tenant-id: {{adminTenantId}} | |
| 13 | + | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeSegmentController.java
| ... | ... | @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowle |
| 7 | 7 | import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentRespVO; |
| 8 | 8 | import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentUpdateReqVO; |
| 9 | 9 | import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentUpdateStatusReqVO; |
| 10 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentProcessRespVO; | |
| 10 | 11 | import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeSegmentDO; |
| 11 | 12 | import cn.iocoder.yudao.module.ai.service.knowledge.AiKnowledgeSegmentService; |
| 12 | 13 | import io.swagger.v3.oas.annotations.Operation; |
| ... | ... | @@ -69,4 +70,13 @@ public class AiKnowledgeSegmentController { |
| 69 | 70 | return success(BeanUtils.toBean(segments, AiKnowledgeSegmentRespVO.class)); |
| 70 | 71 | } |
| 71 | 72 | |
| 73 | + @GetMapping("/get-process-list") | |
| 74 | + @Operation(summary = "获取文档处理列表") | |
| 75 | + @Parameter(name = "documentIds", description = "文档编号列表", required = true, example = "1,2,3") | |
| 76 | + public CommonResult<List<AiKnowledgeSegmentProcessRespVO>> getKnowledgeSegmentProcessList( | |
| 77 | + @RequestParam("documentIds") List<Long> documentIds) { | |
| 78 | + List<AiKnowledgeSegmentProcessRespVO> list = segmentService.getKnowledgeSegmentProcessList(documentIds); | |
| 79 | + return success(list); | |
| 80 | + } | |
| 81 | + | |
| 72 | 82 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/segment/AiKnowledgeSegmentProcessRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +@Schema(description = "管理后台 - AI 知识库段落向量进度 Response VO") | |
| 7 | +@Data | |
| 8 | +public class AiKnowledgeSegmentProcessRespVO { | |
| 9 | + | |
| 10 | + @Schema(description = "文档编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 11 | + private Long documentId; | |
| 12 | + | |
| 13 | + @Schema(description = "总段落数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") | |
| 14 | + private Long count; | |
| 15 | + | |
| 16 | + @Schema(description = "已向量化段落数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") | |
| 17 | + private Long embeddingCount; | |
| 18 | + | |
| 19 | +} | |
| 0 | 20 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/segment/AiKnowledgeSegmentUpdateReqVO.java
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/knowledge/AiKnowledgeSegmentMapper.java
| ... | ... | @@ -3,11 +3,15 @@ package cn.iocoder.yudao.module.ai.dal.mysql.knowledge; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX; | |
| 6 | 7 | import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentPageReqVO; |
| 8 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentProcessRespVO; | |
| 7 | 9 | import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeSegmentDO; |
| 10 | +import com.github.yulichang.wrapper.MPJLambdaWrapper; | |
| 8 | 11 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 12 | |
| 10 | 13 | import java.util.List; |
| 14 | +import java.util.Collection; | |
| 11 | 15 | |
| 12 | 16 | /** |
| 13 | 17 | * AI 知识库分片 Mapper |
| ... | ... | @@ -37,4 +41,15 @@ public interface AiKnowledgeSegmentMapper extends BaseMapperX<AiKnowledgeSegment |
| 37 | 41 | .orderByDesc(AiKnowledgeSegmentDO::getId)); |
| 38 | 42 | } |
| 39 | 43 | |
| 44 | + default List<AiKnowledgeSegmentProcessRespVO> selectProcessList(Collection<Long> documentIds) { | |
| 45 | + MPJLambdaWrapper<AiKnowledgeSegmentDO> wrapper = new MPJLambdaWrapperX<AiKnowledgeSegmentDO>() | |
| 46 | + .selectAs(AiKnowledgeSegmentDO::getDocumentId, AiKnowledgeSegmentProcessRespVO::getDocumentId) | |
| 47 | + .selectCount(AiKnowledgeSegmentDO::getId, "count") | |
| 48 | + .select("COUNT(CASE WHEN vector_id > '" + AiKnowledgeSegmentDO.VECTOR_ID_EMPTY | |
| 49 | + + "' THEN 1 ELSE NULL END) AS embeddingCount") | |
| 50 | + .in(AiKnowledgeSegmentDO::getDocumentId, documentIds) | |
| 51 | + .groupBy(AiKnowledgeSegmentDO::getDocumentId); | |
| 52 | + return selectJoinList(AiKnowledgeSegmentProcessRespVO.class, wrapper); | |
| 53 | + } | |
| 54 | + | |
| 40 | 55 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeDocumentServiceImpl.java
| ... | ... | @@ -67,8 +67,8 @@ public class AiKnowledgeDocumentServiceImpl implements AiKnowledgeDocumentServic |
| 67 | 67 | .setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 68 | 68 | knowledgeDocumentMapper.insert(documentDO); |
| 69 | 69 | |
| 70 | - // 4. 文档切片入库(同步) | |
| 71 | - knowledgeSegmentService.createKnowledgeSegmentBySplitContent(documentDO.getId(), content); | |
| 70 | + // 4. 文档切片入库(异步) | |
| 71 | + knowledgeSegmentService.createKnowledgeSegmentBySplitContentAsync(documentDO.getId(), content); | |
| 72 | 72 | return documentDO.getId(); |
| 73 | 73 | } |
| 74 | 74 | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeSegmentService.java
| ... | ... | @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowle |
| 5 | 5 | import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentSearchReqVO; |
| 6 | 6 | import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentUpdateReqVO; |
| 7 | 7 | import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentUpdateStatusReqVO; |
| 8 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentProcessRespVO; | |
| 8 | 9 | import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeSegmentDO; |
| 9 | 10 | import org.springframework.scheduling.annotation.Async; |
| 10 | 11 | |
| ... | ... | @@ -82,4 +83,12 @@ public interface AiKnowledgeSegmentService { |
| 82 | 83 | */ |
| 83 | 84 | List<AiKnowledgeSegmentDO> splitContent(String url, Integer segmentMaxTokens); |
| 84 | 85 | |
| 86 | + /** | |
| 87 | + * 获取文档处理进度(多个) | |
| 88 | + * | |
| 89 | + * @param documentIds 文档编号列表 | |
| 90 | + * @return 文档处理列表 | |
| 91 | + */ | |
| 92 | + List<AiKnowledgeSegmentProcessRespVO> getKnowledgeSegmentProcessList(List<Long> documentIds); | |
| 93 | + | |
| 85 | 94 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeSegmentServiceImpl.java
| ... | ... | @@ -6,10 +6,7 @@ import cn.hutool.core.util.StrUtil; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | 8 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 9 | -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentPageReqVO; | |
| 10 | -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentSearchReqVO; | |
| 11 | -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentUpdateReqVO; | |
| 12 | -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentUpdateStatusReqVO; | |
| 9 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.segment.*; | |
| 13 | 10 | import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDO; |
| 14 | 11 | import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDocumentDO; |
| 15 | 12 | import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeSegmentDO; |
| ... | ... | @@ -252,4 +249,12 @@ public class AiKnowledgeSegmentServiceImpl implements AiKnowledgeSegmentService |
| 252 | 249 | .build(); |
| 253 | 250 | } |
| 254 | 251 | |
| 252 | + @Override | |
| 253 | + public List<AiKnowledgeSegmentProcessRespVO> getKnowledgeSegmentProcessList(List<Long> documentIds) { | |
| 254 | + if (CollUtil.isEmpty(documentIds)) { | |
| 255 | + return Collections.emptyList(); | |
| 256 | + } | |
| 257 | + return segmentMapper.selectProcessList(documentIds); | |
| 258 | + } | |
| 259 | + | |
| 255 | 260 | } | ... | ... |