fix(workflow): fix missing re-ranking for hybrid retrieval results in knowledge base node, add config example

This commit is contained in:
mengyonghao
2025-12-25 14:47:22 +08:00
parent aef7ae2cce
commit 0b141fb952
3 changed files with 30 additions and 2 deletions

View File

@@ -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)}'

View File

@@ -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"
}
]
}

View File

@@ -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]