Skip to content

Fix: Clean Residual Edges from VDB During Entity Deletion#2290

Merged
danielaskdd merged 1 commit intoHKUDS:mainfrom
danielaskdd:delete-residual-edges
Oct 30, 2025
Merged

Fix: Clean Residual Edges from VDB During Entity Deletion#2290
danielaskdd merged 1 commit intoHKUDS:mainfrom
danielaskdd:delete-residual-edges

Conversation

@danielaskdd
Copy link
Collaborator

Fix: Clean Residual Edges from VDB During Entity Deletion

🐛 Problem

When deleting entities from the knowledge graph, the system was only removing nodes from the graph structure but not cleaning up associated edge data from, causing data inconsistencies between Graph DB and VDB.

  • Vector database (relationships_vdb)
  • Relation chunks storage (relation_chunks)

This resulted in orphaned edge is cause by manully editing entity name.

✅ Solution

This PR adds comprehensive edge cleanup logic before node deletion:

  1. Edge Tracking: Collect all edges connected to entities being deleted into a deduplicated set with normalized representation (sorted tuples for consistency)

  2. VDB Cleanup: Delete edge vectors from relationships_vdb using computed relationship IDs for both directions (src→tgt and tgt→src)

  3. Storage Cleanup: Remove relation chunk tracking data using make_relation_chunk_key

  4. Improved Logging:

    • Fixed edge direction in warning message ({src} <-- {tgt} instead of {tgt} --> {src})
    • Added info log showing number of cleaned residual edges

📝 Changes

  • File: lightrag/lightrag.py
  • Location: Entity deletion logic in the cleanup process
  • Lines Modified: ~30 lines added/modified

🧪 Testing

Tested with entity deletion scenarios to verify:

  • All edge data is properly cleaned from VDB
  • Relation chunk storage is correctly updated
  • No orphaned data remains after deletion
  • Log messages provide clear feedback

…hips

- Track edges to delete in set
- Clean VDB before node deletion
- Remove from relation chunks storage
- Prevent orphaned relationship data
@danielaskdd danielaskdd merged commit 94cdbe7 into HKUDS:main Oct 30, 2025
1 check passed
@danielaskdd danielaskdd deleted the delete-residual-edges branch October 30, 2025 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant