Skip to content

Commit

Permalink
Fix dynamic community selection in global search
Browse files Browse the repository at this point in the history
  • Loading branch information
AlonsoGuevara committed Nov 26, 2024
1 parent 6d21ef2 commit 0c4fab7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .semversioner/next-release/patch-20241126205530514149.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "patch",
"description": "Fix Global Search with dynamic Community selection bug"
}
6 changes: 4 additions & 2 deletions graphrag/query/context_builder/dynamic_community_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ def __init__(
}
# mapping from level to communities
self.levels: dict[str, list[str]] = {}

for community in communities:
if community.level not in self.levels:
self.levels[community.level] = []
if community.id in self.reports:
self.levels[community.level].append(community.id)
if community.short_id in self.reports:
self.levels[community.level].append(community.short_id)

# start from root communities (level 0)
self.starting_communities = self.levels["0"]
Expand All @@ -100,6 +101,7 @@ async def select(self, query: str) -> tuple[list[CommunityReport], dict[str, Any
"output_tokens": 0,
}
relevant_communities = set()

while queue:
gather_results = await asyncio.gather(*[
rate_relevancy(
Expand Down
11 changes: 6 additions & 5 deletions graphrag/query/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,11 @@ def get_global_search_engine(

dynamic_community_selection_kwargs = {}
if dynamic_community_selection:
gs_config = config.global_search
_config = deepcopy(config)
_config.llm.model = _config.llm.deployment_name = gs_config.dynamic_search_llm
# TODO: Allow for another llm definition only for Global Search to leverage -mini models

dynamic_community_selection_kwargs.update({
"llm": get_llm(_config),
"token_encoder": tiktoken.encoding_for_model(gs_config.dynamic_search_llm),
"llm": get_llm(config),
"token_encoder": tiktoken.encoding_for_model(config.llm.model),
"keep_parent": gs_config.dynamic_search_keep_parent,
"num_repeats": gs_config.dynamic_search_num_repeats,
"use_summary": gs_config.dynamic_search_use_summary,
Expand All @@ -119,6 +118,8 @@ def get_global_search_engine(
"max_level": gs_config.dynamic_search_max_level,
})

print(dynamic_community_selection_kwargs)

return GlobalSearch(
llm=get_llm(config),
map_system_prompt=map_system_prompt,
Expand Down

0 comments on commit 0c4fab7

Please sign in to comment.