graphrag icon indicating copy to clipboard operation
graphrag copied to clipboard

Fix type mismatch in DynamicCommunitySelection children lookup

Open KeonhoChu opened this issue 1 month ago • 1 comments

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].children were not matching keys in self.reports dictionary due to type inconsistency
    • Added explicit string conversion (str(child)) to ensure child IDs match the self.reports key type
    • Added explanatory comment for clarity

Root Cause:

  • Community.children contains IDs that may be loaded as integers
  • CommunityReport.community_id is defined as str type
  • self.reports dictionary is keyed by community_id (strings)
  • The membership test if child in self.reports always 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)

KeonhoChu avatar Nov 10 '25 01:11 KeonhoChu

@microsoft-github-policy-service agree

KeonhoChu avatar Nov 10 '25 01:11 KeonhoChu