From 0b141fb952fe3996ffcba72b10100a4aa6d212b3 Mon Sep 17 00:00:00 2001 From: mengyonghao <1533512157@qq.com> Date: Thu, 25 Dec 2025 14:47:22 +0800 Subject: [PATCH] fix(workflow): fix missing re-ranking for hybrid retrieval results in knowledge base node, add config example --- api/app/core/workflow/nodes/if_else/node.py | 13 ++++++++++++- api/app/core/workflow/nodes/knowledge/config.py | 16 ++++++++++++++++ api/app/core/workflow/nodes/knowledge/node.py | 3 ++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/api/app/core/workflow/nodes/if_else/node.py b/api/app/core/workflow/nodes/if_else/node.py index aedf0727..579c2840 100644 --- a/api/app/core/workflow/nodes/if_else/node.py +++ b/api/app/core/workflow/nodes/if_else/node.py @@ -158,10 +158,21 @@ class IfElseNode(BaseNode): async def execute(self, state: WorkflowState) -> Any: """ + Execute the conditional branching logic of the node. + + Evaluates the node's configured conditional expressions (expressions) in order. + Once a condition is satisfied, it returns the corresponding CASE identifier. + If none of the conditions match, it returns the default last CASE. + + Args: + state (WorkflowState): The current workflow state, containing variables, messages, node outputs, etc. + + Returns: + str: The matched branch identifier, e.g., 'CASE1', 'CASE2', ..., used for node transitions. """ expressions = self.build_conditional_edge_expressions() for i in range(len(expressions)): logger.info(expressions[i]) if self._evaluate_condition(expressions[i], state): - return f'CASE{i+1}' + return f'CASE{i + 1}' return f'CASE{len(expressions)}' diff --git a/api/app/core/workflow/nodes/knowledge/config.py b/api/app/core/workflow/nodes/knowledge/config.py index 530116ff..09c23855 100644 --- a/api/app/core/workflow/nodes/knowledge/config.py +++ b/api/app/core/workflow/nodes/knowledge/config.py @@ -36,3 +36,19 @@ class KnowledgeRetrievalNodeConfig(BaseNodeConfig): default=RetrieveType.PARTICIPLE, description="Retrieve type" ) + + class Config: + json_schema_extra = { + "examples": [ + { + "query": "{{sys.message}}", + "kb_ids": [ + "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + ], + "similarity_threshold": 0.2, + "vector_similarity_weight": 0.3, + "top_k": 1, + "retrieve_type": "hybrid" + } + ] + } diff --git a/api/app/core/workflow/nodes/knowledge/node.py b/api/app/core/workflow/nodes/knowledge/node.py index 10b877d8..319a0b88 100644 --- a/api/app/core/workflow/nodes/knowledge/node.py +++ b/api/app/core/workflow/nodes/knowledge/node.py @@ -163,5 +163,6 @@ class KnowledgeRetrievalNode(BaseNode): indices=indices, score_threshold=self.typed_config.similarity_threshold) # Deduplicate hybrid retrieval results - rs = self._deduplicate_docs(rs1, rs2) + unique_rs = self._deduplicate_docs(rs1, rs2) + rs = vector_service.rerank(query=query, docs=unique_rs, top_k=self.typed_config.top_k) return [chunk.model_dump() for chunk in rs]