MCPcopy Index your code
hub / github.com/1Panel-dev/MaxKB / delete

Method delete

apps/knowledge/serializers/document.py:823–840  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

821
822 @transaction.atomic
823 def delete(self):
824 self.is_valid(raise_exception=True)
825 document_id = self.data.get("document_id")
826 source_file_ids = [
827 doc["meta"].get("source_file_id") for doc in Document.objects.filter(id=document_id).values("meta")
828 ]
829 QuerySet(File).filter(id__in=source_file_ids).delete()
830 QuerySet(File).filter(source_id=document_id, source_type=FileSourceType.DOCUMENT).delete()
831 paragraph_ids = QuerySet(model=Paragraph).filter(document_id=document_id).values_list("id", flat=True)
832 # 删除问题
833 delete_problems_and_mappings(paragraph_ids)
834 # 删除段落
835 QuerySet(model=Paragraph).filter(document_id=document_id).delete()
836 # 删除向量库
837 delete_embedding_by_document(document_id)
838 QuerySet(model=DocumentTag).filter(document_id=document_id).delete()
839 QuerySet(model=Document).filter(id=document_id).delete()
840 return True
841
842 def refresh(self, state_list=None, with_valid=True):
843 if state_list is None:

Callers 4

syncMethod · 0.45
batch_deleteMethod · 0.45
delete_tagsMethod · 0.45
batch_delete_docs_tagMethod · 0.45

Calls 4

is_validMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected