Merge pull request #337 from eroXianYin/main

知识库检索节点补齐严格模式、默认回复及节点注册
This commit is contained in:
ageerle
2026-09-21 11:02:32 +08:00
committed by GitHub
4 changed files with 65 additions and 17 deletions

View File

@@ -3476,6 +3476,7 @@ INSERT INTO `t_workflow_component` VALUES (18, '5cd6ac69bbb411f0bb7840c2ba9a7fbc
INSERT INTO `t_workflow_component` VALUES (19, '5cd6c8eabbb411f0bb7840c2ba9a7fbc', 'Answer', '生成回答', '调用大语言模型回答问题', 0, 1, '2025-11-07 16:32:49', '2025-11-07 16:32:49', 0, '000000'); INSERT INTO `t_workflow_component` VALUES (19, '5cd6c8eabbb411f0bb7840c2ba9a7fbc', 'Answer', '生成回答', '调用大语言模型回答问题', 0, 1, '2025-11-07 16:32:49', '2025-11-07 16:32:49', 0, '000000');
INSERT INTO `t_workflow_component` VALUES (26, 'bb00fc2f52c74fec82ee3f99725b56bb', 'Switcher', '条件分支', '根据条件执行不同分支', 0, 1, '2025-12-26 16:30:46', '2025-12-26 16:30:46', 0, '000000'); INSERT INTO `t_workflow_component` VALUES (26, 'bb00fc2f52c74fec82ee3f99725b56bb', 'Switcher', '条件分支', '根据条件执行不同分支', 0, 1, '2025-12-26 16:30:46', '2025-12-26 16:30:46', 0, '000000');
INSERT INTO `t_workflow_component` VALUES (37, 'a7f8c2d44e5b4c83a9d6f103c2b47e18', 'Google', '网络搜索', '调用智谱 Web Search 检索互联网信息', 40, 1, '2026-07-29 20:30:00', '2026-07-29 20:30:00', 0, '000000'); INSERT INTO `t_workflow_component` VALUES (37, 'a7f8c2d44e5b4c83a9d6f103c2b47e18', 'Google', '网络搜索', '调用智谱 Web Search 检索互联网信息', 40, 1, '2026-07-29 20:30:00', '2026-07-29 20:30:00', 0, '000000');
INSERT INTO `t_workflow_component` VALUES (38, 'b8e3c1d55f6a4d92b0e7f214d3c58a29', 'KnowledgeRetrieval', '知识库检索', '从知识库中检索相关内容,支持向量检索和混合检索', 30, 1, '2026-09-11 10:00:00', '2026-09-11 10:00:00', 0, '000000');
-- ---------------------------- -- ----------------------------
-- Table structure for t_workflow_edge -- Table structure for t_workflow_edge

View File

@@ -0,0 +1,24 @@
-- 知识库检索工作流节点注册
-- 为新安装和已有环境提供幂等的节点注册
INSERT INTO `t_workflow_component`
(`uuid`, `name`, `title`, `remark`, `display_order`, `is_enable`,
`create_time`, `update_time`, `is_deleted`, `tenant_id`)
SELECT
'b8e3c1d55f6a4d92b0e7f214d3c58a29',
'KnowledgeRetrieval',
'知识库检索',
'从知识库中检索相关内容,支持向量检索和混合检索',
30,
1,
NOW(),
NOW(),
0,
'000000'
FROM DUAL
WHERE NOT EXISTS (
SELECT 1
FROM `t_workflow_component`
WHERE `name` = 'KnowledgeRetrieval'
AND `tenant_id` = '000000'
);

View File

@@ -88,6 +88,15 @@ public class KnowledgeRetrievalNode extends AbstractWfNode {
retrievalResult = retrieveFromVector(config, finalQuery); retrievalResult = retrieveFromVector(config, finalQuery);
// 严格模式处理:检索无结果时返回默认回复
if (StringUtils.isBlank(retrievalResult) && Boolean.TRUE.equals(config.getIsStrict())) {
String defaultResp = config.getDefaultResponse();
if (StringUtils.isNotBlank(defaultResp)) {
log.info("Knowledge retrieval returned no results, using default response (strict mode)");
retrievalResult = defaultResp;
}
}
log.info("Retrieval result length: {}", retrievalResult.length()); log.info("Retrieval result length: {}", retrievalResult.length());
// 构建输出 // 构建输出
@@ -238,9 +247,9 @@ public class KnowledgeRetrievalNode extends AbstractWfNode {
bo.setVectorModelName(kb.getVectorModel()); bo.setVectorModelName(kb.getVectorModel());
bo.setBaseUrl(embModel.getApiHost()); bo.setBaseUrl(embModel.getApiHost());
// 节点明确选择的模式覆盖知识库配置,避免知识库开启混合检索时节点无法切回纯向量
String mode = config.getRetrievalMode() != null ? config.getRetrievalMode().toLowerCase() : "vector"; String mode = config.getRetrievalMode() != null ? config.getRetrievalMode().toLowerCase() : "vector";
boolean enableHybrid = "hybrid".equals(mode) boolean enableHybrid = "hybrid".equals(mode);
|| (kb.getEnableHybrid() != null && kb.getEnableHybrid() == 1);
bo.setEnableHybrid(enableHybrid); bo.setEnableHybrid(enableHybrid);
bo.setHybridAlpha(kb.getHybridAlpha()); bo.setHybridAlpha(kb.getHybridAlpha());
bo.setEnableRerank(kb.getEnableRerank() != null && kb.getEnableRerank() == 1); bo.setEnableRerank(kb.getEnableRerank() != null && kb.getEnableRerank() == 1);

View File

@@ -108,4 +108,18 @@ public class KnowledgeRetrievalNodeConfig {
* 用于对查询进行预处理或改写 * 用于对查询进行预处理或改写
*/ */
private String prompt; private String prompt;
/**
* 是否开启严格模式
* 开启后,当检索无结果时返回 defaultResponse;关闭则返回空字符串
*/
@JsonProperty("is_strict")
private Boolean isStrict = true;
/**
* 严格模式下的默认回复内容
* 当检索无结果且严格模式开启时,返回此内容
*/
@JsonProperty("default_response")
private String defaultResponse;
} }