fix: stabilize knowledge compilation navigation updates (#17345)

This commit is contained in:
buua436
2026-07-24 17:48:27 +08:00
committed by GitHub
parent 1f97823ee3
commit 2ba7ccecaf
12 changed files with 181 additions and 76 deletions

View File

@@ -492,6 +492,20 @@ class DocumentService(CommonService):
except Exception as e:
logging.warning(f"Failed to delete thumbnail for document {doc.id}: {e}")
# Prune this doc's line from the KB's tree-kind navigation before the
# broad doc_id delete below removes the nav_doc row needed to locate
# and update its parent cluster.
try:
from rag.advanced_rag.knowlege_compile.dataset_nav import (
remove_dataset_nav_doc_sync,
)
remove_dataset_nav_doc_sync(tenant_id, doc.kb_id, doc.id)
except Exception as e:
logging.warning(
f"Failed to prune dataset_nav for document {doc.id}: {e}",
)
# Delete chunks from doc store - this is critical, log errors
try:
settings.docStoreConn.delete({"doc_id": doc.id}, chunk_index_name, doc.kb_id)
@@ -507,20 +521,6 @@ class DocumentService(CommonService):
except Exception as e:
logging.warning(f"Failed to clean up artifact products for document {doc.id}: {e}")
# Prune this doc's line from the KB's tree-kind navigation
# markdown (best-effort — the markdown is a downstream artifact,
# and failure here must not block the document delete).
try:
from rag.advanced_rag.knowlege_compile.dataset_nav import (
remove_dataset_nav_doc_sync,
)
remove_dataset_nav_doc_sync(tenant_id, doc.kb_id, doc.id)
except Exception as e:
logging.warning(
f"Failed to prune dataset_nav for document {doc.id}: {e}",
)
# Delete document metadata (non-critical, log and continue)
try:
DocMetadataService.delete_document_metadata(doc.id, doc.kb_id, tenant_id)