liveBook · Manning

Context window

As explained in Build Applications with Local AI Models on a Mac

Context length is the maximum number of tokens a language model can consider at once.

A context window is the maximum amount of text a language model can process in one request, measured in tokens. Tokens are small pieces of text; 8,192 tokens amount to roughly 6,000 English words. Think of the window as working space for the conversation, not permanent memory. section 11.4 section 11.1

A chatbot appears to remember because the app sends conversation history with each new message. The window must fit the user’s messages, the model’s earlier replies, and the reply being generated. After enough exchanges, that history may no longer fit. section 7.4.5 section 11.4

When a chat gets long

After twenty detailed exchanges, history could reach 5,000–10,000 tokens. If it exceeds the available window, the model may lose earlier messages or give confused, contradictory answers. Sending more context can also make each response slower. section 11.4 section 11.4.1

Table 11.1 Typical context window sizes for common local models

Model

Context window

gemma2:2b

~8,192 tokens

llama3.2:3b

~128,000 tokens

qwen2.5:3b

~32,768 tokens

Compare typical context-window capacities across local models. These figures describe model capacity, not necessarily the context Ollama has allocated; check the active context with ollama ps. section 11.4

Keep the full conversation visible to the user, but trim the messages sent to the model when necessary. Streamlit’s st.session_state can store the app’s messages; it does not increase the model’s context window. To inspect model details, including context length, use ollama show with the model name. section 11.9 section 11.1 section 4.5.3

How Build Applications with Local AI Models on a Mac covers it

How deep it goes
Defines the token limit, estimates conversation growth, and explains overflow; identifies trimming as a remedy without specifying a trimming algorithm.
Examples
Compares local-model capacities and estimates how twenty exchanges can consume 5,000–10,000 tokens.
What it assumes
Introduces tokens and stateless model calls before explaining why conversation history needs managing.
What you can do after
Apply it via Streamlit session state by retaining visible history while trimming messages sent to the model.
How it connects
Connects conversation history, stateless LLM calls, Streamlit session state, and response quality.

Also explained in

Compare how 22 books explain context window →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Applications with Local AI Models on a Mac. The section links point to the parts of the book it draws on.