From 9ca7ff6cf9c92d0f087d1b61fa2ef5af64d4481e Mon Sep 17 00:00:00 2001 From: FuJiaJie123 <75252569+FuJiaJie123@users.noreply.github.com> Date: Fri, 18 Apr 2025 03:22:24 +0800 Subject: [PATCH] Fix bug of label_propagation (#302) Fix bug of issue #297 --- .../utils/maintenance/community_operations.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/graphiti_core/utils/maintenance/community_operations.py b/graphiti_core/utils/maintenance/community_operations.py index f814b53e..4d30544e 100644 --- a/graphiti_core/utils/maintenance/community_operations.py +++ b/graphiti_core/utils/maintenance/community_operations.py @@ -101,9 +101,13 @@ def label_propagation(projection: dict[str, list[Neighbor]]) -> list[list[str]]: ] community_lst.sort(reverse=True) - community_candidate = community_lst[0][1] if len(community_lst) > 0 else -1 - - new_community = max(community_candidate, curr_community) + candidate_rank, community_candidate = ( + community_lst[0] if community_lst else (0, -1) + ) + if community_candidate != -1 and candidate_rank > 1: + new_community = community_candidate + else: + new_community = max(community_candidate, curr_community) new_community_map[uuid] = new_community