Context Window: Why the Model 'Forgets' the Start of a Dialogue
You are discussing a project for a long time, and at some point the assistant stops remembering what was discussed at the beginning. This is not a bug or the model's 'stupidity'—it's due to the context window. We'll break down what it is and how to deal with it.
What is the Context Window
The context window is the amount of text the model 'sees' at once. Everything you've written, plus all its responses, plus the system prompt — all of this is compiled into one array and fed to the model as input.
The window is measured in tokens, not words or characters. One Russian text takes up more tokens than it seems: a word can be split into 1–2 tokens.
Why the Dialogue 'Falls' Out of Memory
When the conversation exceeds the window size, the model can't keep everything in mind at once. Something has to be discarded — usually the beginning. That's why the assistant 'forgets' early agreements.
flowchart LR
A[Dialogue Start] --> B[Midpoint]
B --> C[End]
C --> D{Does everything fit in the window?}
D -->|Yes| E[Model remembers everything]
D -->|No| F[Beginning is discarded]
This is not a loss of the model's knowledge — it's a limitation of the working memory of a specific conversation.
How Much is That in Numbers
| Model | Context Window |
|---|---|
| DeepSeek | 128K tokens |
| Claude | 200K tokens |
| Gemini | up to 1M tokens |
128K tokens is roughly a whole book. That sounds like a lot, but a long dialogue with code, logs, and documents can quickly eat up this capacity.
What Takes Up Space
- the dialogue itself: your messages and the model's responses;
- system prompt — it's always in the window;
- inserted documents and code snippets;
- search results in RAG;
- tool instructions.
All of this adds up. So even with a large window, the dialogue can 'shrink' unnoticed.
How to Not Hit the Ceiling
- Summarize along the way. Every few messages, ask the assistant to condense the results and continue from there.
- Keep the system prompt short. The shorter it is, the more room is left for the dialogue.
- Don't insert entire large documents. Cut and take what's needed.
- Start a new chat for a new task. Don't drag the tail of old topics.
- Use RAG for working with large volumes — the model gets only relevant pieces.
What Else Affects 'Memory'
Besides the window, there's the KV-cache — a utility memory that grows with the length of the dialogue and affects speed and cost. The longer the conversation, the more expensive each subsequent response. So saving context is also saving money.
In Brief
The context window is the working memory of the model for one dialogue. It's large, but not infinite. Knowing how to manage it is another skill in working with AI, like knowing how to write good prompts.
