What is the context window for?
The context window is the working memory of a language model for the duration of a request: instructions, attached documents, conversation history and the response being written must all fit within it. It is measured in tokens.
The larger it is, the more long documents you can submit at once. Context windows have grown considerably in recent years, but their size does not guarantee that the model pays equal attention to every passage of a very long document. Beyond that point, you need to select the useful information, for example with RAG.
What fills the context window
With each request, the model receives a set of elements whose total, in tokens, must stay below the limit.
- 1 Step 1 Instructions The system prompt and the instructions that set the assistant’s role and rules.
- 2 Step 2 Documents The texts, excerpts or images provided to answer, for example selected by a RAG system.
- 3 Step 3 History The previous exchanges in the conversation, sent back to the model with each new message.
- 4 Step 4 The response The text generated by the model, which also takes up part of the window.
What it changes for businesses
- Document analysis A large window lets you submit a long contract or report in a single request.
- Internal assistants With a large document base, RAG selects the useful passages instead of sending everything.
- Long conversations Regularly summarising the history avoids losing the first exchanges and keeps costs down.
- Budget The longer the context sent, the more each request costs and the longer it takes.
Send everything or use RAG?
| Everything in the window | RAG | |
|---|---|---|
| Principle | Send all the documents with every request | Pass on only the relevant passages |
| Document volume | Limited by the size of the window | Can cover a very large document base |
| Cost per request | High if the documents are long | Better controlled: only excerpts are sent |
| Ideal for | In-depth analysis of one or a few documents | Frequent questions across a large document collection |
The two approaches complement each other: RAG selects the right passages, and a generous window lets you pass on enough of them.
Frequently asked questions
-
Depending on the application, the request is rejected, or the oldest elements are removed or summarised. Either way, the model cannot take into account anything it has not been sent.
-
Not automatically. A very long context increases cost and response time, and information buried in the middle may be given less weight. A focused context often gives better results.
-
It is listed in the provider’s documentation, expressed in tokens, often with a separate limit for the maximum response length. It can change from one model version to another.
