Commit 1de70eeeb30868204e920ddf286c5d3357823264

Authored by xiaoxin
1 parent c05d7c9f

【优化】AI知识库:visibilityPermissions 使用 list

yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/knowledge/AiKnowledgeCreateReqVO.java
@@ -5,6 +5,8 @@ import jakarta.validation.constraints.NotBlank; @@ -5,6 +5,8 @@ import jakarta.validation.constraints.NotBlank;
5 import jakarta.validation.constraints.NotNull; 5 import jakarta.validation.constraints.NotNull;
6 import lombok.Data; 6 import lombok.Data;
7 7
  8 +import java.util.List;
  9 +
8 @Schema(description = "管理后台 - AI 知识库创建 Request VO") 10 @Schema(description = "管理后台 - AI 知识库创建 Request VO")
9 @Data 11 @Data
10 public class AiKnowledgeCreateReqVO { 12 public class AiKnowledgeCreateReqVO {
@@ -16,8 +18,8 @@ public class AiKnowledgeCreateReqVO { @@ -16,8 +18,8 @@ public class AiKnowledgeCreateReqVO {
16 @Schema(description = "知识库描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "存储 ruoyi-vue-pro 操作文档") 18 @Schema(description = "知识库描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "存储 ruoyi-vue-pro 操作文档")
17 private String description; 19 private String description;
18 20
19 - @Schema(description = "可见权限,只能选择哪些人可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3")  
20 - private String visibilityPermissions; 21 + @Schema(description = "可见权限,只能选择哪些人可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1,2,3]")
  22 + private List<Long> visibilityPermissions;
21 23
22 @Schema(description = "嵌入模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") 24 @Schema(description = "嵌入模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
23 @NotNull(message = "嵌入模型不能为空") 25 @NotNull(message = "嵌入模型不能为空")
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/knowledge/AiKnowledgeUpdateReqVO.java
@@ -5,6 +5,8 @@ import jakarta.validation.constraints.NotBlank; @@ -5,6 +5,8 @@ import jakarta.validation.constraints.NotBlank;
5 import jakarta.validation.constraints.NotNull; 5 import jakarta.validation.constraints.NotNull;
6 import lombok.Data; 6 import lombok.Data;
7 7
  8 +import java.util.List;
  9 +
8 @Schema(description = "管理后台 - AI 知识库更新【我的】 Request VO") 10 @Schema(description = "管理后台 - AI 知识库更新【我的】 Request VO")
9 @Data 11 @Data
10 public class AiKnowledgeUpdateReqVO { 12 public class AiKnowledgeUpdateReqVO {
@@ -21,7 +23,7 @@ public class AiKnowledgeUpdateReqVO { @@ -21,7 +23,7 @@ public class AiKnowledgeUpdateReqVO {
21 private String description; 23 private String description;
22 24
23 @Schema(description = "可见权限,只能选择哪些人可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3") 25 @Schema(description = "可见权限,只能选择哪些人可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3")
24 - private String visibilityPermissions; 26 + private List<Long> visibilityPermissions;
25 27
26 @Schema(description = "嵌入模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") 28 @Schema(description = "嵌入模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
27 @NotNull(message = "嵌入模型不能为空") 29 @NotNull(message = "嵌入模型不能为空")
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/knowledge/AiKnowledgeDO.java
@@ -2,10 +2,14 @@ package cn.iocoder.yudao.module.ai.dal.dataobject.knowledge; @@ -2,10 +2,14 @@ package cn.iocoder.yudao.module.ai.dal.dataobject.knowledge;
2 2
3 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; 3 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
4 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; 4 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  5 +import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler;
  6 +import com.baomidou.mybatisplus.annotation.TableField;
5 import com.baomidou.mybatisplus.annotation.TableId; 7 import com.baomidou.mybatisplus.annotation.TableId;
6 import com.baomidou.mybatisplus.annotation.TableName; 8 import com.baomidou.mybatisplus.annotation.TableName;
7 import lombok.Data; 9 import lombok.Data;
8 10
  11 +import java.util.List;
  12 +
9 /** 13 /**
10 * AI 知识库 DO 14 * AI 知识库 DO
11 * 15 *
@@ -40,7 +44,8 @@ public class AiKnowledgeDO extends BaseDO { @@ -40,7 +44,8 @@ public class AiKnowledgeDO extends BaseDO {
40 * <p> 44 * <p>
41 * -1 所有人可见,其他为各自用户编号 45 * -1 所有人可见,其他为各自用户编号
42 */ 46 */
43 - private String visibilityPermissions; 47 + @TableField(typeHandler = LongListTypeHandler.class)
  48 + private List<Long> visibilityPermissions;
44 /** 49 /**
45 * 嵌入模型编号 50 * 嵌入模型编号
46 */ 51 */
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/chat/AiChatMessageServiceImpl.java
@@ -156,11 +156,10 @@ public class AiChatMessageServiceImpl implements AiChatMessageService { @@ -156,11 +156,10 @@ public class AiChatMessageServiceImpl implements AiChatMessageService {
156 } 156 }
157 157
158 private List<AiKnowledgeSegmentDO> recallSegment(String content, Long knowledgeId) { 158 private List<AiKnowledgeSegmentDO> recallSegment(String content, Long knowledgeId) {
159 - List<AiKnowledgeSegmentDO> segmentList = new ArrayList<>();  
160 - if (Objects.nonNull(knowledgeId)) {  
161 - segmentList = knowledgeSegmentService.similaritySearch(new AiKnowledgeSegmentSearchReqVO().setKnowledgeId(knowledgeId).setContent(content)); 159 + if (Objects.isNull(knowledgeId)) {
  160 + return Collections.emptyList();
162 } 161 }
163 - return segmentList; 162 + return knowledgeSegmentService.similaritySearch(new AiKnowledgeSegmentSearchReqVO().setKnowledgeId(knowledgeId).setContent(content));
164 } 163 }
165 164
166 private Prompt buildPrompt(AiChatConversationDO conversation, List<AiChatMessageDO> messages,List<AiKnowledgeSegmentDO> segmentList, 165 private Prompt buildPrompt(AiChatConversationDO conversation, List<AiChatMessageDO> messages,List<AiKnowledgeSegmentDO> segmentList,