Commit b4af042c640cc0e710f7c4121b6375c50210d54e
1 parent
b4538568
【新增】AI 知识库管理
Showing
20 changed files
with
484 additions
and
10 deletions
yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/ErrorCodeConstants.java
| ... | ... | @@ -50,4 +50,8 @@ public interface ErrorCodeConstants { |
| 50 | 50 | ErrorCode WRITE_NOT_EXISTS = new ErrorCode(1_022_007_000, "作文不存在!"); |
| 51 | 51 | ErrorCode WRITE_STREAM_ERROR = new ErrorCode(1_022_07_001, "写作生成异常!"); |
| 52 | 52 | |
| 53 | + | |
| 54 | + // ========== API 知识库 1-022-008-000 ========== | |
| 55 | + ErrorCode KNOWLEDGE_NOT_EXISTS = new ErrorCode(1_022_008_000, "知识库不存在!"); | |
| 56 | + | |
| 53 | 57 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.knowledge; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.AiKnowledgeCreateMyReqVO; | |
| 5 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.AiKnowledgeUpdateMyReqVO; | |
| 6 | +import cn.iocoder.yudao.module.ai.service.knowledge.AiKnowledgeBaseService; | |
| 7 | +import io.swagger.v3.oas.annotations.Operation; | |
| 8 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 9 | +import jakarta.annotation.Resource; | |
| 10 | +import jakarta.validation.Valid; | |
| 11 | +import org.springframework.web.bind.annotation.*; | |
| 12 | + | |
| 13 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 14 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 15 | + | |
| 16 | +@Tag(name = "管理后台 - AI 知识库") | |
| 17 | +@RestController | |
| 18 | +@RequestMapping("/ai/knowledge") | |
| 19 | +public class AiKnowledgeController { | |
| 20 | + | |
| 21 | + @Resource | |
| 22 | + private AiKnowledgeBaseService knowledgeBaseService; | |
| 23 | + | |
| 24 | + @PostMapping("/create-my") | |
| 25 | + @Operation(summary = "创建【我的】知识库") | |
| 26 | + public CommonResult<Long> createKnowledgeMy(@RequestBody @Valid AiKnowledgeCreateMyReqVO createReqVO) { | |
| 27 | + return success(knowledgeBaseService.createKnowledgeMy(createReqVO, getLoginUserId())); | |
| 28 | + } | |
| 29 | + | |
| 30 | + | |
| 31 | + @PutMapping("/update-my") | |
| 32 | + @Operation(summary = "更新【我的】知识库") | |
| 33 | + public CommonResult<Boolean> updateKnowledgeMy(@RequestBody @Valid AiKnowledgeUpdateMyReqVO updateReqVO) { | |
| 34 | + knowledgeBaseService.updateKnowledgeMy(updateReqVO, getLoginUserId()); | |
| 35 | + return success(true); | |
| 36 | + } | |
| 37 | + | |
| 38 | + | |
| 39 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/AiKnowledgeCreateMyReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.constraints.NotBlank; | |
| 5 | +import jakarta.validation.constraints.NotNull; | |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * @author xiaoxin | |
| 12 | + */ | |
| 13 | +@Schema(description = "管理后台 - AI 知识库创建【我的】 Request VO") | |
| 14 | +@Data | |
| 15 | +public class AiKnowledgeCreateMyReqVO { | |
| 16 | + | |
| 17 | + @Schema(description = "知识库名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "") | |
| 18 | + @NotBlank(message = "知识库名称不能为空") | |
| 19 | + private String name; | |
| 20 | + | |
| 21 | + @Schema(description = "知识库描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "") | |
| 22 | + private String description; | |
| 23 | + | |
| 24 | + @Schema(description = "可见权限,只能选择哪些人可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1]") | |
| 25 | + private List<Long> visibilityPermissions; | |
| 26 | + | |
| 27 | + @Schema(description = "嵌入模型 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 28 | + @NotNull(message = "嵌入模型不能为空") | |
| 29 | + private Long modelId; | |
| 30 | + | |
| 31 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/AiKnowledgeUpdateMyReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.constraints.NotBlank; | |
| 5 | +import jakarta.validation.constraints.NotNull; | |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * @author xiaoxin | |
| 12 | + */ | |
| 13 | +@Schema(description = "管理后台 - AI 知识库创建【我的】 Request VO") | |
| 14 | +@Data | |
| 15 | +public class AiKnowledgeUpdateMyReqVO { | |
| 16 | + | |
| 17 | + | |
| 18 | + @Schema(description = "对话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1204") | |
| 19 | + @NotNull(message = "知识库编号不能为空") | |
| 20 | + private Long id; | |
| 21 | + | |
| 22 | + @Schema(description = "知识库名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "") | |
| 23 | + @NotBlank(message = "知识库名称不能为空") | |
| 24 | + private String name; | |
| 25 | + | |
| 26 | + @Schema(description = "知识库描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "") | |
| 27 | + private String description; | |
| 28 | + | |
| 29 | + @Schema(description = "可见权限,只能选择哪些人可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1]") | |
| 30 | + private List<Long> visibilityPermissions; | |
| 31 | + | |
| 32 | + @Schema(description = "嵌入模型 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 33 | + @NotNull(message = "嵌入模型不能为空") | |
| 34 | + private Long modelId; | |
| 35 | + | |
| 36 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/knowledge/AiKnowledgeBaseDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.dal.dataobject.knowledge; | |
| 2 | + | |
| 3 | + | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 5 | +import com.baomidou.mybatisplus.annotation.IdType; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 7 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 8 | +import lombok.Data; | |
| 9 | + | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * AI 知识库 DO | |
| 14 | + * | |
| 15 | + * @author xiaoxin | |
| 16 | + */ | |
| 17 | +@TableName(value = "ai_knowledge_base") | |
| 18 | +@Data | |
| 19 | +public class AiKnowledgeBaseDO extends BaseDO { | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 编号 | |
| 23 | + */ | |
| 24 | + @TableId(type = IdType.AUTO) | |
| 25 | + private Long id; | |
| 26 | + /** | |
| 27 | + * 用户编号 | |
| 28 | + * <p> | |
| 29 | + * 关联 AdminUserDO 的 userId 字段 | |
| 30 | + */ | |
| 31 | + private Long userId; | |
| 32 | + /** | |
| 33 | + * 知识库名称 | |
| 34 | + */ | |
| 35 | + private String name; | |
| 36 | + /** | |
| 37 | + * 知识库描述 | |
| 38 | + */ | |
| 39 | + private String description; | |
| 40 | + /** | |
| 41 | + * 可见权限,只能选择哪些人可见 | |
| 42 | + */ | |
| 43 | + private List<String> visibilityPermissions; | |
| 44 | + /** | |
| 45 | + * 嵌入模型编号,高质量模式时维护 | |
| 46 | + */ | |
| 47 | + private Long modelId; | |
| 48 | + /** | |
| 49 | + * 模型标识 | |
| 50 | + */ | |
| 51 | + private String model; | |
| 52 | + /** | |
| 53 | + * 是否启用 | |
| 54 | + */ | |
| 55 | + private Boolean status; | |
| 56 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/knowledge/AiKnowledgeDocumentDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.dal.dataobject.knowledge; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | +import com.baomidou.mybatisplus.annotation.IdType; | |
| 5 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 7 | +import lombok.Data; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * AI 知识库-文档 DO | |
| 11 | + * | |
| 12 | + * @author xiaoxin | |
| 13 | + */ | |
| 14 | +@TableName(value = "ai_knowledge_document") | |
| 15 | +@Data | |
| 16 | +public class AiKnowledgeDocumentDO extends BaseDO { | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 编号 | |
| 20 | + */ | |
| 21 | + @TableId(type = IdType.AUTO) | |
| 22 | + private Long id; | |
| 23 | + /** | |
| 24 | + * 知识库编号 | |
| 25 | + */ | |
| 26 | + private Long knowledgeId; | |
| 27 | + /** | |
| 28 | + * 文件名称 | |
| 29 | + */ | |
| 30 | + private String name; | |
| 31 | + /** | |
| 32 | + * 内容 | |
| 33 | + */ | |
| 34 | + private String content; | |
| 35 | + /** | |
| 36 | + * 文件 URL | |
| 37 | + */ | |
| 38 | + private String url; | |
| 39 | + /** | |
| 40 | + * token数量 | |
| 41 | + */ | |
| 42 | + private Integer tokens; | |
| 43 | + /** | |
| 44 | + * 字符数 | |
| 45 | + */ | |
| 46 | + private Integer wordCount; | |
| 47 | + /** | |
| 48 | + * 切片状态 | |
| 49 | + */ | |
| 50 | + private Integer sliceStatus; | |
| 51 | + /** | |
| 52 | + * 是否启用 | |
| 53 | + */ | |
| 54 | + private Boolean status; | |
| 55 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/knowledge/AiKnowledgeSegmentDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.dal.dataobject.knowledge; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | +import com.baomidou.mybatisplus.annotation.IdType; | |
| 5 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 7 | +import lombok.Data; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * AI 知识库-文档分段 DO | |
| 11 | + * | |
| 12 | + * @author xiaoxin | |
| 13 | + */ | |
| 14 | +@TableName(value = "ai_knowledge_segment") | |
| 15 | +@Data | |
| 16 | +public class AiKnowledgeSegmentDO extends BaseDO { | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 编号 | |
| 20 | + */ | |
| 21 | + @TableId(type = IdType.AUTO) | |
| 22 | + private Long id; | |
| 23 | + /** | |
| 24 | + * 向量库的id | |
| 25 | + */ | |
| 26 | + private String vectorId; | |
| 27 | + /** | |
| 28 | + * 文档编号 | |
| 29 | + */ | |
| 30 | + private Long documentId; | |
| 31 | + /** | |
| 32 | + * 切片内容 | |
| 33 | + */ | |
| 34 | + private String content; | |
| 35 | + /** | |
| 36 | + * 字符数 | |
| 37 | + */ | |
| 38 | + private Integer wordCount; | |
| 39 | + /** | |
| 40 | + * token数量 | |
| 41 | + */ | |
| 42 | + private Integer tokens; | |
| 43 | + /** | |
| 44 | + * 是否启用 | |
| 45 | + */ | |
| 46 | + private Boolean status; | |
| 47 | + | |
| 48 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/knowledge/AiKnowledgeBaseMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.dal.mysql.knowledge; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeBaseDO; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * AI 知识库基础信息 Mapper | |
| 8 | + * | |
| 9 | + * @author xiaoxin | |
| 10 | + */ | |
| 11 | +public interface AiKnowledgeBaseMapper extends BaseMapperX<AiKnowledgeBaseDO> { | |
| 12 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/knowledge/AiKnowledgeDocumentMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.dal.mysql.knowledge; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDocumentDO; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * AI 知识库-文档 Mapper | |
| 8 | + * | |
| 9 | + * @author xiaoxin | |
| 10 | + */ | |
| 11 | +public interface AiKnowledgeDocumentMapper extends BaseMapperX<AiKnowledgeDocumentDO> { | |
| 12 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/knowledge/AiKnowledgeSegmentMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.dal.mysql.knowledge; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeSegmentDO; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * AI 知识库-分片 Mapper | |
| 8 | + * | |
| 9 | + * @author xiaoxin | |
| 10 | + */ | |
| 11 | +public interface AiKnowledgeSegmentMapper extends BaseMapperX<AiKnowledgeSegmentDO> { | |
| 12 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/DocService.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiEmbeddingService.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.service.knowledge; |
| 2 | 2 | |
| 3 | +import org.springframework.ai.document.Document; | |
| 4 | + | |
| 5 | +import java.util.List; | |
| 6 | + | |
| 3 | 7 | /** |
| 4 | - * AI 知识库 Service 接口 | |
| 8 | + * AI 嵌入 Service 接口 | |
| 5 | 9 | * |
| 6 | 10 | * @author xiaoxin |
| 7 | 11 | */ |
| 8 | -public interface DocService { | |
| 12 | +public interface AiEmbeddingService { | |
| 9 | 13 | |
| 10 | 14 | /** |
| 11 | 15 | * 向量化文档 |
| 12 | 16 | */ |
| 13 | 17 | void embeddingDoc(); |
| 14 | 18 | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * 相似查询 | |
| 22 | + * | |
| 23 | + * @param content 查询内容 | |
| 24 | + */ | |
| 25 | + List<Document> similaritySearch(String content); | |
| 15 | 26 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/DocServiceImpl.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiEmbeddingServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.service.knowledge; |
| 2 | 2 | |
| 3 | 3 | import jakarta.annotation.Resource; |
| 4 | -import lombok.extern.slf4j.Slf4j; | |
| 5 | 4 | import org.springframework.ai.document.Document; |
| 6 | 5 | import org.springframework.ai.reader.tika.TikaDocumentReader; |
| 7 | 6 | import org.springframework.ai.transformer.splitter.TokenTextSplitter; |
| 8 | 7 | import org.springframework.ai.vectorstore.RedisVectorStore; |
| 8 | +import org.springframework.ai.vectorstore.SearchRequest; | |
| 9 | 9 | import org.springframework.beans.factory.annotation.Value; |
| 10 | 10 | import org.springframework.stereotype.Service; |
| 11 | 11 | |
| 12 | 12 | import java.util.List; |
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | - * AI 知识库 Service 实现类 | |
| 15 | + * AI 嵌入 Service 实现类 | |
| 16 | 16 | * |
| 17 | 17 | * @author xiaoxin |
| 18 | 18 | */ |
| 19 | 19 | @Service |
| 20 | -@Slf4j | |
| 21 | -public class DocServiceImpl implements DocService { | |
| 20 | +public class AiEmbeddingServiceImpl implements AiEmbeddingService { | |
| 22 | 21 | |
| 23 | 22 | @Resource |
| 24 | 23 | private RedisVectorStore vectorStore; |
| ... | ... | @@ -40,4 +39,9 @@ public class DocServiceImpl implements DocService { |
| 40 | 39 | vectorStore.add(segments); |
| 41 | 40 | } |
| 42 | 41 | |
| 42 | + @Override | |
| 43 | + public List<Document> similaritySearch(String content) { | |
| 44 | + SearchRequest request = SearchRequest.query(content); | |
| 45 | + return vectorStore.similaritySearch(request); | |
| 46 | + } | |
| 43 | 47 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeBaseService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.service.knowledge; | |
| 2 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.AiKnowledgeCreateMyReqVO; | |
| 3 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.AiKnowledgeUpdateMyReqVO; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * AI 知识库-基础信息 Service 接口 | |
| 7 | + * | |
| 8 | + * @author xiaoxin | |
| 9 | + */ | |
| 10 | +public interface AiKnowledgeBaseService { | |
| 11 | + | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 创建【我的】知识库 | |
| 15 | + * | |
| 16 | + * @param createReqVO 创建信息 | |
| 17 | + * @param userId 用户编号 | |
| 18 | + * @return 编号 | |
| 19 | + */ | |
| 20 | + Long createKnowledgeMy(AiKnowledgeCreateMyReqVO createReqVO, Long userId); | |
| 21 | + | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 创建【我的】知识库 | |
| 25 | + * | |
| 26 | + * @param updateReqVO 更新信息 | |
| 27 | + * @param userId 用户编号 | |
| 28 | + */ | |
| 29 | + void updateKnowledgeMy(AiKnowledgeUpdateMyReqVO updateReqVO, Long userId); | |
| 30 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeBaseServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.service.knowledge; | |
| 2 | + | |
| 3 | +import cn.hutool.core.lang.Assert; | |
| 4 | +import cn.hutool.core.util.ObjUtil; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.AiKnowledgeCreateMyReqVO; | |
| 7 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.AiKnowledgeUpdateMyReqVO; | |
| 8 | +import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeBaseDO; | |
| 9 | +import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; | |
| 10 | +import cn.iocoder.yudao.module.ai.dal.mysql.knowledge.AiKnowledgeBaseMapper; | |
| 11 | +import cn.iocoder.yudao.module.ai.service.model.AiChatModelService; | |
| 12 | +import jakarta.annotation.Resource; | |
| 13 | +import lombok.extern.slf4j.Slf4j; | |
| 14 | +import org.springframework.stereotype.Service; | |
| 15 | + | |
| 16 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 17 | +import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.KNOWLEDGE_NOT_EXISTS; | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * AI 知识库-基础信息 Service 实现类 | |
| 21 | + * | |
| 22 | + * @author xiaoxin | |
| 23 | + */ | |
| 24 | +@Service | |
| 25 | +@Slf4j | |
| 26 | +public class AiKnowledgeBaseServiceImpl implements AiKnowledgeBaseService { | |
| 27 | + | |
| 28 | + @Resource | |
| 29 | + private AiKnowledgeBaseMapper knowledgeBaseMapper; | |
| 30 | + @Resource | |
| 31 | + private AiChatModelService chatModalService; | |
| 32 | + | |
| 33 | + @Override | |
| 34 | + public Long createKnowledgeMy(AiKnowledgeCreateMyReqVO createReqVO, Long userId) { | |
| 35 | + AiChatModelDO model = validateChatModel(createReqVO.getModelId()); | |
| 36 | + | |
| 37 | + AiKnowledgeBaseDO knowledgeBaseDO = BeanUtils.toBean(createReqVO, AiKnowledgeBaseDO.class); | |
| 38 | + knowledgeBaseDO.setModel(model.getModel()).setUserId(userId); | |
| 39 | + | |
| 40 | + knowledgeBaseMapper.insert(knowledgeBaseDO); | |
| 41 | + return knowledgeBaseDO.getId(); | |
| 42 | + } | |
| 43 | + | |
| 44 | + @Override | |
| 45 | + public void updateKnowledgeMy(AiKnowledgeUpdateMyReqVO updateReqVO, Long userId) { | |
| 46 | + | |
| 47 | + AiKnowledgeBaseDO knowledgeBaseDO = validateKnowledgeExists(updateReqVO.getId()); | |
| 48 | + if (ObjUtil.notEqual(knowledgeBaseDO.getUserId(), userId)) { | |
| 49 | + throw exception(KNOWLEDGE_NOT_EXISTS); | |
| 50 | + } | |
| 51 | + AiChatModelDO model = validateChatModel(updateReqVO.getModelId()); | |
| 52 | + AiKnowledgeBaseDO updateDO = BeanUtils.toBean(updateReqVO, AiKnowledgeBaseDO.class); | |
| 53 | + updateDO.setModel(model.getModel()); | |
| 54 | + | |
| 55 | + knowledgeBaseMapper.updateById(updateDO); | |
| 56 | + } | |
| 57 | + | |
| 58 | + | |
| 59 | + private AiChatModelDO validateChatModel(Long id) { | |
| 60 | + AiChatModelDO model = chatModalService.validateChatModel(id); | |
| 61 | + Assert.notNull(model, "未找到对应嵌入模型"); | |
| 62 | + return model; | |
| 63 | + } | |
| 64 | + | |
| 65 | + public AiKnowledgeBaseDO validateKnowledgeExists(Long id) { | |
| 66 | + AiKnowledgeBaseDO knowledgeBase = knowledgeBaseMapper.selectById(id); | |
| 67 | + if (knowledgeBase == null) { | |
| 68 | + throw exception(KNOWLEDGE_NOT_EXISTS); | |
| 69 | + } | |
| 70 | + return knowledgeBase; | |
| 71 | + } | |
| 72 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeDocumentService.java
0 → 100644
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeDocumentServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.service.knowledge; | |
| 2 | + | |
| 3 | +import lombok.extern.slf4j.Slf4j; | |
| 4 | +import org.springframework.stereotype.Service; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * AI 知识库-文档 Service 实现类 | |
| 8 | + * | |
| 9 | + * @author xiaoxin | |
| 10 | + */ | |
| 11 | +@Service | |
| 12 | +@Slf4j | |
| 13 | +public class AiKnowledgeDocumentServiceImpl implements AiKnowledgeDocumentService { | |
| 14 | + | |
| 15 | + | |
| 16 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeSegmentService.java
0 → 100644
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeSegmentServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.service.knowledge; | |
| 2 | + | |
| 3 | +import lombok.extern.slf4j.Slf4j; | |
| 4 | +import org.springframework.stereotype.Service; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * AI 知识库-基础信息 Service 实现类 | |
| 8 | + * | |
| 9 | + * @author xiaoxin | |
| 10 | + */ | |
| 11 | +@Service | |
| 12 | +@Slf4j | |
| 13 | +public class AiKnowledgeSegmentServiceImpl implements AiKnowledgeSegmentService { | |
| 14 | + | |
| 15 | + | |
| 16 | +} | ... | ... |
yudao-module-ai/yudao-spring-boot-starter-ai/pom.xml
| ... | ... | @@ -57,11 +57,9 @@ |
| 57 | 57 | <version>${spring-ai.version}</version> |
| 58 | 58 | </dependency> |
| 59 | 59 | |
| 60 | - <!-- TODO @xin:引入我们项目的 starter --> | |
| 61 | 60 | <dependency> |
| 62 | - <groupId>org.springframework.data</groupId> | |
| 63 | - <artifactId>spring-data-redis</artifactId> | |
| 64 | - <optional>true</optional> | |
| 61 | + <groupId>cn.iocoder.boot</groupId> | |
| 62 | + <artifactId>yudao-spring-boot-starter-redis</artifactId> | |
| 65 | 63 | </dependency> |
| 66 | 64 | |
| 67 | 65 | <dependency> | ... | ... |
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/org/springframework/ai/autoconfigure/vectorstore/redis/RedisVectorStoreAutoConfiguration.java