diff --git a/.semversioner/next-release/patch-20251110004953346654.json b/.semversioner/next-release/patch-20251110004953346654.json new file mode 100644 index 0000000000..ca5e346d50 --- /dev/null +++ b/.semversioner/next-release/patch-20251110004953346654.json @@ -0,0 +1,4 @@ +{ + "type": "patch", + "description": "Fix type mismatch in DynamicCommunitySelection when checking children communities. Convert child IDs to string to match self.reports key type (fixes #2004)" +} diff --git a/graphrag/query/context_builder/dynamic_community_selection.py b/graphrag/query/context_builder/dynamic_community_selection.py index 904478f738..3981e5c8e5 100644 --- a/graphrag/query/context_builder/dynamic_community_selection.py +++ b/graphrag/query/context_builder/dynamic_community_selection.py @@ -123,8 +123,10 @@ async def select(self, query: str) -> tuple[list[CommunityReport], dict[str, Any # TODO check why some sub_communities are NOT in report_df if community in self.communities: for child in self.communities[community].children: - if child in self.reports: - communities_to_rate.append(child) + # Convert child to string to match self.reports key type + child_str = str(child) + if child_str in self.reports: + communities_to_rate.append(child_str) else: logger.debug( "dynamic community selection: cannot find community %s in reports",