LLM Context Window Explained: From 4K to 1M Tokens

LLM Context Window Explained: From 4K to 1M Tokens

Context window size is one of the most important — and most misunderstood — specs for local LLM inference. More context means higher memory usage, slower inference, and sometimes lower quality on short tasks. Understanding the tradeoffs helps you choose the right context size for your workload rather than defaulting to maximum.

Key fact: Every additional 1K tokens of context adds ~1MB to KV cache (in FP16, for a 7B model). Running a 7B model at 32K context vs 4K context adds 28MB to VRAM usage. For hardware limits by context size, see LLMHardware.io's VRAM calculator.

How Context Window Works

The context window is the total amount of text the model can "see" at once — including your system prompt, conversation history, and the current message. When it fills up, older content is dropped (truncated from the beginning by default in most tools). The KV cache stores attention states for all context tokens in VRAM, which is why larger contexts use more memory proportionally.

Context vs Quality: The Lost in the Middle Problem

Research shows most LLMs degrade in quality when important information is in the middle of very long contexts. Models reliably recall information from the beginning and end of context, but forget content buried in the middle. This "lost in the middle" effect means a 128K context window doesn't guarantee the model effectively uses all 128K tokens. For RAG applications, smaller focused context often outperforms large unfocused context.

Practical Recommendations

For conversation: 8K-16K is sufficient for most interactions. For document analysis: match to document size but cap at 32K unless needed. For code generation with large codebases: 32K-64K. For document summarization pipelines: use chunking + RAG rather than hoping context alone works. Enable --flash-attn in llama.cpp when using contexts over 8K — it significantly reduces memory pressure and speeds up prefill.

Comments

Popular posts from this blog

AMD RX 9070 XT for Local LLMs: ROCm Performance Guide (2026)

llama.cpp flash attention: how to enable and benchmark

SillyTavern with Local LLMs: Complete Setup for AI Companions