Improve default llm retry logic to be more optimized #1701
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR makes changes to provide a more optimized retry logic for graphrag by default. It also simplifies the configuration by removing config variables that do not provide much value.
Proposed Changes
There are two significant behavioral changes to take note of (can be disabled if users don't wish to use it)
max_retries
in the openai librarymax_retries
in each step of the indexing pipeline based on the input dataset sizeAs default behavior, these changes will cause graphrag's retry-logic to utilize the response back from OpenAI to determine how long to wait until it retries an LLM call (i.e. server-side retry logic), as opposed to retry logic that is based on the client-side only. This is done by calculating optimal values for the
max_retries
parameter when instantiating an openai client. Note that the openai library now has support for theretry-after
header (providing a more accurate estimate of time to wait between LLM calls)...so if graphrag bases its' retry-logic entirely on the openai library, this approach should allow us to achieve full quota utilization with fewer configuration variables needed by graphrag.For users that don't want to use the dynamic retry logic, it can be disabled and other retry-logic is exposed in the configuration file (
tokens_per_minute
andrequests_per_minute
).This dynamic retry logic was tested on two separate AOAI models, with 10K TPM and 400K TPM, to evaluate effectiveness. I also tested across different dataset sizes as well and did not any experience errors due to graphrag reaching the max number of retries for an LLM call.
Checklist
Additional Notes
[Add any additional notes or context that may be helpful for the reviewer(s).]