Skip to content

Commit 327b6cc

Browse files
committed
refactor: adjust paragraph position indexing to start from 1
1 parent 4b4691d commit 327b6cc

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

apps/knowledge/serializers/paragraph.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,14 @@ def save(self, instance: Dict, with_valid=True, with_embedding=True):
259259
ProblemParagraphManage(problem_paragraph_object_list, knowledge_id)
260260
.to_problem_model_list())
261261
# 新加的在最上面
262-
paragraph.position = 0
262+
paragraph.position = 1
263263
paragraph.save()
264264
# 调整位置
265265
if 'position' in instance:
266266
if type(instance['position']) is not int:
267-
instance['position'] = 0
267+
instance['position'] = 1
268268
else:
269-
instance['position'] = 0
269+
instance['position'] = 1
270270

271271
ParagraphSerializers.AdjustPosition(data={
272272
'paragraph_id': str(paragraph.id),
@@ -498,9 +498,9 @@ def migrate(self, with_valid=True):
498498
paragraph_list = Paragraph.objects.filter(
499499
id__in=paragraph_id_list, document_id=target_document_id
500500
)
501-
# 将迁移的段落位置设置为从0开始的序号
501+
# 将迁移的段落位置设置为从1开始的序号
502502
for i, paragraph in enumerate(paragraph_list):
503-
paragraph.position = i
503+
paragraph.position = i + 1
504504
paragraph.save()
505505
# 不同数据集迁移
506506
else:
@@ -544,9 +544,9 @@ def migrate(self, with_valid=True):
544544
paragraph_list = Paragraph.objects.filter(
545545
id__in=pid_list, document_id=target_document_id
546546
)
547-
# 将迁移的段落位置设置为从0开始的序号
547+
# 将迁移的段落位置设置为从1开始的序号
548548
for i, paragraph in enumerate(paragraph_list):
549-
paragraph.position = i
549+
paragraph.position = i + 1
550550
paragraph.save()
551551
# 修改向量段落信息
552552
update_embedding_document_id(pid_list, target_document_id, target_knowledge_id, embedding_model_id)

0 commit comments

Comments
 (0)