Commit e5cc9d2ad857939a42a8ddabd37c9c445981d734

Authored by YunaiV
1 parent 7918ba7d

【代码优化】AI:知识库的索引过程

Showing 19 changed files with 149 additions and 47 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeController.java
... ... @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnow
9 9 import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDO;
10 10 import cn.iocoder.yudao.module.ai.service.knowledge.AiKnowledgeService;
11 11 import io.swagger.v3.oas.annotations.Operation;
  12 +import io.swagger.v3.oas.annotations.Parameter;
12 13 import io.swagger.v3.oas.annotations.tags.Tag;
13 14 import jakarta.annotation.Resource;
14 15 import jakarta.validation.Valid;
... ... @@ -17,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
17 18  
18 19 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
19 20  
  21 +// TODO @芋艿:增加权限标识
20 22 @Tag(name = "管理后台 - AI 知识库")
21 23 @RestController
22 24 @RequestMapping("/ai/knowledge")
... ... @@ -29,11 +31,19 @@ public class AiKnowledgeController {
29 31 @GetMapping("/page")
30 32 @Operation(summary = "获取知识库分页")
31 33 public CommonResult<PageResult<AiKnowledgeRespVO>> getKnowledgePage(@Valid AiKnowledgePageReqVO pageReqVO) {
32   -
  34 +
33 35 PageResult<AiKnowledgeDO> pageResult = knowledgeService.getKnowledgePage(pageReqVO);
34 36 return success(BeanUtils.toBean(pageResult, AiKnowledgeRespVO.class));
35 37 }
36 38  
  39 + @GetMapping("/get")
  40 + @Operation(summary = "获得知识库")
  41 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  42 + public CommonResult<AiKnowledgeRespVO> getKnowledge(@RequestParam("id") Long id) {
  43 + AiKnowledgeDO knowledge = knowledgeService.getKnowledge(id);
  44 + return success(BeanUtils.toBean(knowledge, AiKnowledgeRespVO.class));
  45 + }
  46 +
37 47 @PostMapping("/create")
38 48 @Operation(summary = "创建知识库")
39 49 public CommonResult<Long> createKnowledge(@RequestBody @Valid AiKnowledgeSaveReqVO createReqVO) {
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeDocumentController.java
... ... @@ -6,7 +6,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 6 import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentPageReqVO;
7 7 import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentRespVO;
8 8 import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentUpdateReqVO;
9   -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeDocumentCreateListReqVO;
  9 +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentCreateListReqVO;
10 10 import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeDocumentCreateReqVO;
11 11 import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDocumentDO;
12 12 import cn.iocoder.yudao.module.ai.service.knowledge.AiKnowledgeDocumentService;
... ... @@ -21,6 +21,7 @@ import java.util.List;
21 21  
22 22 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
23 23  
  24 +// TODO @芋艿:增加权限标识
24 25 @Tag(name = "管理后台 - AI 知识库文档")
25 26 @RestController
26 27 @RequestMapping("/ai/knowledge/document")
... ... @@ -38,6 +39,13 @@ public class AiKnowledgeDocumentController {
38 39 return success(BeanUtils.toBean(pageResult, AiKnowledgeDocumentRespVO.class));
39 40 }
40 41  
  42 + @GetMapping("/get")
  43 + @Operation(summary = "获取文档详情")
  44 + public CommonResult<AiKnowledgeDocumentRespVO> getKnowledgeDocument(@RequestParam("id") Long id) {
  45 + AiKnowledgeDocumentDO document = documentService.getKnowledgeDocument(id);
  46 + return success(BeanUtils.toBean(document, AiKnowledgeDocumentRespVO.class));
  47 + }
  48 +
41 49 @PostMapping("/create")
42 50 @Operation(summary = "新建文档")
43 51 public CommonResult<Long> createKnowledgeDocument(@RequestBody @Valid AiKnowledgeDocumentCreateReqVO reqVO) {
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeSegmentController.java
... ... @@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
18 18  
19 19 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
20 20  
  21 +// TODO @芋艿:增加权限标识
21 22 @Tag(name = "管理后台 - AI 知识库段落")
22 23 @RestController
23 24 @RequestMapping("/ai/knowledge/segment")
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/knowledge/AiKnowledgeDocumentCreateListReqVO.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/document/AiKnowledgeDocumentCreateListReqVO.java
1   -package cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge;
  1 +package cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import jakarta.validation.constraints.NotBlank;
... ... @@ -17,6 +17,10 @@ public class AiKnowledgeDocumentCreateListReqVO {
17 17 @NotNull(message = "知识库编号不能为空")
18 18 private Long knowledgeId;
19 19  
  20 + @Schema(description = "分段的最大 Token 数", requiredMode = Schema.RequiredMode.REQUIRED, example = "800")
  21 + @NotNull(message = "分段的最大 Token 数不能为空")
  22 + private Integer segmentMaxTokens;
  23 +
20 24 @Schema(description = "文档列表", requiredMode = Schema.RequiredMode.REQUIRED)
21 25 @NotEmpty(message = "文档列表不能为空")
22 26 private List<Document> list;
... ... @@ -33,10 +37,6 @@ public class AiKnowledgeDocumentCreateListReqVO {
33 37 @URL(message = "文档 URL 格式不正确")
34 38 private String url;
35 39  
36   - @Schema(description = "分段的最大 Token 数", requiredMode = Schema.RequiredMode.REQUIRED, example = "800")
37   - @NotNull(message = "分段的最大 Token 数不能为空")
38   - private Integer segmentMaxTokens;
39   -
40 40 }
41 41  
42 42 }
43 43 \ 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/document/AiKnowledgeDocumentPageReqVO.java
... ... @@ -8,6 +8,9 @@ import lombok.Data;
8 8 @Data
9 9 public class AiKnowledgeDocumentPageReqVO extends PageParam {
10 10  
  11 + @Schema(description = "知识库编号", example = "1")
  12 + private Long knowledgeId;
  13 +
11 14 @Schema(description = "文档名称", example = "Java 开发手册")
12 15 private String name;
13 16  
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/document/AiKnowledgeDocumentRespVO.java
1 1 package cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document;
2 2  
3   -import cn.iocoder.yudao.framework.common.pojo.PageParam;
4 3 import io.swagger.v3.oas.annotations.media.Schema;
5 4 import lombok.Data;
6 5  
7   -@Schema(description = "管理后台 - AI 知识库-文档 Response VO")
  6 +import java.time.LocalDateTime;
  7 +
  8 +@Schema(description = "管理后台 - AI 知识库文档 Response VO")
8 9 @Data
9   -public class AiKnowledgeDocumentRespVO extends PageParam {
  10 +public class AiKnowledgeDocumentRespVO {
10 11  
11   - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24790")
  12 + @Schema(description = "文档编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24790")
12 13 private Long id;
13 14  
14 15 @Schema(description = "知识库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24790")
15 16 private Long knowledgeId;
16 17  
17   - @Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "Java 开发手册")
  18 + @Schema(description = "文档名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "Java 开发手册")
18 19 private String name;
19 20  
20   - @Schema(description = "内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "Java 是一门面向对象的语言.....")
  21 + @Schema(description = "文档 URL", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://doc.iocoder.cn")
  22 + private String url;
  23 +
  24 + @Schema(description = "文档内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "Java 是一门面向对象的语言.....")
21 25 private String content;
22 26  
23   - @Schema(description = "文档 url", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://doc.iocoder.cn")
24   - private String url;
  27 + @Schema(description = "文档内容长度", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
  28 + private Integer contentLength;
25 29  
26   - @Schema(description = "token 数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
  30 + @Schema(description = "文档 Token 数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
27 31 private Integer tokens;
28 32  
29   - @Schema(description = "字符数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1008")
30   - private Integer wordCount;
  33 + @Schema(description = "分片最大 Token 数", requiredMode = Schema.RequiredMode.REQUIRED, example = "512")
  34 + private Integer segmentMaxTokens;
31 35  
32   - @Schema(description = "切片状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
33   - private Integer sliceStatus;
  36 + @Schema(description = "召回次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
  37 + private Integer retrievalCount;
34 38  
35   - @Schema(description = "文档状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  39 + @Schema(description = "文档状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
36 40 private Integer status;
37 41  
  42 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  43 + private LocalDateTime createTime;
  44 +
38 45 }
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/document/AiKnowledgeDocumentUpdateReqVO.java
... ... @@ -6,8 +6,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
6 6 import jakarta.validation.constraints.NotNull;
7 7 import lombok.Data;
8 8  
9   -
10   -@Schema(description = "管理后台 - AI 更新 知识库-文档 Request VO")
  9 +// TODO @芋艿:稍后优化
  10 +@Schema(description = "管理后台 - AI 知识库文档更新 Request VO")
11 11 @Data
12 12 public class AiKnowledgeDocumentUpdateReqVO {
13 13  
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/knowledge/AiKnowledgePageReqVO.java
1 1 package cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge;
2 2  
  3 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
3 4 import cn.iocoder.yudao.framework.common.pojo.PageParam;
  5 +import cn.iocoder.yudao.framework.common.validation.InEnum;
4 6 import io.swagger.v3.oas.annotations.media.Schema;
5 7 import lombok.Data;
  8 +import org.springframework.format.annotation.DateTimeFormat;
  9 +
  10 +import java.time.LocalDateTime;
  11 +
  12 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
6 13  
7 14 @Schema(description = "管理后台 - AI 知识库的分页 Request VO")
8 15 @Data
9 16 public class AiKnowledgePageReqVO extends PageParam {
10 17  
11   - @Schema(description = "知识库名称", example = "Java 开发手册")
  18 + @Schema(description = "知识库名称", example = "芋艿")
12 19 private String name;
13 20  
  21 + @Schema(description = "是否启用", example = "1")
  22 + @InEnum(CommonStatusEnum.class)
  23 + private Integer status;
  24 +
  25 + @Schema(description = "创建时间")
  26 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  27 + private LocalDateTime[] createTime;
  28 +
14 29 }
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/knowledge/AiKnowledgeRespVO.java
... ... @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge;
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import lombok.Data;
5 5  
  6 +import java.time.LocalDateTime;
6 7  
7 8 @Schema(description = "管理后台 - AI 知识库 Response VO")
8 9 @Data
... ... @@ -17,10 +18,22 @@ public class AiKnowledgeRespVO {
17 18 @Schema(description = "知识库描述", example = "帮助你快速构建系统")
18 19 private String description;
19 20  
20   - @Schema(description = "模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "14")
21   - private Long modelId;
  21 + @Schema(description = "向量模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "14")
  22 + private Long embeddingModelId;
22 23  
23   - @Schema(description = "模型标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "qwen-72b-chat")
24   - private String model;
  24 + @Schema(description = "向量模型标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "qwen-72b-chat")
  25 + private String embeddingModel;
  26 +
  27 + @Schema(description = "topK", requiredMode = Schema.RequiredMode.REQUIRED, example = "3")
  28 + private Integer topK;
  29 +
  30 + @Schema(description = "相似度阈值", requiredMode = Schema.RequiredMode.REQUIRED, example = "0.7")
  31 + private Double similarityThreshold;
  32 +
  33 + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  34 + private Integer status;
  35 +
  36 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  37 + private LocalDateTime createTime;
25 38  
26 39 }
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/knowledge/AiKnowledgeSaveReqVO.java
1 1 package cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge;
2 2  
  3 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  4 +import cn.iocoder.yudao.framework.common.validation.InEnum;
3 5 import io.swagger.v3.oas.annotations.media.Schema;
4 6 import jakarta.validation.constraints.NotBlank;
5 7 import jakarta.validation.constraints.NotNull;
... ... @@ -31,6 +33,9 @@ public class AiKnowledgeSaveReqVO {
31 33 @NotNull(message = "相似性阈值不能为空")
32 34 private Double similarityThreshold;
33 35  
34   - // TODO @芋艿:status
  36 + @Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  37 + @NotNull(message = "是否启用不能为空")
  38 + @InEnum(CommonStatusEnum.class)
  39 + private Integer status;
35 40  
36 41 }
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/knowledge/AiKnowledgeDocumentDO.java
... ... @@ -29,7 +29,7 @@ public class AiKnowledgeDocumentDO extends BaseDO {
29 29 */
30 30 private Long knowledgeId;
31 31 /**
32   - * 文件名称
  32 + * 文档名称
33 33 */
34 34 private String name;
35 35 /**
... ... @@ -50,11 +50,16 @@ public class AiKnowledgeDocumentDO extends BaseDO {
50 50 */
51 51 private Integer tokens;
52 52 /**
53   - * 每个文本块的目标 token 数
  53 + * 分片最大 Token 数
54 54 */
55 55 private Integer segmentMaxTokens;
56 56  
57 57 /**
  58 + * 召回次数
  59 + */
  60 + private Integer retrievalCount;
  61 +
  62 + /**
58 63 * 状态
59 64 * <p>
60 65 * 枚举 {@link CommonStatusEnum}
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/knowledge/AiKnowledgeSegmentDO.java
... ... @@ -58,6 +58,11 @@ public class AiKnowledgeSegmentDO extends BaseDO {
58 58 private Integer tokens;
59 59  
60 60 /**
  61 + * 召回次数
  62 + */
  63 + private Integer retrievalCount;
  64 +
  65 + /**
61 66 * 状态
62 67 * <p>
63 68 * 枚举 {@link CommonStatusEnum}
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/knowledge/AiKnowledgeDocumentMapper.java
... ... @@ -8,7 +8,7 @@ import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDocumentDO
8 8 import org.apache.ibatis.annotations.Mapper;
9 9  
10 10 /**
11   - * AI 知识库-文档 Mapper
  11 + * AI 知识库文档 Mapper
12 12 *
13 13 * @author xiaoxin
14 14 */
... ... @@ -17,6 +17,7 @@ public interface AiKnowledgeDocumentMapper extends BaseMapperX&lt;AiKnowledgeDocume
17 17  
18 18 default PageResult<AiKnowledgeDocumentDO> selectPage(AiKnowledgeDocumentPageReqVO reqVO) {
19 19 return selectPage(reqVO, new LambdaQueryWrapperX<AiKnowledgeDocumentDO>()
  20 + .eqIfPresent(AiKnowledgeDocumentDO::getKnowledgeId, reqVO.getKnowledgeId())
20 21 .likeIfPresent(AiKnowledgeDocumentDO::getName, reqVO.getName())
21 22 .orderByDesc(AiKnowledgeDocumentDO::getId));
22 23 }
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/knowledge/AiKnowledgeMapper.java
1 1 package cn.iocoder.yudao.module.ai.dal.mysql.knowledge;
2 2  
3   -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
4 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
6 5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
... ... @@ -9,7 +8,7 @@ import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDO;
9 8 import org.apache.ibatis.annotations.Mapper;
10 9  
11 10 /**
12   - * AI 知识库基础信息 Mapper
  11 + * AI 知识库 Mapper
13 12 *
14 13 * @author xiaoxin
15 14 */
... ... @@ -18,7 +17,10 @@ public interface AiKnowledgeMapper extends BaseMapperX&lt;AiKnowledgeDO&gt; {
18 17  
19 18 default PageResult<AiKnowledgeDO> selectPage(AiKnowledgePageReqVO pageReqVO) {
20 19 return selectPage(pageReqVO, new LambdaQueryWrapperX<AiKnowledgeDO>()
21   - .eq(AiKnowledgeDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
22   - .likeIfPresent(AiKnowledgeDO::getName, pageReqVO.getName()));
  20 + .likeIfPresent(AiKnowledgeDO::getName, pageReqVO.getName())
  21 + .eqIfPresent(AiKnowledgeDO::getStatus, pageReqVO.getStatus())
  22 + .betweenIfPresent(AiKnowledgeDO::getCreateTime, pageReqVO.getCreateTime())
  23 + .orderByDesc(AiKnowledgeDO::getId));
23 24 }
  25 +
24 26 }
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/knowledge/AiKnowledgeSegmentMapper.java
... ... @@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Mapper;
10 10 import java.util.List;
11 11  
12 12 /**
13   - * AI 知识库-分片 Mapper
  13 + * AI 知识库分片 Mapper
14 14 *
15 15 * @author xiaoxin
16 16 */
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeDocumentService.java
... ... @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentPageReqVO;
5 5 import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentUpdateReqVO;
6 6 import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeDocumentCreateReqVO;
7   -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeDocumentCreateListReqVO;
  7 +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentCreateListReqVO;
8 8 import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDocumentDO;
9 9  
10 10 import java.util.List;
... ... @@ -41,6 +41,14 @@ public interface AiKnowledgeDocumentService {
41 41 PageResult<AiKnowledgeDocumentDO> getKnowledgeDocumentPage(AiKnowledgeDocumentPageReqVO pageReqVO);
42 42  
43 43 /**
  44 + * 获取文档详情
  45 + *
  46 + * @param id 文档编号
  47 + * @return 文档详情
  48 + */
  49 + AiKnowledgeDocumentDO getKnowledgeDocument(Long id);
  50 +
  51 + /**
44 52 * 更新文档
45 53 *
46 54 * @param reqVO 更新信息
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeDocumentServiceImpl.java
... ... @@ -8,7 +8,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
8 8 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
9 9 import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentPageReqVO;
10 10 import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentUpdateReqVO;
11   -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeDocumentCreateListReqVO;
  11 +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.document.AiKnowledgeDocumentCreateListReqVO;
12 12 import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeDocumentCreateReqVO;
13 13 import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDocumentDO;
14 14 import cn.iocoder.yudao.module.ai.dal.mysql.knowledge.AiKnowledgeDocumentMapper;
... ... @@ -84,15 +84,17 @@ public class AiKnowledgeDocumentServiceImpl implements AiKnowledgeDocumentServic
84 84 for (int i = 0; i < createListReqVO.getList().size(); i++) {
85 85 AiKnowledgeDocumentCreateListReqVO.Document documentVO = createListReqVO.getList().get(i);
86 86 String content = contents.get(i);
87   - documentDOs.add(BeanUtils.toBean(documentVO, AiKnowledgeDocumentDO.class).setKnowledgeId(createListReqVO.getKnowledgeId())
88   - .setContent(content).setContentLength(content.length()).setTokens(tokenCountEstimator.estimate(content))
  87 + documentDOs.add(BeanUtils.toBean(documentVO, AiKnowledgeDocumentDO.class)
  88 + .setKnowledgeId(createListReqVO.getKnowledgeId())
  89 + .setContent(content).setContentLength(content.length())
  90 + .setTokens(tokenCountEstimator.estimate(content))
89 91 .setStatus(CommonStatusEnum.ENABLE.getStatus()));
90 92 }
91 93 knowledgeDocumentMapper.insertBatch(documentDOs);
92 94  
93 95 // 4. 批量创建文档切片(异步)
94   - documentDOs.forEach(documentDO ->
95   - knowledgeSegmentService.createKnowledgeSegmentBySplitContentAsync(documentDO.getId(), documentDO.getContent()));
  96 + documentDOs.forEach(documentDO -> knowledgeSegmentService
  97 + .createKnowledgeSegmentBySplitContentAsync(documentDO.getId(), documentDO.getContent()));
96 98 return convertList(documentDOs, AiKnowledgeDocumentDO::getId);
97 99 }
98 100  
... ... @@ -102,6 +104,11 @@ public class AiKnowledgeDocumentServiceImpl implements AiKnowledgeDocumentServic
102 104 }
103 105  
104 106 @Override
  107 + public AiKnowledgeDocumentDO getKnowledgeDocument(Long id) {
  108 + return knowledgeDocumentMapper.selectById(id);
  109 + }
  110 +
  111 + @Override
105 112 public void updateKnowledgeDocument(AiKnowledgeDocumentUpdateReqVO reqVO) {
106 113 // 1. 校验文档是否存在
107 114 validateKnowledgeDocumentExists(reqVO.getId());
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeService.java
... ... @@ -28,6 +28,14 @@ public interface AiKnowledgeService {
28 28 void updateKnowledge(AiKnowledgeSaveReqVO updateReqVO);
29 29  
30 30 /**
  31 + * 获得知识库
  32 + *
  33 + * @param id 编号
  34 + * @return 知识库
  35 + */
  36 + AiKnowledgeDO getKnowledge(Long id);
  37 +
  38 + /**
31 39 * 校验知识库是否存在
32 40 *
33 41 * @param id 记录编号
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeServiceImpl.java
1 1 package cn.iocoder.yudao.module.ai.service.knowledge;
2 2  
3   -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
4 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 4 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 5 import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgePageReqVO;
... ... @@ -8,11 +7,9 @@ import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnow
8 7 import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDO;
9 8 import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO;
10 9 import cn.iocoder.yudao.module.ai.dal.mysql.knowledge.AiKnowledgeMapper;
11   -import cn.iocoder.yudao.module.ai.service.model.AiApiKeyService;
12 10 import cn.iocoder.yudao.module.ai.service.model.AiChatModelService;
13 11 import jakarta.annotation.Resource;
14 12 import lombok.extern.slf4j.Slf4j;
15   -import org.springframework.ai.vectorstore.VectorStore;
16 13 import org.springframework.stereotype.Service;
17 14  
18 15 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
... ... @@ -40,7 +37,7 @@ public class AiKnowledgeServiceImpl implements AiKnowledgeService {
40 37  
41 38 // 2. 插入知识库
42 39 AiKnowledgeDO knowledge = BeanUtils.toBean(createReqVO, AiKnowledgeDO.class)
43   - .setEmbeddingModel(model.getModel()).setStatus(CommonStatusEnum.ENABLE.getStatus());
  40 + .setEmbeddingModel(model.getModel());
44 41 knowledgeMapper.insert(knowledge);
45 42 return knowledge.getId();
46 43 }
... ... @@ -56,6 +53,13 @@ public class AiKnowledgeServiceImpl implements AiKnowledgeService {
56 53 AiKnowledgeDO updateObj = BeanUtils.toBean(updateReqVO, AiKnowledgeDO.class)
57 54 .setEmbeddingModel(model.getModel());
58 55 knowledgeMapper.updateById(updateObj);
  56 +
  57 + // TODO @芋艿:如果模型变化,需要 reindex 所有的文档
  58 + }
  59 +
  60 + @Override
  61 + public AiKnowledgeDO getKnowledge(Long id) {
  62 + return knowledgeMapper.selectById(id);
59 63 }
60 64  
61 65 @Override
... ...