from morphik import Morphikdb = Morphik()# Delete a document by its filenameresult = db.delete_document_by_filename("report.pdf")print(result["message"]) # "Document doc_123456 deleted successfully"
If multiple documents have the same filename, this method will delete the most recently updated one. To delete a specific document when duplicates exist, use delete_document with the exact document ID instead.
Copy
Ask AI
# To handle multiple documents with the same filenamedocs = db.list_documents()# Find all documents with a specific filenamematching_docs = [doc for doc in docs if doc.filename == "report.pdf"]# Review themfor doc in matching_docs: print(f"ID: {doc.external_id}, Created: {doc.system_metadata.get('created_at')}")# Delete a specific one by IDresult = db.delete_document(matching_docs[0].external_id)
This operation requires appropriate permissions for the document.
If no document exists with the specified filename, a ValueError will be raised.
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.