Commit ea3ad5c828c048ddd3712e74eae5e41894a9a98c

Authored by YunaiV
1 parent 0be9af4d

✨ feat(ai):补齐 AI 知识库段落删除接口 DELETE /ai/knowledge/segment/delete,对齐前端 KnowledgeSeg…

…mentApi.deleteKnowledgeSegment 调用
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeSegmentController.java
@@ -83,6 +83,15 @@ public class AiKnowledgeSegmentController { @@ -83,6 +83,15 @@ public class AiKnowledgeSegmentController {
83 return success(true); 83 return success(true);
84 } 84 }
85 85
  86 + @DeleteMapping("/delete")
  87 + @Operation(summary = "删除段落")
  88 + @Parameter(name = "id", description = "段落编号", required = true, example = "1024")
  89 + @PreAuthorize("@ss.hasPermission('ai:knowledge:delete')")
  90 + public CommonResult<Boolean> deleteKnowledgeSegment(@RequestParam("id") Long id) {
  91 + segmentService.deleteKnowledgeSegment(id);
  92 + return success(true);
  93 + }
  94 +
86 @GetMapping("/split") 95 @GetMapping("/split")
87 @Operation(summary = "切片内容") 96 @Operation(summary = "切片内容")
88 @Parameters({ 97 @Parameters({
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeSegmentService.java
@@ -99,6 +99,13 @@ public interface AiKnowledgeSegmentService { @@ -99,6 +99,13 @@ public interface AiKnowledgeSegmentService {
99 void updateKnowledgeSegmentStatus(AiKnowledgeSegmentUpdateStatusReqVO reqVO); 99 void updateKnowledgeSegmentStatus(AiKnowledgeSegmentUpdateStatusReqVO reqVO);
100 100
101 /** 101 /**
  102 + * 删除知识库段落
  103 + *
  104 + * @param id 段落编号
  105 + */
  106 + void deleteKnowledgeSegment(Long id);
  107 +
  108 + /**
102 * 重新索引知识库下的所有文档段落 109 * 重新索引知识库下的所有文档段落
103 * 110 *
104 * @param knowledgeId 知识库编号 111 * @param knowledgeId 知识库编号
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeSegmentServiceImpl.java
@@ -142,6 +142,19 @@ public class AiKnowledgeSegmentServiceImpl implements AiKnowledgeSegmentService @@ -142,6 +142,19 @@ public class AiKnowledgeSegmentServiceImpl implements AiKnowledgeSegmentService
142 } 142 }
143 143
144 @Override 144 @Override
  145 + public void deleteKnowledgeSegment(Long id) {
  146 + // 1. 校验段落存在
  147 + AiKnowledgeSegmentDO segment = validateKnowledgeSegmentExists(id);
  148 +
  149 + // 2. 删除向量
  150 + VectorStore vectorStore = getVectorStoreById(segment.getKnowledgeId());
  151 + deleteVectorStore(vectorStore, segment);
  152 +
  153 + // 3. 删除段落记录
  154 + segmentMapper.deleteById(id);
  155 + }
  156 +
  157 + @Override
145 public void deleteKnowledgeSegmentByDocumentId(Long documentId) { 158 public void deleteKnowledgeSegmentByDocumentId(Long documentId) {
146 // 1. 查询需要删除的段落 159 // 1. 查询需要删除的段落
147 List<AiKnowledgeSegmentDO> segments = segmentMapper.selectListByDocumentId(documentId); 160 List<AiKnowledgeSegmentDO> segments = segmentMapper.selectListByDocumentId(documentId);