Context window
Also known as: context length
The most text, counted in tokens, that a language model can take in and keep in view at one time, including its own answer.
Draft - this entry has not been reviewed yet.
Formal
The fixed limit on how many tokens a language model can handle in one go; the prompt, earlier turns of the chat, added documents and the answer must all fit inside it.
In plain English
Like the size of a desk - everything the model is working on has to fit on it, and when it is full, something has to be cleared away to make room.
In practice
A clerk in a region works with an AI assistant through a long afternoon; it starts ignoring the format rules given at the start, because the chat app has cut the oldest messages to keep the rest inside the context window.
Why it matters
It limits how much a model can weigh in one answer, and everything inside it - including text from a file nobody checked - shapes that answer.
Technical deep dive
The context window is the maximum sequence length, in tokens, over which a transformer computes attention in one forward pass. Input and output share the same budget: a model with a 200,000-token window that is asked for up to 8,000 output tokens can accept at most 192,000 tokens of input, and APIs reject or truncate requests that exceed it. Everything counts - system prompt, tool definitions, earlier turns, retrieved documents, images converted to tokens and, for reasoning models, the hidden reasoning tokens generated during the current turn.
The limit has three technical sources. Self-attention compares every token with every other token, so naive compute and memory grow quadratically with sequence length; kernels such as FlashAttention (Dao et al., 2022) reduce memory traffic but not the quadratic compute. Positional information must generalise: models trained with rotary position embeddings (RoPE) or ALiBi are usually pretrained on shorter sequences and then extended by continued training on long documents combined with rescaling of the positional frequencies. Finally, during generation the KV cache stores a key and a value vector per token, per layer and per KV head, so its size grows linearly with context length and often dominates GPU memory; grouped-query attention and cache quantisation exist largely to shrink it.
Advertised length and usable length are not the same. Liu et al. ("Lost in the Middle", 2023) showed that retrieval accuracy on multi-document question answering drops when the relevant passage sits in the middle of a long context rather than near the start or end, and synthetic benchmarks such as RULER report that many models' effective context is well below the nominal figure once tasks require more than finding a single needle. Anthropic describes the general effect as context rot: recall degrades as token count grows. More context is therefore not free even when it fits.
Applications manage the window explicitly. Chat front-ends drop or summarise the oldest turns (the failure in this term's example), agents compact long histories into summaries or offload notes to external memory, and RAG systems insert only the top-ranked chunks. Prompt caching reuses the computed prefix across calls to cut latency and cost but does not enlarge the window. The context window is also distinct from memory features that persist between sessions: those work by writing text to storage and re-inserting it into a later context, so they consume the same budget and inherit the same prompt-injection exposure as any other text placed there.
What to learn first
Everything this builds on, foundations first.
- Token
- →Context window
Relationships
- Part of
- Large language model (LLM)
- Consists of
- Prompt
- Requires
- Token
- Don't confuse with
- Training dataKnowledge cutoffAgent memory
- Used with
- KV cacheAttention mechanism
Sources & further reading
Standards & official texts
- NIST AI 600-1 - Artificial Intelligence Risk Management Framework, Generative AI Profile · NIST
Reference works
- Vaswani et al. (2017), Attention Is All You Need
Where this data comes from
This entry was drafted by an AI from the sources above and has not yet been checked by a person. Treat it as a starting point, and check anything important against the sources.
See the review queueSuggest a correction on GitHubThis term as JSON
Mentioned in
Check yourself
Loading…