Skip to content

Conversation

@Parteeksachdeva
Copy link

@Parteeksachdeva Parteeksachdeva commented Dec 31, 2025

Summary

This PR fixes an issue where orphaned Entity nodes were not cleaned up when deleting episodes via remove_episode().

Due to LLM non-determinism, Graphiti can sometimes create Entity nodes without corresponding MENTIONS relationships. These entities were invisible to the existing cleanup logic and accumulated indefinitely in the database.

Type of Change

  • Bug fix
  • New feature
  • Performance improvement
  • Documentation/Tests

Objective

Fix an issue where Entity nodes without MENTIONS relationships are not cleaned up when an episode is deleted.

Due to LLM non-determinism or partial ingestion failures, entities can be created without corresponding MENTIONS edges. The existing remove_episode() logic only considers entities reachable via MENTIONS, causing these orphaned entities to persist indefinitely and bloat the database.

This PR adds a post-deletion cleanup step that removes all Entity nodes in the same group_id that have zero MENTIONS relationships after an episode is deleted.

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • All existing tests pass

Breaking Changes

  • This PR contains breaking changes

No breaking changes. Behavior is strictly additive and limited to cleanup during episode deletion

Checklist

  • Code follows project style guidelines (make lint passes)
  • Self-review completed
  • Documentation updated where necessary
  • No secrets or sensitive information committed

Related Issues

Closes #1083

@danielchalef
Copy link
Member

danielchalef commented Dec 31, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Parteeksachdeva
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

danielchalef added a commit that referenced this pull request Dec 31, 2025
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.

Orphaned entities not cleaned up during episode deletion due to missing MENTIONS relationships

2 participants