@@ -988,6 +988,89 @@ These operations maintain data consistency across both the graph database and ve
988988
989989</details >
990990
991+ ## Delete Functions
992+
993+ LightRAG provides comprehensive deletion capabilities, allowing you to delete documents, entities, and relationships.
994+
995+ <details >
996+ <summary > <b >Delete Entities</b > </summary >
997+
998+ You can delete entities by their name along with all associated relationships:
999+
1000+ ``` python
1001+ # Delete entity and all its relationships (synchronous version)
1002+ rag.delete_by_entity(" Google" )
1003+
1004+ # Asynchronous version
1005+ await rag.adelete_by_entity(" Google" )
1006+ ```
1007+
1008+ When deleting an entity:
1009+ - Removes the entity node from the knowledge graph
1010+ - Deletes all associated relationships
1011+ - Removes related embedding vectors from the vector database
1012+ - Maintains knowledge graph integrity
1013+
1014+ </details >
1015+
1016+ <details >
1017+ <summary > <b >Delete Relations</b > </summary >
1018+
1019+ You can delete relationships between two specific entities:
1020+
1021+ ``` python
1022+ # Delete relationship between two entities (synchronous version)
1023+ rag.delete_by_relation(" Google" , " Gmail" )
1024+
1025+ # Asynchronous version
1026+ await rag.adelete_by_relation(" Google" , " Gmail" )
1027+ ```
1028+
1029+ When deleting a relationship:
1030+ - Removes the specified relationship edge
1031+ - Deletes the relationship's embedding vector from the vector database
1032+ - Preserves both entity nodes and their other relationships
1033+
1034+ </details >
1035+
1036+ <details >
1037+ <summary > <b >Delete by Document ID</b > </summary >
1038+
1039+ You can delete an entire document and all its related knowledge through document ID:
1040+
1041+ ``` python
1042+ # Delete by document ID (asynchronous version)
1043+ await rag.adelete_by_doc_id(" doc-12345" )
1044+ ```
1045+
1046+ Optimized processing when deleting by document ID:
1047+ - ** Smart Cleanup** : Automatically identifies and removes entities and relationships that belong only to this document
1048+ - ** Preserve Shared Knowledge** : If entities or relationships exist in other documents, they are preserved and their descriptions are rebuilt
1049+ - ** Cache Optimization** : Clears related LLM cache to reduce storage overhead
1050+ - ** Incremental Rebuilding** : Reconstructs affected entity and relationship descriptions from remaining documents
1051+
1052+ The deletion process includes:
1053+ 1 . Delete all text chunks related to the document
1054+ 2 . Identify and delete entities and relationships that belong only to this document
1055+ 3 . Rebuild entities and relationships that still exist in other documents
1056+ 4 . Update all related vector indexes
1057+ 5 . Clean up document status records
1058+
1059+ Note: Deletion by document ID is an asynchronous operation as it involves complex knowledge graph reconstruction processes.
1060+
1061+ </details >
1062+
1063+ ** Important Reminders:**
1064+
1065+ 1 . ** Irreversible Operations** : All deletion operations are irreversible, please use with caution
1066+ 2 . ** Performance Considerations** : Deleting large amounts of data may take some time, especially deletion by document ID
1067+ 3 . ** Data Consistency** : Deletion operations automatically maintain consistency between the knowledge graph and vector database
1068+ 4 . ** Backup Recommendations** : Consider backing up data before performing important deletion operations
1069+
1070+ ** Batch Deletion Recommendations:**
1071+ - For batch deletion operations, consider using asynchronous methods for better performance
1072+ - For large-scale deletions, consider processing in batches to avoid excessive system load
1073+
9911074## Entity Merging
9921075
9931076<details >
0 commit comments