Context Window
Also known as: Context length
The maximum amount of input, measured in tokens, that a language model can take into account at once, including the text it is generating.
A context window is the span of input a language model can attend to when producing its next output. It is measured in tokens and includes everything the model sees in a given request: system instructions, the conversation so far, any pasted documents or tool results and the response being generated. Anything outside the window is simply not available to the model for that step. The context window is often described as the model's working memory, distinct from the knowledge stored in its weights during training.
The limit arises from how transformer models work. Each token can attend to every other token in the window, so the computation and memory required by standard attention grow roughly with the square of the sequence length. Early large language models such as GPT-3 handled about two thousand tokens; by 2024 several commercial models accepted hundreds of thousands, and some a million or more, thanks to architectural changes, more efficient attention implementations and training on longer sequences. Larger windows still raise cost and latency.
A long window does not guarantee that a model uses all of it well. Studies have found that models can overlook information placed in the middle of long inputs, and quality may degrade as the window fills. Practitioners therefore combine large windows with techniques such as retrieval, summarization of earlier conversation and careful ordering of material. For users, the context window explains why a chatbot may lose track of early parts of a long conversation and why supplying the right documents matters as much as phrasing the question.
Key points
- Context window size is measured in tokens, not in words or characters.
- Everything in a request, including instructions, documents and the model's reply, shares the same window.
- Standard attention cost grows roughly quadratically with sequence length, which historically limited window sizes.
- A larger window helps only if the model can reliably find and use the relevant information within it.
From the source
...is different from the large corpus of data the language model was trained on, and instead represents a "working memory" for the model.
Related entries
The process of splitting text into smaller units called tokens, such as words, subwords or characters, that a language model can process as numbers.
Neural network architecture based on self-attention, introduced in 2017, that underlies most large language models and many vision and audio models.
Neural network technique that lets a model weigh the relevance of different parts of its input when producing each part of its output.
Retrieval-Augmented Generation
Technique that improves a language model's answers by first retrieving relevant documents and supplying them to the model as context.
Neural network trained on very large amounts of text to predict the next token, able to generate language and perform many tasks from prompts.
The practice of designing and refining instructions, examples and context given to a generative AI model to obtain more useful and reliable outputs.
Ability of a language model to perform a task from instructions or examples given in its prompt, without any change to its trained weights.
Featured in guides
Referenced by
Other entries that discuss or point to Context Window.