Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: segment resort in dataset retrieve by index_node_id_to_position (#721)

takatost654985177f95
diff --git a/api/core/tool/dataset_retriever_tool.py b/api/core/tool/dataset_retriever_tool.py
index 45c5a9f226c..35f15bbceb7 100644
--- a/api/core/tool/dataset_retriever_tool.py
+++ b/api/core/tool/dataset_retriever_tool.py
@@ -109,7 +109,11 @@ class DatasetRetrieverTool(BaseTool):
).all()
if segments:
- for segment in segments:
+ index_node_id_to_position = {id: position for position, id in enumerate(index_node_ids)}
+ sorted_segments = sorted(segments,
+ key=lambda segment: index_node_id_to_position.get(segment.index_node_id,
+ float('inf')))
+ for segment in sorted_segments:
if segment.answer:
document_context_list.append(f'question:{segment.content} \nanswer:{segment.answer}')
else: