SIMETRIUM .COM ctx · kv · rope
EN|36 languages
ctxctxctxctxctxmodelseesonlywhatisinsidethewindowmodelseesonlywhatisinsidethewindowwindow · seesforgotten ←TOKENS IN WINDOW128 000KV CACHE · MEMORYweights · cacheSYMBOL PLATET ≤ n_ctxwindow = frame · 1 token per tickISO/IEC 22989:2022 · Vaswani et al., 2017AAAWgmp1bWIAAAAeanVtZGMycGEAEQAQgAAAqgA4m3EDYzJwYQAAABZcanVtYgAAAEdqdW1kYzJtYQARABCAAACqADibcQN1cm46YzJwYTo5MjgzZmRhNS0wNTQ4LTQ5MzctYWFkMC05NmY5ZjcxZGU0ZDEAAAADl2p1bWIAAAApanVtZGMyYXMAEQAQgAAAqgA4m3EDYzJwYS5hc3NlcnRpb25zAAAAALxqdW1iAAAARGp1bWRjYm9yABEAEIAAAKoAOJtxE2MycGEuaW5ncmVkaWVudC52MwAAAAAYYzJzaMpKha5zX0mRAkGuEmgsx9QAAABwY2JvcqNpZGM6Zm9ybWF0bWltYWdlL3N2Zyt4bWxqaW5zdGFuY2VJRHgseG1wOmlpZDo4YzA4NjJmZC02ZTU0LTQxYjItYTY2Yy1iYmZjYmExMWZhNTFscmVsYXRpb25zaGlwaHBhcmVudE9mAAAB4mp1bWIAAABBanVtZGNib3IAEQAQgAAAqgA4m3ETYzJwYS5hY3Rpb25zLnYyAAAAABhjMnNoEcrp/4ahQ7cOPWLn7dMnNgAAAZljYm9yomdhY3Rpb25zgqJmYWN0aW9ua2MycGEub3BlbmVkanBhcmFtZXRlcnOha2luZ3JlZGllbnRzgaJjdXJseC1zZWxmI2p1bWJmPWMycGEuYXNzZXJ0aW9ucy9jMnBhLmluZ3JlZGllbnQudjNkaGFzaFgg5Idg9EQUn4hUQUizPalNF21oAcVzNxWLQIbihnQOLW+kZmFjdGlvbngdY29tLmFudGhyb3BpYy5jbGF1ZGUucHJvdmlkZWRqcGFyYW1ldGVyc6F4H2NvbS5hbnRocm9waWMub3JpZ2luLWNvbmZpZGVuY2VndW5rb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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPZYQJsvV9T0qy8+IvGovOyGTYrIadLoJxvo1H8uqOtZq/E1cotFyXXN/otsZR7vNujx5dwq/PM/TURIAbm+jrrdEyc=
a
other
already
forgotten
and
new
tokens
arrive
from right
model
sees
only
what
is
inside
the
window
a
other
already
forgotten
and
new
tokens
arrive
from right
a
other
already
forgotten
and
new
tokens
arrive
from right
model
sees
only
what
is
inside
the
window
a
other
already
forgotten
and
new
tokens
arrive
from right
Letter case
Length is written in tokens, often with the letter K: “128K” means 128 000 or 131 072, depending on who is counting. In documentation it appears as context window, context length, max_position_embeddings, num_ctx. In formulas it is T or n_ctx.
Do not confuse
The window is not the model’s memory of the world: its knowledge lives in the weights. The window holds the question and the answer together, and the answer length is usually capped separately, at a much smaller value. And the “advertised” length is not the “working” one: inside the window the model remembers text unevenly.
Beneath the cast letters ctx runs a ribbon of tokens, and above it a violet frame hangs motionless — the model’s window. Everything inside the frame glows mint: this is what the model sees. Tokens that have slid off to the left beyond the frame fade and turn red — it has already forgotten them. At the bottom right, the GPU memory gauge fills with amber cache with every new token.
Unit passport · AI series · working memory of a model

ctx

Context length
T = prompt + history + answer ≤ n_ctx · 128K = 131 072

In 2023, researchers at Stanford gave a model an exam. They handed it a question and twenty Wikipedia documents, one of which contained the answer. When the right document came first, the model answered correctly in three cases out of four. But when it sat right in the middle, the result was worse than with no documents at all, when it had to recall the answer from memory. Why does an extra hint hurt, and where is the window’s “blind spot”? Test it yourself in the lab.

Context length is how many tokens a language model sees at once: the instruction, the whole conversation, pasted documents and the answer it is writing. Whatever does not fit does not exist for it. Windows have grown from 512 tokens in 2017 to millions, but every token is paid for in GPU memory, time and money. This sheet offers a “will the document fit” calculator, a KV-cache memory counter, experiments on the lost middle and the cost of attention, and a workshop that shows how a short-context model is stretched to long texts.

What it is
the largest number of tokens a model processes in a single pass
Notation
T, n_ctx; “128K”; in Chinese 上下文长度
Memory cost
KV cache = 2 · layers · KV heads · head size · bytes × T
Compute cost
attention grows as T²: a prompt twice as long means four times the attention work
Typical values
512 — BERT · 2048 — GPT-3 · 128K — GPT-4o, Llama 3.1 · 1–2M — Gemini · 10M — Llama 4 Scout
References
ISO/IEC 22989:2022 · Vaswani et al., 2017 · Su et al., 2021 (RoPE)
Will the document fit Find the blind spot Stretch the window
Calculator
Tool · will the document fit

How much room your text takes in the window

Pick a model and a language, enter the number of pages, the length of the instruction, the number of turns in the conversation and how many tokens you leave for the answer. The same page gives a different number of tokens in different languages, so one and the same contract in Russian or Hindi will take up more room than in English.

Tool · KV-cache memory

How much GPU memory a long context will eat

So as not to reread the whole conversation for every new word, the model stores keys and values for every token in all layers — this is the KV cache. It grows in direct proportion to the context length and the number of users, and easily outgrows the weights themselves. Pick a model, a length and a storage format.

Etymology

Woven, window and stash

Three words without which no talk about long texts is possible came from a weaver’s workshop, a village hut and a gold prospector’s stash. Context is what is woven together with a word. A window is a slit one looks through. And a cache is a supply hidden for later so as not to have to get it again.

contextLat. contextus
texere · to weave→contexere · to weave together→the surroundings of a word
Latin texere, “to weave”, gave us both “text” and “textile”. With the prefix con- — “together” — it became contexere, “to weave together”. Context is the threads around a word, without which the pattern cannot be understood: whether a “key” opens a door or sits on a music staff is clear only from the neighbouring words. For a model, context is everything that lies before the next token.
windowEng. window
vindauga · wind’s eye→window→context window
English window comes from Old Norse vindauga — “wind’s eye”, a hole in the roof. The Russian word okno comes from oko, “eye”. In both languages a window is what one looks through, and only a part of the world is visible in it. In engineering, a “sliding window” long meant the piece of a data stream being processed right now — hence context window.
cacheFr. cache
cacher · to hide→a stash of supplies→KV cache
French cacher means “to hide”. Canadian trappers and gold prospectors called a cache a hiding place with food and gunpowder for the way back. In the 1960s the name was given to a processor’s fast memory — a supply kept close so as not to go far. A model’s KV cache is a stash of keys and values of tokens already read.
What it is called in other languages
上下文窗口 shàngxiàwén — Chinese, “up-down text”, i.e. the surroundings
コンテキスト長 — Japanese; 컨텍스트 길이 — Korean
ventana de contexto, janela de contexto, fenêtre de contexte, Kontextfenster
نافذة السياق — Arabic; संदर्भ विंडो — Hindi; kontekst tsonkh — Mongolian
Abbreviations nearby
K · Mthousands and millions of tokens; 128K can mean both 128 000 and 2¹⁷ = 131 072KV cacheattention keys and values for every token readRoPErotary position embedding: position as a rotation of a vectorRAGretrieval-augmented generation: put only the needed pieces into the window
01 · Definition and the conversation window

A model with no memory but with a sheet of paper

Imagine a conversation partner who remembers nothing for longer than a second, but before every phrase rereads a sheet with the record of the whole conversation. This is how a chatbot works: between your messages the model stores nothing, and the service sends it the entire dialogue each time — the instruction, all the turns and pasted files. Context length is the size of this sheet. When the conversation does not fit, the oldest turns have to be thrown out or briefly summarised.

The model’s answer is written on the same sheet: each new token is added at the end and also takes space. That is why the window limit is shared between the prompt and the answer, and a separate limit on the answer is usually much smaller than the window. Move the slider on the right and see which turns the model stops seeing.

T — tokens in the window · L — layers · h_kv — KV heads · d_h — head size · b — bytes per number · d — model width
Interactive · conversation in the window

What the model still sees

Turns in the conversation

Reference · benchmark values
512tokens — the window of the original 2017 transformer and of BERT 131 072tokens — the Llama 3.1 window, exactly 2¹⁷; GPT-4o has 128 000 128 KiBof KV cache per token for Llama 3.1 8B in BF16: 2 · 32 layers · 8 heads · 128 · 2 bytes 16 GiBof cache for one full 128K conversation with the same model — more than its weights
Lab · three experiments with the window

Blind spot, memory and the square

In “Middle” you hide the needed document among others and see how often the model finds it — using data from the Stanford experiment. In “Memory” a long context fills the GPU until it overflows. “Attention” shows why a long prompt gets more expensive faster than it grows: every token looks at all the previous ones.

Documents in the window
Where the right one lies
Context length
Simultaneous users
Prompt length
Whom each token sees

Chart · window growth
Twenty-thousand-fold in eight years
Horizontally the release year, vertically the window in tokens on a logarithmic scale: each division is ten times larger. In eight years windows grew from half a thousand tokens to ten million — from a paragraph to a small library.
Chart · claimed and working
The window is bigger than the attention
NVIDIA researchers in the 2024 RULER test gave models tasks — find, count, trace a chain — on ever longer texts. The pale bar is the claimed window, the bright one the length at which the model still solves tasks as well as the baseline. Almost all have a working length two to four times shorter.
02 · Orders of magnitude · context length, tokens

tokens, logarithmic scale

03 · Window-stretching workshop

How a short-context model is taught to read long text

Modern models learn where a token stands by a rotation: each pair of numbers in its vector is rotated by an angle proportional to the position number — this is RoPE, invented in 2021 by the Chinese researcher Jianlin Su. The pairs spin at different speeds, like clock hands: fast ones tell neighbours apart, slow ones tell distant places apart. If you feed the model text longer than it saw in training, the slow hands move to angles it has never seen — and the model gets confused. Below you can see how this is fixed: squeeze all positions (PI), change the base (NTK) or squeeze only the slow hands (YaRN).

Tool · RoPE hands
Original model
Stretch factor
Method

Each bar is one of the 64 pairs of an attention head’s vector: fast hands on the left, slow on the right. Height is how many turns the hand makes over the whole text length, on a logarithmic scale. The white line is how many it managed in training. Mint bars are safe, red ones go into unfamiliar angles, amber ones are squeezed so that neighbouring tokens are told apart worse.
Cheat sheet · living with a limited window
04 · The window in code

Where the length is set and why it is sometimes less than promised

A model has a limit built in during training, and the program that runs it has its own. A common trap: the model can do 128K, but a local run by default gives it a few thousand tokens, and a long document is silently cut off. Touch a line to read the details.

toolsettingdefault

For work · three snippets

Trim the conversation history by tokens, keeping the instruction; run Qwen2.5 at 128K with YaRN in vLLM; raise the window of a local model in Ollama and llama.cpp.

05 · Writing rules
Correct
Write the window in tokens, with a clarification: “128K = 131 072 tokens”.
State the answer limit separately: “128K window, answer up to 16K”.
Distinguish claimed from working length: “working per RULER — 64K”.
For the KV cache, name the format and length: “16 GiB at 128K in BF16”.
Compare text sizes in tokens of the same vocabulary.
Incorrect
Measure the window in words or pages, with no language or vocabulary.
Think a 1M window means an answer of a million tokens.
Think the model “remembers” past conversations: it sees only the window.
Write “128 kB of context” — these are tokens, not bytes.
Believe the model sees everything in the window equally well.
06 · Neighbouring units
07 · Historical section
needle in a haystack
Kamradt test, 2023
Note

In November 2023 the enthusiast Greg Kamradt devised a simple test: insert one foreign sentence into a long collection of essays — “the best thing to do in San Francisco is eat a sandwich and sit in Dolores Park on a sunny day” — and ask the model about it. He ran the test at different lengths and depths and coloured the results into a table. Claude 2.1, with its window of 200 thousand tokens, in many cells answered that there was no such sentence, although it was right in front of it.

Developers at Anthropic found that the model did find the sentence but did not dare to name it: it stood out from the topic of the essays. Once the answer was started with the words “Here is the most relevant sentence from the text:”, accuracy rose, by their data, from 27 to 98 percent. The lesson is useful to everyone: a window is not only a size but also how you ask the question. Put the important thing at the beginning or the end and ask outright for a quote.

depth × length
red — not found
Series · AI
units of language models

How a neural network is measured

Context length stands at a crossroads: it is counted in tokens, its memory depends on the model’s design, its price is in FLOP, and quality inside the window is tested by perplexity. On the left is information about one long prompt, where each row leads to its own sheet; on the right are the sheets of the series.

usage · long prompt
Catalogue of quantities
the whole index →
the foundation · 7 units

The seven SI base units

on the sheet’s topic · model training and AI
The index lab: a glass of cabbage juice, a burner, a glass of water on a cold plate and a gear train
Index · all quantities on one page
The lab at the entrance to the index

A drop of acid changes the colour of the juice, salt colours the flame, water freezes at a tap. Below them are all Simetrium sheets, by discipline and alphabetically.

Open the index →
08 · Your language
every link is a real page in that locale

Read it in your own language

translated and checkeddraft translationqueued