Repository navigation
Putting a dollar cap on one LightRAG indexing job #4150
domondi1
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Indexing makes a lot of LLM calls: entity and relation extraction for every chunk, gleaning passes, and summaries, several at a time with
llm_model_max_async. On a big document set the cost of oneainsertis hard to predict, and there isn't a per-job limit built in. Here's one way to give each indexing job a hard dollar budget without changing LightRAG.openai_complete_if_cachepasses its extra kwargs straight tochat.completions.create, sollm_model_kwargscan carry abase_urland per-requestextra_headers(the job's id and budget) to a small OpenAI-compatible gateway running in the same process:Each call reserves its worst-case cost before it's sent, so the concurrent extraction calls can't all spend the same remaining money, and a call that doesn't fit is refused with a 402 before it reaches OpenAI. LightRAG doesn't retry a 402 (only rate limits, timeouts and connection errors), so the job stops quickly instead of spending more.
inferrail work index-2026-10-03shows what the job cost.Caveats: set
max_tokens(without it each call reserves a 4,096-token default), leaveOPENAI_API_BASEunset so embeddings keep going to OpenAI (the gateway only handles chat completions), and cached LLM responses don't count because they never make a call. The model needs a price in Inferrail;gpt-4o-minihas one built in.Setup details: guide. I maintain Inferrail (open source, Apache-2.0), so take the suggestion with that in mind. Curious how others here keep indexing cost bounded on large corpora.
All reactions