正在显示
3 个修改的文件
包含
4 行增加
和
36 行删除
| @@ -118,7 +118,6 @@ public class AiragLogController extends JeecgController<AiragLog, IAiragLogServi | @@ -118,7 +118,6 @@ public class AiragLogController extends JeecgController<AiragLog, IAiragLogServi | ||
| 118 | .filter(model -> "LLM".equals(model.getModelType())) | 118 | .filter(model -> "LLM".equals(model.getModelType())) |
| 119 | .collect(Collectors.toList()); | 119 | .collect(Collectors.toList()); |
| 120 | 120 | ||
| 121 | - | ||
| 122 | return Result.OK(filteredList); | 121 | return Result.OK(filteredList); |
| 123 | } | 122 | } |
| 124 | 123 |
| @@ -56,6 +56,8 @@ public class PgVectorMapper { | @@ -56,6 +56,8 @@ public class PgVectorMapper { | ||
| 56 | countParams.add("%" + embeddings.getText() + "%"); | 56 | countParams.add("%" + embeddings.getText() + "%"); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | + sql.append(" ORDER BY (metadata->>'knowledgeId') ASC NULLS LAST, (metadata->>'docName') ASC"); | ||
| 60 | + | ||
| 59 | // 添加分页 | 61 | // 添加分页 |
| 60 | sql.append(" LIMIT ? OFFSET ?"); | 62 | sql.append(" LIMIT ? OFFSET ?"); |
| 61 | params.add(pageSize); | 63 | params.add(pageSize); |
| @@ -80,24 +82,6 @@ public class PgVectorMapper { | @@ -80,24 +82,6 @@ public class PgVectorMapper { | ||
| 80 | throw new RuntimeException("查询向量数据时发生数据库错误", e); | 82 | throw new RuntimeException("查询向量数据时发生数据库错误", e); |
| 81 | } | 83 | } |
| 82 | 84 | ||
| 83 | - | ||
| 84 | - // 2. 获取知识库名称映射 | ||
| 85 | - Map<String, String> knowledgeNameMap = getKnowledgeNameMap(results); | ||
| 86 | - | ||
| 87 | - // 3. 设置知识库名称并处理空值 | ||
| 88 | - for (Embeddings record : results) { | ||
| 89 | - String knowledgeId = record.getKnowledgeId(); | ||
| 90 | - String name = knowledgeNameMap.get(knowledgeId); | ||
| 91 | - record.setKnowledgeName(name != null ? name : ""); | ||
| 92 | - } | ||
| 93 | - | ||
| 94 | - // 4. 安全排序(处理空值) | ||
| 95 | - results.sort(Comparator | ||
| 96 | - .comparing(Embeddings::getKnowledgeName, | ||
| 97 | - Comparator.nullsLast(Comparator.naturalOrder())) | ||
| 98 | - .thenComparing(Embeddings::getDocName, | ||
| 99 | - Comparator.nullsLast(Comparator.naturalOrder()))); | ||
| 100 | - | ||
| 101 | // 执行计数查询 | 85 | // 执行计数查询 |
| 102 | int total = 0; | 86 | int total = 0; |
| 103 | try(Connection conn = getConnection(); | 87 | try(Connection conn = getConnection(); |
| @@ -68,6 +68,8 @@ public class QuestionEmbeddingMapper { | @@ -68,6 +68,8 @@ public class QuestionEmbeddingMapper { | ||
| 68 | countParams.add("%" + questionEmbedding.getAnswer() + "%"); | 68 | countParams.add("%" + questionEmbedding.getAnswer() + "%"); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | + sql.append(" ORDER BY (metadata->>'knowledgeId') ASC NULLS LAST, question ASC"); | ||
| 72 | + | ||
| 71 | // 添加分页 | 73 | // 添加分页 |
| 72 | sql.append(" LIMIT ? OFFSET ?"); | 74 | sql.append(" LIMIT ? OFFSET ?"); |
| 73 | params.add(pageSize); | 75 | params.add(pageSize); |
| @@ -91,23 +93,6 @@ public class QuestionEmbeddingMapper { | @@ -91,23 +93,6 @@ public class QuestionEmbeddingMapper { | ||
| 91 | throw new RuntimeException("查询数据时发生数据库错误", e); | 93 | throw new RuntimeException("查询数据时发生数据库错误", e); |
| 92 | } | 94 | } |
| 93 | 95 | ||
| 94 | - // 2. 获取知识库名称映射 | ||
| 95 | - Map<String, String> knowledgeNameMap = getKnowledgeNameMap(results); | ||
| 96 | - | ||
| 97 | - // 3. 设置知识库名称并处理空值 | ||
| 98 | - for (QuestionEmbedding record : results) { | ||
| 99 | - String knowledgeId = record.getKnowledgeId(); | ||
| 100 | - String name = knowledgeNameMap.get(knowledgeId); | ||
| 101 | - record.setKnowledgeName(name != null ? name : ""); | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | - // 4. 安全排序(处理空值) | ||
| 105 | - results.sort(Comparator | ||
| 106 | - .comparing(QuestionEmbedding::getKnowledgeName, | ||
| 107 | - Comparator.nullsLast(Comparator.naturalOrder())) | ||
| 108 | - .thenComparing(QuestionEmbedding::getQuestion, | ||
| 109 | - Comparator.nullsLast(Comparator.naturalOrder()))); | ||
| 110 | - | ||
| 111 | // 执行计数查询 | 96 | // 执行计数查询 |
| 112 | long total = 0; | 97 | long total = 0; |
| 113 | try(Connection conn = getConnection(); | 98 | try(Connection conn = getConnection(); |
-
请 注册 或 登录 后发表评论