diff --git a/.semversioner/next-release/patch-20241009221929632018.json b/.semversioner/next-release/patch-20241009221929632018.json new file mode 100644 index 0000000000..ec560627a9 --- /dev/null +++ b/.semversioner/next-release/patch-20241009221929632018.json @@ -0,0 +1,4 @@ +{ + "type": "patch", + "description": "Small cleanup in community context history building" +} diff --git a/graphrag/query/structured_search/global_search/community_context.py b/graphrag/query/structured_search/global_search/community_context.py index d63320c85b..f5991526c0 100644 --- a/graphrag/query/structured_search/global_search/community_context.py +++ b/graphrag/query/structured_search/global_search/community_context.py @@ -87,13 +87,21 @@ def build_context( context_name=context_name, random_state=self.random_state, ) - if isinstance(community_context, list): - final_context = [ - f"{conversation_history_context}\n\n{context}" - for context in community_context - ] - else: - final_context = f"{conversation_history_context}\n\n{community_context}" + # Prepare context_prefix based on whether conversation_history_context exists + context_prefix = ( + f"{conversation_history_context}\n\n" + if conversation_history_context + else "" + ) + + final_context = ( + [f"{context_prefix}{context}" for context in community_context] + if isinstance(community_context, list) + else f"{context_prefix}{community_context}" + ) + + # Update the final context data with the provided community_context_data final_context_data.update(community_context_data) - return (final_context, final_context_data) + + return final_context, final_context_data