Refact: Add Entity Identifier Length Truncation to Prevent Storage Failures #2245
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Entity Identifier Length Truncation to Prevent Storage Failures
Problem
LLM extraction occasionally generates extremely long entity names that can cause failures in downstream storage systems:
Without truncation, a single malformed LLM extraction could crash the entire ingestion pipeline or create unqueryable knowledge graphs.
Solution
This PR implements defensive truncation of entity identifiers at the extraction boundary:
Changes
lightrag/constants.pyDEFAULT_ENTITY_NAME_MAX_LENGTH = 256constant to define the maximum allowed lengthlightrag/operate.py_truncate_entity_identifier()helper function that:_process_extraction_result()to apply truncation to:entity_name)src_id)tgt_id)Key Design Decisions
Why 256 characters?
Why truncate at extraction time?
Why simple prefix truncation?
Example Warning Log
Backward Compatibility
✅ Fully backward compatible
Potential Considerations
These edge cases are acceptable trade-offs for production stability. Future enhancements could make the limit configurable or add hash-based collision detection if needed.