-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[Bug]: graphrag index creates 637 AsyncAzureOpenAI on gutenberg QuickStart #1517
Comments
I found a workaround by overriding the LLM loaders in from pathlib import Path
from typing import Any
from fnllm import JsonStrategy, LLMEvents
from fnllm.openai import (
AzureOpenAIConfig,
create_openai_chat_llm,
create_openai_client,
create_openai_embeddings_llm,
)
from fnllm.openai.types.chat.parameters import OpenAIChatParameters
from graphrag.cli.index import index_cli
from graphrag.config.enums import LLMType
from graphrag.logger.types import LoggerType
from graphrag.index.llm.load_llm import loaders
from graphrag.index.typing import ErrorHandlerFn
import graphrag.config.defaults as defs
import tiktoken
def main():
_initialize_llm_loader(
LLMType.AzureOpenAIChat,
model="gpt-4o-mini",
model_supports_json=True,
api_base="https://<snip>.openai.azure.com",
api_version="2024-08-01-preview",
deployment_name="gpt-4o-mini",
)
_initialize_llm_loader(
LLMType.AzureOpenAIEmbedding,
model="text-embedding-3-small",
model_supports_json=False,
api_base="https://<snip>.openai.azure.com",
api_version="2023-05-15",
deployment_name="text-embedding-3-small",
)
index_cli(
root_dir=Path(os.path.dirname(__file__)),
verbose=True,
resume=None,
memprofile=False,
cache=True,
logger=LoggerType.PRINT,
config_filepath=None,
dry_run=False,
skip_validation=False,
output_dir=None,
)
def _initialize_llm_loader(
type: LLMType,
model: str,
model_supports_json: bool,
api_base: str,
api_version: str,
deployment_name: str,
) -> None:
openai_config=AzureOpenAIConfig(
model=model,
encoding=tiktoken.encoding_name_for_model(model),
deployment=deployment_name,
endpoint=api_base,
json_strategy=JsonStrategy.VALID if model_supports_json else JsonStrategy.LOOSE,
api_version=api_version,
max_retries=defs.LLM_MAX_RETRIES,
max_retry_wait=defs.LLM_MAX_RETRY_WAIT,
requests_per_minute=defs.LLM_REQUESTS_PER_MINUTE,
tokens_per_minute=defs.LLM_TOKENS_PER_MINUTE,
timeout=defs.LLM_REQUEST_TIMEOUT,
max_concurrency=defs.LLM_CONCURRENT_REQUESTS,
chat_parameters=OpenAIChatParameters(
frequency_penalty=defs.LLM_FREQUENCY_PENALTY,
presence_penalty=defs.LLM_PRESENCE_PENALTY,
top_p=defs.LLM_TOP_P,
max_tokens=defs.LLM_MAX_TOKENS,
n=defs.LLM_N,
temperature=defs.LLM_TEMPERATURE,
),
)
openai_client = create_openai_client(openai_config)
if type == LLMType.AzureOpenAIChat:
loaders[type]["load"] = lambda on_error, cache, _: create_openai_chat_llm(
openai_config,
client=openai_client,
cache=cache,
events=GraphRagLLMEvents(on_error),
)
elif type == LLMType.AzureOpenAIEmbedding:
loaders[type]["load"] = lambda on_error, cache, _: create_openai_embeddings_llm(
openai_config,
client=openai_client,
cache=cache,
events=GraphRagLLMEvents(on_error),
)
else:
raise ValueError(f"Unsupported LLM type: {type}")
class GraphRagLLMEvents(LLMEvents):
def __init__(self, on_error: ErrorHandlerFn):
self._on_error = on_error
async def on_error(
self,
error: BaseException | None,
traceback: str | None = None,
arguments: dict[str, Any] | None = None,
) -> None:
self._on_error(error, traceback, arguments)
if __name__ == "__main__":
main() |
We believe this was a bug introducing during our adoption of fnllm as the underlying LLM library. We just pushed out a 1.0.1 patch today, please let if know if your problem still exists with that version. |
This issue has been marked stale due to inactivity after repo maintainer or community member responses that request more information or suggest a solution. It will be closed after five additional days. |
Do you need to file an issue?
Describe the bug
GraphRAG v1.0.0 keeps on calling
fnllm.openai.create_openai_client()
during indexing instead of reusing the OpenAI client. Since fnllm creates a newDefaultAzureCredential
for eachcreate_openai_client()
call (code), this restarts the authentication process and adds to indexing runtime.Steps to reproduce
Follow the GraphRAG quickstart (https://microsoft.github.io/graphrag/get_started/) until the step
graphrag index --root ./ragtest
, using Entra authentication instead of API key. Open indexing-engine.log and observe repeated log lines like this:Expected Behavior
The OpenAI client is reused and only one Entra access token is acquired for authentication.
GraphRAG Config Used
Logs and screenshots
No response
Additional Information
The text was updated successfully, but these errors were encountered: