Skip to content

Commit 23a4067

Browse files
committed
refactor: remove processor version references from document handling
feat: add resource type field to document serializers and update processor version handling refactor: remove image asset metadata fields feat: track image asset metadata and recall fix: harden incremental knowledge synchronization feat: enhance asset processing by adding visual text retrieval and improving embedding handling feat: enhance image handling by adding upstream knowledge image retrieval and recall tracking
1 parent f7ef6aa commit 23a4067

26 files changed

Lines changed: 1414 additions & 292 deletions

apps/application/flow/i_step_node.py

Lines changed: 26 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
KnowledgeSyncStatus,
2727
KnowledgeSyncType,
2828
KnowledgeType,
29-
Paragraph,
3029
)
3130
from knowledge.models.knowledge_action import KnowledgeAction, State
31+
from knowledge.services.workflow_sync import merge_workflow_incremental_snapshot
3232
from rest_framework import serializers
3333
from rest_framework.exceptions import ErrorDetail, ValidationError
3434
from tools.models import ToolRecord
@@ -156,77 +156,42 @@ def handler(self, workflow):
156156
if self.sync_log_id is not None:
157157
sync_log = QuerySet(KnowledgeSyncLog).filter(id=self.sync_log_id).first()
158158
if sync_log is not None:
159-
new_documents = list(
160-
QuerySet(Document).filter(
161-
knowledge_id=sync_log.knowledge_id,
162-
type=KnowledgeType.WORKFLOW,
163-
resource_type=DocumentResourceType.DOCUMENT,
164-
create_time__gte=sync_log.create_time,
165-
)
166-
)
167-
synced_count = len(new_documents)
168-
skipped_count = 0
169159
if (
170160
state == State.SUCCESS
171161
and sync_log.sync_type == KnowledgeSyncType.INCREMENTAL
172162
and self.document_cleanup is not None
173163
):
174-
old_documents = list(
175-
QuerySet(Document).filter(
164+
stats = merge_workflow_incremental_snapshot(sync_log)
165+
else:
166+
stats = {
167+
"total_count": QuerySet(Document)
168+
.filter(
176169
knowledge_id=sync_log.knowledge_id,
177-
type=KnowledgeType.WORKFLOW,
178170
resource_type=DocumentResourceType.DOCUMENT,
179-
create_time__lt=sync_log.create_time,
180171
)
181-
)
182-
old_by_name = {}
183-
for document in old_documents:
184-
old_by_name.setdefault(document.name, []).append(document)
185-
for new_document in new_documents:
186-
matched = old_by_name.get(new_document.name, [])
187-
if not matched:
188-
continue
189-
new_content = list(
190-
QuerySet(Paragraph)
191-
.filter(document_id=new_document.id)
192-
.order_by("position")
193-
.values_list("title", "content")
194-
)
195-
unchanged = next(
196-
(
197-
old_document
198-
for old_document in matched
199-
if list(
200-
QuerySet(Paragraph)
201-
.filter(document_id=old_document.id)
202-
.order_by("position")
203-
.values_list("title", "content")
204-
)
205-
== new_content
206-
),
207-
None,
172+
.count(),
173+
"synced_count": QuerySet(Document)
174+
.filter(
175+
knowledge_id=sync_log.knowledge_id,
176+
type=KnowledgeType.WORKFLOW,
177+
resource_type=DocumentResourceType.DOCUMENT,
178+
create_time__gte=sync_log.create_time,
208179
)
209-
if unchanged is not None:
210-
self.document_cleanup([new_document.id])
211-
synced_count -= 1
212-
skipped_count += 1
213-
else:
214-
self.document_cleanup([document.id for document in matched])
215-
total_count = (
216-
QuerySet(Document)
217-
.filter(
218-
knowledge_id=sync_log.knowledge_id,
219-
resource_type=DocumentResourceType.DOCUMENT,
220-
)
221-
.count()
222-
)
180+
.count(),
181+
"skipped_count": 0,
182+
"deleted_count": sync_log.deleted_count,
183+
"failed_count": 0 if state == State.SUCCESS else 1,
184+
}
223185
is_success = state == State.SUCCESS
224186
QuerySet(KnowledgeSyncLog).filter(id=sync_log.id).update(
225-
status=KnowledgeSyncStatus.SUCCESS if is_success else KnowledgeSyncStatus.FAILURE,
226-
total_count=total_count,
227-
synced_count=synced_count,
228-
skipped_count=skipped_count,
229-
failed_count=0 if is_success else 1,
187+
status=KnowledgeSyncStatus.SUCCESS
188+
if is_success and not stats["failed_count"]
189+
else KnowledgeSyncStatus.FAILURE,
190+
total_count=stats["total_count"],
191+
synced_count=stats["synced_count"],
192+
skipped_count=stats["skipped_count"],
193+
deleted_count=stats["deleted_count"],
194+
failed_count=stats["failed_count"],
230195
duration_ms=max(0, round(run_time * 1000)),
231196
message=f"Workflow action {self.knowledge_action_id}: {state}",
232197
)

0 commit comments

Comments
 (0)