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:position error when creating segments (#10706)

jarvis2f5ff02b469ff7
diff --git a/api/services/dataset_service.py b/api/services/dataset_service.py
index 8562dad1d3e..806dbdf8c52 100644
--- a/api/services/dataset_service.py
+++ b/api/services/dataset_service.py
@@ -1458,6 +1458,7 @@ class SegmentService:
pre_segment_data_list = []
segment_data_list = []
keywords_list = []
+ position = max_position + 1 if max_position else 1
for segment_item in segments:
content = segment_item["content"]
doc_id = str(uuid.uuid4())
@@ -1475,7 +1476,7 @@ class SegmentService:
document_id=document.id,
index_node_id=doc_id,
index_node_hash=segment_hash,
- position=max_position + 1 if max_position else 1,
+ position=position,
content=content,
word_count=len(content),
tokens=tokens,
@@ -1490,6 +1491,7 @@ class SegmentService:
increment_word_count += segment_document.word_count
db.session.add(segment_document)
segment_data_list.append(segment_document)
+ position += 1
pre_segment_data_list.append(segment_document)
if "keywords" in segment_item: