graphrag
graphrag copied to clipboard
Fix type mismatch in DynamicCommunitySelection children lookup
Description
Fixes a type mismatch bug in DynamicCommunitySelection that prevented the algorithm from correctly traversing child communities during global search queries with dynamic_community_selection=True.
Related Issues
Fixes #2004
Proposed Changes
- Fixed type mismatch in
dynamic_community_selection.py(lines 125-129)- Child community IDs from
self.communities[community].childrenwere not matching keys inself.reportsdictionary due to type inconsistency - Added explicit string conversion (
str(child)) to ensure child IDs match theself.reportskey type - Added explanatory comment for clarity
- Child community IDs from
Root Cause:
Community.childrencontains IDs that may be loaded as integersCommunityReport.community_idis defined asstrtypeself.reportsdictionary is keyed bycommunity_id(strings)- The membership test
if child in self.reportsalways failed, causing all child communities to be skipped
Impact:
- Before fix: Only 10 out of 5,586 communities were referenced (stuck at level 0)
- After fix: 309 out of 5,586 communities are correctly traversed across multiple levels
Checklist
- [v] I have tested these changes locally (unit tests pass)
- [v] I have reviewed the code changes
- [v] I have updated the documentation (added inline comment explaining the fix)
- [v] I have added a semversioner changeset (patch level)
@microsoft-github-policy-service agree