Context Window
The context window defines the maximum number of input tokens a transformer model can process at once, determining the length of conversation history or document it can reason over.
The context window is the fixed-size sequence length that a transformer model was trained to handle, typically 2048 to 1 million tokens in modern LLMs. It limits how many tokens - from prompt, conversation history, or retrieved documents - can be attended to simultaneously. When input exceeds this length, the model must truncate, chunk, or use sliding window strategies. The context window size is limited by the quadratic memory complexity of full attention (O(n^2) with n tokens) and by positional encoding schemes like RoPE, which degrade beyond a certain length. Long-context models (e.g., GPT-4 128K, Claude 200K, Gemini 1M) achieve their reach via techniques like ALiBi, YaRN, or RingAttention to extrapolate to longer sequences. For RAG pipelines, context window size directly impacts how many retrieved document chunks can be inserted into the prompt; exceeding it forces summarization or chunk dropping. In inference, a larger context window dramatically increases KV cache memory usage, often by gigabytes per request. AI builders must balance context window size with available VRAM and throughput requirements. Fine-tuning with RoPE scale factors or using models with linear attention can extend windows without retraining, but may degrade performance on shorter sequences. In practice it refers to the combined length of prompt and generated tokens - exceed it and the oldest tokens are dropped, breaking long conversations or large code-review tasks.
A larger context window does not automatically mean better understanding-models often show 'lost-in-the-middle' effects where they poorly use tokens in the middle of very long contexts.
Related terms
Concepts you'll usually encounter alongside this one.
The KV cache stores intermediate key and value tensors from previous tokens during autoregressive generation, enabling subquadratic computation by avoiding redundant re-encoding of the full context.
FlashAttention is an I/O-aware algorithm that computes exact attention without materializing the full attention matrix, reducing memory usage from O(n^2) to O(n) and improving speed 2-10x on GPUs.
The rate at which a language model generates or processes tokens, commonly used to measure inference throughput.
Used in benchmarks
Workloads on MyAI Bench that involve Context Window.
Mentioned in tutorials
Hands-on guides that put this concept to work.
Stand up a fully functional local LLM stack on Ubuntu 22.04, NVIDIA drivers, CUDA, Ollama, and your first model, in under 30 minutes.
Run local LLMs on Windows 11 the right way, WSL2, the WSL CUDA toolkit, and Ollama with full GPU acceleration. Native installer covered too.
Apple Silicon is shockingly good at LLM inference. Get Ollama running with unified memory acceleration on any M-series Mac in 15 minutes.
DeepSeek's reasoning model rivals GPT-4 on math and code. Run the distilled 7B/14B/32B variants on consumer hardware in 30 minutes.
See how this term affects your memory budget.
Real numbers, real chips, every workload.
Picks for builders, by use case.
Stay Ahead of the AI Curve
Get weekly AI hardware news, benchmark updates, and deals in your inbox. Founding-subscriber list, be one of the first.