from morphik import Morphikdb = Morphik()# Delete a document by its IDresult = db.delete_document("doc_123456")print(result["message"]) # "Document doc_123456 deleted successfully"
If you don’t know the document ID, you can use other methods to find it:
Copy
Ask AI
# List documents to find IDsdocs = db.list_documents(limit=10)for doc in docs: print(f"ID: {doc.external_id}, Filename: {doc.filename}")# Or get document by filenamedoc = db.get_document_by_filename("report.pdf")document_id = doc.external_id# Then delete itresult = db.delete_document(document_id)
For convenience, you can also use the delete_document_by_filename method if you know the filename but not the ID.
This operation requires appropriate permissions for the document.
Deleting a document that is part of an existing knowledge graph will not automatically update the graph. You may need to recreate or update the graph separately.