What Is a Context Window? Tokens and AI Memory, Explained
Why does a chatbot forget what you told it an hour ago, or struggle with a long PDF? The answer is the context window. Here is how it works and how to work around it.
Mubarak Ali · · 3 min read
You spend an hour with a chatbot planning a trip. Early on you mention that you're vegetarian. Forty messages later it recommends a steakhouse. Or you upload a 300-page report and ask about a table near the middle, and the answer is vague or wrong.
Both problems usually trace back to the same limit: the context window.
Tokens first
Language models don't read words the way we do. They read tokens, which are chunks of text. A token is often a whole short word, sometimes part of a longer one, sometimes a space or a punctuation mark. For English, 1,000 tokens is roughly 750 words. Other languages often need more tokens for the same meaning, so the same message in Urdu or Hindi can use several times as many tokens as it would in English.
If you want the longer story of how models use tokens, start with our explainer on how large language models work.
The context window is the model's working memory
The context window is the maximum number of tokens a model can take into account at one time. Everything it uses to write its next reply has to fit inside it:
- the instructions the app gives the model, which you usually don't see
- your messages and its replies so far
- any files, web pages or search results added to the conversation
- the reply it is writing now
The model has no other memory of the conversation. If something isn't inside the window, the model can't use it.
How big windows have become
When ChatGPT launched in late 2022, its window held about 4,000 tokens, roughly the length of a long article. Today's leading models commonly handle hundreds of thousands of tokens, and some accept a million or more. A million tokens is around 750,000 words, enough to hold several long novels at once.
That sounds like the problem is solved. It mostly isn't, for two reasons.
Bigger isn't the same as better
The first reason is attention. A well-known 2023 study titled "Lost in the Middle" found that language models used information at the start and end of a long input much more reliably than information buried in the middle. Models have improved since then, but most still get less dependable as inputs grow. Fitting a document into the window doesn't guarantee the model reads every part of it equally well.
The second reason is cost and speed. The model processes every token in the window each time it writes a reply. Long conversations get slower, and companies that pay per token pay more. Many apps quietly manage this by trimming or summarizing older parts of a conversation, which is exactly how the vegetarian detail from message three gets lost.
Context window vs memory features
Some chat apps have a "memory" feature that remembers you across separate conversations. It doesn't make the context window bigger. The app saves short notes about you ("vegetarian, lives in Toronto, prefers short answers") and adds them to the instructions at the start of each new chat. Those notes still take up space in the window, and the model can only use what was saved.
How to work with the limit
- Start a new chat when you change topics. A fresh conversation gives your new question the model's full attention.
- Restate important details in long conversations. If a constraint matters, repeat it when you ask for the final result.
- Paste the relevant part of a document. If your question is about chapter 7, give it chapter 7.
- Ask for a summary before moving on. When a long chat gets slow or confused, ask the model to summarize the decisions so far, then paste that summary into a new chat.
- Put your instructions where they will be seen. With a long document, put your question after the document as well as before it.
The short version
A context window is how much text a model can consider at once, measured in tokens. Windows are now very large, but models still handle long inputs unevenly, and long conversations get slower and more expensive. Shorter, focused conversations with the right material pasted in get better answers than one endless chat.
- context window
- tokens
- LLM
- ChatGPT
- beginners