Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphrag integration #4612

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e3e8f45
add initial global search draft
lpinheiroms Dec 7, 2024
8242378
add graphrag dep
lpinheiroms Dec 9, 2024
fb2fb19
Merge branch 'main' into lpinheiro/feat/add-graphrag-tools
lpinheiroms Dec 10, 2024
a13c18b
fix local search embedding
lpinheiroms Dec 17, 2024
8f3c484
linting
lpinheiroms Dec 17, 2024
0c05047
add from config constructor
lpinheiroms Dec 17, 2024
0e53f91
Merge branch 'main' into lpinheiro/feat/add-graphrag-tools
lspinheiro Dec 17, 2024
c1e7ea2
remove draft notebook
lpinheiroms Dec 17, 2024
a8b38ad
Merge branch 'main' into lpinheiro/feat/add-graphrag-tools
lspinheiro Dec 19, 2024
6d61c8e
update config factory and add docstrings
lpinheiroms Dec 20, 2024
1c4ed3d
add graphrag sample
lpinheiroms Dec 20, 2024
95f329c
add sample prompts
lpinheiroms Dec 20, 2024
3bc104b
update readme
lpinheiroms Dec 20, 2024
2ae6812
Merge branch 'main' into lpinheiro/feat/add-graphrag-tools
lspinheiro Dec 20, 2024
33523df
update deps
lpinheiroms Dec 20, 2024
8080ddb
Add API docs
ekzhu Dec 30, 2024
603c1c9
Update python/samples/agentchat_graphrag/requirements.txt
ekzhu Dec 30, 2024
934230b
Update python/samples/agentchat_graphrag/requirements.txt
ekzhu Dec 30, 2024
1c5fcd3
merge main, fix conflicts
lpinheiroms Dec 30, 2024
4f0c71f
update docstrings with snippet and doc ref
lpinheiroms Dec 30, 2024
e3dc1f9
lint
lpinheiroms Dec 30, 2024
f24fb6c
improve set up instructions in docstring
lpinheiroms Jan 3, 2025
4a5d611
lint
lpinheiroms Jan 3, 2025
74a2a23
Merge branch 'main' into lpinheiro/feat/add-graphrag-tools
lpinheiroms Jan 3, 2025
cac2aef
update lock
lpinheiroms Jan 3, 2025
e42f027
Update python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_gl…
lspinheiro Jan 4, 2025
e60a9aa
Update python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_lo…
lspinheiro Jan 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/packages/autogen-core/docs/src/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ python/autogen_ext.teams.magentic_one
python/autogen_ext.models.openai
python/autogen_ext.models.replay
python/autogen_ext.tools.langchain
python/autogen_ext.tools.graphrag
python/autogen_ext.code_executors.local
python/autogen_ext.code_executors.docker
python/autogen_ext.code_executors.azure
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
autogen\_ext.tools.graphrag
===========================


.. automodule:: autogen_ext.tools.graphrag
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions python/packages/autogen-ext/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ file-surfer = [
"autogen-agentchat==0.4.0.dev13",
"markitdown>=0.0.1a2",
]
graphrag = ["graphrag>=1.0.1"]
web-surfer = [
"autogen-agentchat==0.4.0.dev13",
"playwright>=1.48.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from ._config import (

Check warning on line 1 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/__init__.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/__init__.py#L1

Added line #L1 was not covered by tests
EmbeddingConfig,
GlobalContextConfig,
GlobalDataConfig,
LocalContextConfig,
LocalDataConfig,
MapReduceConfig,
SearchConfig,
)
from ._global_search import GlobalSearchTool
from ._local_search import LocalSearchTool

Check warning on line 11 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/__init__.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/__init__.py#L10-L11

Added lines #L10 - L11 were not covered by tests

__all__ = [

Check warning on line 13 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/__init__.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/__init__.py#L13

Added line #L13 was not covered by tests
"GlobalSearchTool",
"LocalSearchTool",
"GlobalDataConfig",
"LocalDataConfig",
"GlobalContextConfig",
"LocalContextConfig",
"MapReduceConfig",
"SearchConfig",
"EmbeddingConfig",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from typing import Callable, Literal, Optional

Check warning on line 1 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py#L1

Added line #L1 was not covered by tests

from pydantic import BaseModel

Check warning on line 3 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py#L3

Added line #L3 was not covered by tests


class DataConfig(BaseModel):
input_dir: str
entity_table: str = "create_final_nodes"
entity_embedding_table: str = "create_final_entities"
community_level: int = 2

Check warning on line 10 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py#L6-L10

Added lines #L6 - L10 were not covered by tests


class GlobalDataConfig(DataConfig):
community_table: str = "create_final_communities"
community_report_table: str = "create_final_community_reports"

Check warning on line 15 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py#L13-L15

Added lines #L13 - L15 were not covered by tests


class LocalDataConfig(DataConfig):
relationship_table: str = "create_final_relationships"
text_unit_table: str = "create_final_text_units"

Check warning on line 20 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py#L18-L20

Added lines #L18 - L20 were not covered by tests


class ContextConfig(BaseModel):
max_data_tokens: int = 8000

Check warning on line 24 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py#L23-L24

Added lines #L23 - L24 were not covered by tests


class GlobalContextConfig(ContextConfig):
use_community_summary: bool = False
shuffle_data: bool = True
include_community_rank: bool = True
min_community_rank: int = 0
community_rank_name: str = "rank"
include_community_weight: bool = True
community_weight_name: str = "occurrence weight"
normalize_community_weight: bool = True
max_data_tokens: int = 12000

Check warning on line 36 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py#L27-L36

Added lines #L27 - L36 were not covered by tests


class LocalContextConfig(ContextConfig):
text_unit_prop: float = 0.5
community_prop: float = 0.25
include_entity_rank: bool = True
rank_description: str = "number of relationships"
include_relationship_weight: bool = True
relationship_ranking_attribute: str = "rank"

Check warning on line 45 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py#L39-L45

Added lines #L39 - L45 were not covered by tests


class MapReduceConfig(BaseModel):
map_max_tokens: int = 1000
map_temperature: float = 0.0
reduce_max_tokens: int = 2000
reduce_temperature: float = 0.0
allow_general_knowledge: bool = False
json_mode: bool = False
response_type: str = "multiple paragraphs"

Check warning on line 55 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py#L48-L55

Added lines #L48 - L55 were not covered by tests


class SearchConfig(BaseModel):
max_tokens: int = 1500
temperature: float = 0.0
response_type: str = "multiple paragraphs"

Check warning on line 61 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py#L58-L61

Added lines #L58 - L61 were not covered by tests


class EmbeddingConfig(BaseModel):
api_key: Optional[str] = None
model: str
api_base: Optional[str] = None
deployment_name: Optional[str] = None
api_version: Optional[str] = None
api_type: Literal["azure", "openai"] = "openai"
organization: Optional[str] = None
azure_ad_token_provider: Optional[Callable[[], str]] = None
max_retries: int = 10
request_timeout: float = 180.0

Check warning on line 74 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_config.py#L64-L74

Added lines #L64 - L74 were not covered by tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
# mypy: disable-error-code="no-any-unimported,misc"
from pathlib import Path

Check warning on line 2 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L2

Added line #L2 was not covered by tests

import pandas as pd
import tiktoken
from autogen_core import CancellationToken
from autogen_core.tools import BaseTool
from graphrag.config.config_file_loader import load_config_from_file
from graphrag.query.indexer_adapters import (

Check warning on line 9 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L4-L9

Added lines #L4 - L9 were not covered by tests
read_indexer_communities,
read_indexer_entities,
read_indexer_reports,
)
from graphrag.query.llm.base import BaseLLM
from graphrag.query.llm.get_client import get_llm
from graphrag.query.structured_search.global_search.community_context import GlobalCommunityContext
from graphrag.query.structured_search.global_search.search import GlobalSearch
from pydantic import BaseModel, Field

Check warning on line 18 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L14-L18

Added lines #L14 - L18 were not covered by tests

from ._config import GlobalContextConfig as ContextConfig
from ._config import GlobalDataConfig as DataConfig
from ._config import MapReduceConfig

Check warning on line 22 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L20-L22

Added lines #L20 - L22 were not covered by tests

_default_context_config = ContextConfig()
_default_mapreduce_config = MapReduceConfig()

Check warning on line 25 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L24-L25

Added lines #L24 - L25 were not covered by tests


class GlobalSearchToolArgs(BaseModel):
query: str = Field(..., description="The user query to perform global search on.")

Check warning on line 29 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L28-L29

Added lines #L28 - L29 were not covered by tests


class GlobalSearchToolReturn(BaseModel):
answer: str

Check warning on line 33 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L32-L33

Added lines #L32 - L33 were not covered by tests


class GlobalSearchTool(BaseTool[GlobalSearchToolArgs, GlobalSearchToolReturn]):

Check warning on line 36 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L36

Added line #L36 was not covered by tests
"""Enables running GraphRAG global search queries as an AutoGen tool.

This tool allows you to perform semantic search over a corpus of documents using the GraphRAG framework.
The search combines graph-based document relationships with semantic embeddings to find relevant information.

.. note::

This tool requires the :code:`graphrag` extra for the :code:`autogen-ext` package.
To install:

.. code-block:: bash

pip install "autogen-agentchat==0.4.0.dev12" "autogen-ext[graphrag]==0.4.0.dev12"
lspinheiro marked this conversation as resolved.
Show resolved Hide resolved

Before using this tool, you must complete the GraphRAG setup and indexing process:

1. Follow the GraphRAG documentation to initialize your project and settings
2. Configure and tune your prompts for the specific use case
3. Run the indexing process to generate the required data files
4. Ensure you have the settings.yaml file from the setup process

Please refer to the [GraphRAG documentation](https://microsoft.github.io/graphrag/)
for detailed instructions on completing these prerequisite steps.

Example usage with AssistantAgent:

.. code-block:: python

import asyncio
from autogen_ext.models.openai import AzureOpenAIChatCompletionClient
from autogen_ext.tools.graphrag import GlobalSearchTool
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
from autogen_agentchat.agents import AssistantAgent


async def main():
# Initialize the OpenAI client
openai_client = OpenAIChatCompletionClient(
model="gpt-4o-mini",
api_key="<api-key>",
)

# Set up global search tool
global_tool = GlobalSearchTool.from_settings(settings_path="./settings.yaml")
ekzhu marked this conversation as resolved.
Show resolved Hide resolved

# Create assistant agent with the global search tool
assistant_agent = AssistantAgent(
name="search_assistant",
tools=[global_tool],
model_client=openai_client,
system_message=(
"You are a tool selector AI assistant using the GraphRAG framework. "
"Your primary task is to determine the appropriate search tool to call based on the user's query. "
"For broader, abstract questions requiring a comprehensive understanding of the dataset, call the 'global_search' function."
),
)

# Run a sample query
query = "What is the overall sentiment of the community reports?"
response_stream = assistant_agent.run_stream(task=query)
async for msg in response_stream:
if hasattr(msg, "content"):
print(f"\nAgent response: {msg.content}")


if __name__ == "__main__":
asyncio.run(main())

Args:
token_encoder (tiktoken.Encoding): The tokenizer used for text encoding
llm (BaseLLM): The language model to use for search
data_config (DataConfig): Configuration for data source locations and settings
context_config (ContextConfig, optional): Configuration for context building. Defaults to default config.
mapreduce_config (MapReduceConfig, optional): Configuration for map-reduce operations. Defaults to default config.
"""

def __init__(

Check warning on line 113 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L113

Added line #L113 was not covered by tests
self,
token_encoder: tiktoken.Encoding,
llm: BaseLLM,
data_config: DataConfig,
context_config: ContextConfig = _default_context_config,
mapreduce_config: MapReduceConfig = _default_mapreduce_config,
):
super().__init__(

Check warning on line 121 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L121

Added line #L121 was not covered by tests
args_type=GlobalSearchToolArgs,
return_type=GlobalSearchToolReturn,
name="global_search_tool",
description="Perform a global search with given parameters using graphrag.",
)
# Use the provided LLM
self._llm = llm

Check warning on line 128 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L128

Added line #L128 was not covered by tests

# Load parquet files
community_df: pd.DataFrame = pd.read_parquet(f"{data_config.input_dir}/{data_config.community_table}.parquet") # type: ignore
entity_df: pd.DataFrame = pd.read_parquet(f"{data_config.input_dir}/{data_config.entity_table}.parquet") # type: ignore
report_df: pd.DataFrame = pd.read_parquet( # type: ignore

Check warning on line 133 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L131-L133

Added lines #L131 - L133 were not covered by tests
f"{data_config.input_dir}/{data_config.community_report_table}.parquet"
)
entity_embedding_df: pd.DataFrame = pd.read_parquet( # type: ignore

Check warning on line 136 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L136

Added line #L136 was not covered by tests
f"{data_config.input_dir}/{data_config.entity_embedding_table}.parquet"
)

communities = read_indexer_communities(community_df, entity_df, report_df)
reports = read_indexer_reports(report_df, entity_df, data_config.community_level)
entities = read_indexer_entities(entity_df, entity_embedding_df, data_config.community_level)

Check warning on line 142 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L140-L142

Added lines #L140 - L142 were not covered by tests

context_builder = GlobalCommunityContext(

Check warning on line 144 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L144

Added line #L144 was not covered by tests
community_reports=reports,
communities=communities,
entities=entities,
token_encoder=token_encoder,
)

context_builder_params = {

Check warning on line 151 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L151

Added line #L151 was not covered by tests
"use_community_summary": context_config.use_community_summary,
"shuffle_data": context_config.shuffle_data,
"include_community_rank": context_config.include_community_rank,
"min_community_rank": context_config.min_community_rank,
"community_rank_name": context_config.community_rank_name,
"include_community_weight": context_config.include_community_weight,
"community_weight_name": context_config.community_weight_name,
"normalize_community_weight": context_config.normalize_community_weight,
"max_tokens": context_config.max_data_tokens,
"context_name": "Reports",
}

map_llm_params = {

Check warning on line 164 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L164

Added line #L164 was not covered by tests
"max_tokens": mapreduce_config.map_max_tokens,
"temperature": mapreduce_config.map_temperature,
"response_format": {"type": "json_object"},
}

reduce_llm_params = {

Check warning on line 170 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L170

Added line #L170 was not covered by tests
"max_tokens": mapreduce_config.reduce_max_tokens,
"temperature": mapreduce_config.reduce_temperature,
}

self._search_engine = GlobalSearch(

Check warning on line 175 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L175

Added line #L175 was not covered by tests
llm=self._llm,
context_builder=context_builder,
token_encoder=token_encoder,
max_data_tokens=context_config.max_data_tokens,
map_llm_params=map_llm_params,
reduce_llm_params=reduce_llm_params,
allow_general_knowledge=mapreduce_config.allow_general_knowledge,
json_mode=mapreduce_config.json_mode,
context_builder_params=context_builder_params,
concurrent_coroutines=32,
response_type=mapreduce_config.response_type,
)

async def run(self, args: GlobalSearchToolArgs, cancellation_token: CancellationToken) -> GlobalSearchToolReturn:
result = await self._search_engine.asearch(args.query)
assert isinstance(result.response, str), "Expected response to be a string"
return GlobalSearchToolReturn(answer=result.response)

Check warning on line 192 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L189-L192

Added lines #L189 - L192 were not covered by tests

@classmethod
def from_settings(cls, settings_path: str | Path) -> "GlobalSearchTool":

Check warning on line 195 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L194-L195

Added lines #L194 - L195 were not covered by tests
"""Create a GlobalSearchTool instance from GraphRAG settings file.

Args:
settings_path: Path to the GraphRAG settings.yaml file

Returns:
An initialized GlobalSearchTool instance
"""
# Load GraphRAG config
config = load_config_from_file(settings_path)

Check warning on line 205 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L205

Added line #L205 was not covered by tests

# Initialize token encoder
token_encoder = tiktoken.get_encoding(config.encoding_model)

Check warning on line 208 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L208

Added line #L208 was not covered by tests

# Initialize LLM using graphrag's get_client
llm = get_llm(config)

Check warning on line 211 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L211

Added line #L211 was not covered by tests

# Create data config from storage paths
data_config = DataConfig(

Check warning on line 214 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L214

Added line #L214 was not covered by tests
input_dir=str(Path(config.storage.base_dir)),
)

return cls(

Check warning on line 218 in python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py

View check run for this annotation

Codecov / codecov/patch

python/packages/autogen-ext/src/autogen_ext/tools/graphrag/_global_search.py#L218

Added line #L218 was not covered by tests
token_encoder=token_encoder,
llm=llm,
data_config=data_config,
context_config=_default_context_config,
mapreduce_config=_default_mapreduce_config,
)
Loading
Loading