fix(workflow): fix missing re-ranking for hybrid retrieval results in knowledge base node, add config example
This commit is contained in:
@@ -158,10 +158,21 @@ class IfElseNode(BaseNode):
|
|||||||
|
|
||||||
async def execute(self, state: WorkflowState) -> Any:
|
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()
|
expressions = self.build_conditional_edge_expressions()
|
||||||
for i in range(len(expressions)):
|
for i in range(len(expressions)):
|
||||||
logger.info(expressions[i])
|
logger.info(expressions[i])
|
||||||
if self._evaluate_condition(expressions[i], state):
|
if self._evaluate_condition(expressions[i], state):
|
||||||
return f'CASE{i+1}'
|
return f'CASE{i + 1}'
|
||||||
return f'CASE{len(expressions)}'
|
return f'CASE{len(expressions)}'
|
||||||
|
|||||||
@@ -36,3 +36,19 @@ class KnowledgeRetrievalNodeConfig(BaseNodeConfig):
|
|||||||
default=RetrieveType.PARTICIPLE,
|
default=RetrieveType.PARTICIPLE,
|
||||||
description="Retrieve type"
|
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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -163,5 +163,6 @@ class KnowledgeRetrievalNode(BaseNode):
|
|||||||
indices=indices,
|
indices=indices,
|
||||||
score_threshold=self.typed_config.similarity_threshold)
|
score_threshold=self.typed_config.similarity_threshold)
|
||||||
# Deduplicate hybrid retrieval results
|
# 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]
|
return [chunk.model_dump() for chunk in rs]
|
||||||
|
|||||||
Reference in New Issue
Block a user