graphrag icon indicating copy to clipboard operation
graphrag copied to clipboard

Add LLM Token and Cost Estimation Pre-check Before Indexing

Open khaledalam opened this issue 7 months ago • 3 comments

Description

This PR introduces a new feature that estimates the token usage and LLM cost before executing the indexing pipeline. This helps users anticipate costs and make informed decisions before proceeding.

Related Issues

https://github.com/microsoft/graphrag/issues/385 , https://github.com/microsoft/graphrag/pull/487

graphrag

Proposed Changes

New CLI params:

  • --estimate-cost : [True || False] (by default False)
  • --average-output-tokens-per-chunk : (by default 500}
graphrag index \
   --root ./ragtest \
   --estimate-cost \
   --average-output-tokens-per-chunk 500
  • Util file: estimate_cost.py added for token counting and pricing logic.
  • Pricing dynamically fetched from a public JSON source.
  • CLI flag --estimate-cost added for optional pre-check.
  • Console summary with embedding/chat model breakdown and token counts.
  • User confirmation prompt before continuing indexing. = Conservative cost estimation based on --average-output-tokens-per-chunk value.

Checklist

  • [x] I have tested these changes locally.
  • [x] I have reviewed the code changes.
  • [x] I have updated the documentation (if necessary).
  • [ ] I have added appropriate unit tests (if applicable).

khaledalam avatar May 06 '25 18:05 khaledalam

@microsoft-github-policy-service agree

khaledalam avatar May 06 '25 18:05 khaledalam

Please review @natoverse

khaledalam avatar Jun 05 '25 14:06 khaledalam

Please review @jgbradley1

khaledalam avatar Jun 29 '25 23:06 khaledalam