正在显示
5 个修改的文件
包含
21 行增加
和
14 行删除
| @@ -11,6 +11,7 @@ import java.sql.*; | @@ -11,6 +11,7 @@ import java.sql.*; | ||
| 11 | import java.util.Map; | 11 | import java.util.Map; |
| 12 | 12 | ||
| 13 | public class JsonbMapTypeHandler extends BaseTypeHandler<Map<String, Object>> { | 13 | public class JsonbMapTypeHandler extends BaseTypeHandler<Map<String, Object>> { |
| 14 | + | ||
| 14 | private static final ObjectMapper objectMapper = new ObjectMapper(); | 15 | private static final ObjectMapper objectMapper = new ObjectMapper(); |
| 15 | 16 | ||
| 16 | @Override | 17 | @Override |
| @@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage; | @@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage; | ||
| 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| 6 | import org.apache.ibatis.annotations.Mapper; | 6 | import org.apache.ibatis.annotations.Mapper; |
| 7 | import org.apache.ibatis.annotations.Param; | 7 | import org.apache.ibatis.annotations.Param; |
| 8 | -import org.apache.ibatis.annotations.Select; | ||
| 9 | import org.jeecg.modules.airag.app.entity.QuestionEmbedding; | 8 | import org.jeecg.modules.airag.app.entity.QuestionEmbedding; |
| 10 | 9 | ||
| 11 | import java.util.List; | 10 | import java.util.List; |
| @@ -18,7 +17,7 @@ public interface QuestionEmbeddingMapper { | @@ -18,7 +17,7 @@ public interface QuestionEmbeddingMapper { | ||
| 18 | Integer findQuestionCount(@Param("questionEmbedding") QuestionEmbedding questionEmbedding); | 17 | Integer findQuestionCount(@Param("questionEmbedding") QuestionEmbedding questionEmbedding); |
| 19 | 18 | ||
| 20 | QuestionEmbedding findById(@Param("id") String id); | 19 | QuestionEmbedding findById(@Param("id") String id); |
| 21 | - @DS("pgvector") | 20 | + |
| 22 | int insert(@Param("record") QuestionEmbedding record); | 21 | int insert(@Param("record") QuestionEmbedding record); |
| 23 | 22 | ||
| 24 | int update(@Param("record") QuestionEmbedding record); | 23 | int update(@Param("record") QuestionEmbedding record); |
| @@ -29,6 +28,7 @@ public interface QuestionEmbeddingMapper { | @@ -29,6 +28,7 @@ public interface QuestionEmbeddingMapper { | ||
| 29 | 28 | ||
| 30 | List<QuestionEmbedding> similaritySearchByQuestion(@Param("vector") float[] vector, | 29 | List<QuestionEmbedding> similaritySearchByQuestion(@Param("vector") float[] vector, |
| 31 | @Param("limit") int limit, | 30 | @Param("limit") int limit, |
| 32 | - @Param("minSimilarity") Double minSimilarity); | 31 | + @Param("minSimilarity") Double minSimilarity, |
| 32 | + @Param("knowledgeId") String knowledgeId); | ||
| 33 | 33 | ||
| 34 | } | 34 | } |
| @@ -23,7 +23,7 @@ | @@ -23,7 +23,7 @@ | ||
| 23 | <if test="questionEmbedding.answer != null and questionEmbedding.answer != ''"> | 23 | <if test="questionEmbedding.answer != null and questionEmbedding.answer != ''"> |
| 24 | AND answer ILIKE CONCAT('%', #{questionEmbedding.answer}, '%') | 24 | AND answer ILIKE CONCAT('%', #{questionEmbedding.answer}, '%') |
| 25 | </if> | 25 | </if> |
| 26 | - ORDER BY (metadata->>'knowledgeId') ASC NULLS LAST, question ASC | 26 | + ORDER BY (metadata->>'knowledgeId') NULLS LAST, question |
| 27 | </select> | 27 | </select> |
| 28 | 28 | ||
| 29 | <select id="findQuestionCount" resultType="int"> | 29 | <select id="findQuestionCount" resultType="int"> |
| @@ -74,10 +74,14 @@ | @@ -74,10 +74,14 @@ | ||
| 74 | <select id="similaritySearchByQuestion" resultMap="questionEmbeddingResultMap"> | 74 | <select id="similaritySearchByQuestion" resultMap="questionEmbeddingResultMap"> |
| 75 | <![CDATA[ | 75 | <![CDATA[ |
| 76 | SELECT *, | 76 | SELECT *, |
| 77 | - (embedding <-> #{vector, jdbcType=ARRAY, typeHandler=org.jeecg.modules.airag.app.handler.PgVectorTypeHandler})::float AS similarity | 77 | + (embedding <-> |
| 78 | + #{vector, jdbcType=ARRAY, typeHandler=org.jeecg.modules.airag.app.handler.PgVectorTypeHandler})::float AS similarity | ||
| 78 | FROM question_embedding | 79 | FROM question_embedding |
| 79 | - WHERE (embedding <-> #{vector, jdbcType=ARRAY, typeHandler=org.jeecg.modules.airag.app.handler.PgVectorTypeHandler}) < #{minSimilarity} | ||
| 80 | - ORDER BY similarity ASC | 80 | + WHERE (embedding <-> |
| 81 | + #{vector, jdbcType=ARRAY, typeHandler=org.jeecg.modules.airag.app.handler.PgVectorTypeHandler}) < | ||
| 82 | + #{minSimilarity} | ||
| 83 | + AND metadata ->> 'knowledgeId' = #{knowledgeId} | ||
| 84 | + ORDER BY similarity | ||
| 81 | LIMIT #{limit} | 85 | LIMIT #{limit} |
| 82 | ]]> | 86 | ]]> |
| 83 | </select> | 87 | </select> |
| @@ -118,7 +118,7 @@ public class QuestionEmbeddingServiceImpl implements IQuestionEmbeddingService { | @@ -118,7 +118,7 @@ public class QuestionEmbeddingServiceImpl implements IQuestionEmbeddingService { | ||
| 118 | Response<Embedding> embedding = aiModelUtils.getEmbedding(chatSetting.getEmbeddingId(), question); | 118 | Response<Embedding> embedding = aiModelUtils.getEmbedding(chatSetting.getEmbeddingId(), question); |
| 119 | 119 | ||
| 120 | 120 | ||
| 121 | - return questionEmbeddingMapper.similaritySearchByQuestion(embedding.content().vector(), limit, 1 - minSimilarity); | 121 | + return questionEmbeddingMapper.similaritySearchByQuestion(embedding.content().vector(), limit, 1 - minSimilarity,chatSetting.getKnowledgeId()); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | 124 |
| @@ -20,18 +20,18 @@ public class ZdyRagController { | @@ -20,18 +20,18 @@ public class ZdyRagController { | ||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | /** | 22 | /** |
| 23 | + * 1、将提问文本与问题库匹配,若匹配则回答预设回答结果 | ||
| 24 | + * 2、若问题库中无匹配预设问题,则查询知识库,将查询到的知识提供给llm模型,生成回答结果 | ||
| 25 | + * 3、回答时会将当初上传的资料以参考资料的形式进行返回,可进行预览 | ||
| 26 | + * 4、将本次的问答结果记录日志 | ||
| 27 | + * todo :增加产品推荐功能? | ||
| 28 | + * | ||
| 23 | * @author lixiang | 29 | * @author lixiang |
| 24 | * @param questionText 问题文本 | 30 | * @param questionText 问题文本 |
| 25 | * @param code 快捷按钮code | 31 | * @param code 快捷按钮code |
| 26 | * @param codeType 提问方式,用于记录日志,区分输入框提问还是快捷方式 | 32 | * @param codeType 提问方式,用于记录日志,区分输入框提问还是快捷方式 |
| 27 | * @param user 提问人 | 33 | * @param user 提问人 |
| 28 | * @return 以流式返回回答结果 | 34 | * @return 以流式返回回答结果 |
| 29 | - * | ||
| 30 | - * 1、将提问文本与问题库匹配,若匹配则回答预设回答结果 | ||
| 31 | - * 2、若问题库中无匹配预设问题,则查询知识库,将查询到的知识提供给llm模型,生成回答结果 | ||
| 32 | - * 3、回答时会将当初上传的资料以参考资料的形式进行返回,可进行预览 | ||
| 33 | - * 4、将本次的问答结果记录日志 | ||
| 34 | - * todo :增加产品推荐功能? | ||
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | @Operation(summary = "sendStream") | 37 | @Operation(summary = "sendStream") |
| @@ -40,6 +40,8 @@ public class ZdyRagController { | @@ -40,6 +40,8 @@ public class ZdyRagController { | ||
| 40 | @RequestParam("code") String code, | 40 | @RequestParam("code") String code, |
| 41 | @RequestParam("codeType") Integer codeType, | 41 | @RequestParam("codeType") Integer codeType, |
| 42 | @RequestParam("user") String user) { | 42 | @RequestParam("user") String user) { |
| 43 | + | ||
| 43 | return airagResponseService.handleStreamRequest(questionText, code, codeType, user); | 44 | return airagResponseService.handleStreamRequest(questionText, code, codeType, user); |
| 45 | + | ||
| 44 | } | 46 | } |
| 45 | } | 47 | } |
-
请 注册 或 登录 后发表评论