Immutable solution version
Calculated available context size -N was not non-negative
Complete solution
Llama Index: calculated available context size -N was not non-negative. The verified fix is Fix: Collaborator logan-markewich diagnosed: the 'Calculated available context size -N' error appears when a custom LLM does not declare an accurate context_window in its LLMMetadata - set context_window to the real model size (e.g. Use this when you hit the symptoms above in llama_index; not for unrelated llama_index errors or general setup questions.
TL;DR
Fix: Collaborator logan-markewich diagnosed: the 'Calculated available context size -N' error appears when a custom LLM does not declare an accurate contextwindow in its LLMMetadata - set contextwindow to the real model size (e.g.
The error
Issue run-llama/llama_index#16235 (closed, 16 comments): ### Question Validation - [X] I have searched both the documentation and discord for an answer. ### Question Hi, I'm having this issue whenever I reach to the point that my chat exceeds X amount of tokens. I was assuming `as_chat_engine()` set up with `max_prompt` which preserves chat history, would automatically handle this situation. What am I missing ?Fix
- Collaborator logan-markewich diagnosed: the 'Calculated available context size -N' error appears when a custom LLM does not declare an accurate contextwindow in its LLMMetadata - set contextwindow to the real model size (e.g.
Success check: the symptom above is gone and the original operation completes.
When to use
- You hit this exact symptom in llama_index.
- You want the verified fix without digging through the thread.
When not to use
- A different error in llama_index, even a similar-looking one.
- General llama_index setup or credential questions.
Compatibility
- Llama Index (run-llama/llama_index)
Variant phrasings
- How to fix "calculated available context size -N was not non-negative" in llama_index
- llama_index: calculated available context size -N was not non-negative
Edge cases
- If the chat history still overflows, lower the ChatMemoryBuffer token limit, e.g. aschatengine(..., memory=ChatMemoryBuffer.fromdefaults(tokenlimit=(50000)).
Source
- https://github.com/run-llama/llama_index/issues/16235
Evidence
In gh:run-llama/llamaindex#16235 (https://github.com/run-llama/llamaindex/issues/16235), someone reported: Issue run-llama/llamaindex#16235 (closed, 16 comments): ### Question Validation - [X] I have searched both the documentation and discord for an answer. ### Question Hi, I'm having this issue whenever I reach to the point that my chat exceeds X amount of tokens. I was assuming `aschatengine() set up with maxprompt` which preserves chat history, would automatically handle this situation. What am I missing ? The verified resolution from the thread: Collaborator logan-markewich diagnosed: the 'Calculated available context size -N' error appears when a custom LLM does not declare an accurate contextwindow in its LLMMetadata - set contextwindow to the real model size (e.g. LLMMetadata(contextwindow=128000, modelname=...)) and numoutput. If the chat history still overflows, lower the ChatMemoryBuffer token limit, e.g. aschatengine(..., memory=ChatMemoryBuffer.fromdefaults(token_limit=50000)). The chat engine cannot auto-truncate when it doesn't know what the real window is.
By @issueatlas · Version 2 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_OUeVmL0RwotNAorew8zAwA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Calculated available context size -N was not non-negative <span>— Vectle</span></a>