Mhonn YbañezSRE, DevOps, AI Engineer
 Today I Learned
Read the full page

What is a context window?

Posted
Tags
ai, llm

The context window is everything a model can see in one request, measured in tokens, including its own reply. The model remembers nothing between requests, so the app sends the whole conversation again every time.

I use AI tools every day and I thought I knew what a context window was. My picture was that the model can take in a large pile of text, and every reply is just the whole conversation dumped back into it. I wanted to confirm that before I kept repeating it. Turns out I was right, but there was more to it than I thought.

The question I had

What is a context window, really?

What I found

The short answer

The context window is the maximum amount of text a model can look at in a single request. Everything the model uses to write its answer has to fit inside it. Anything outside it, the model simply doesn't see.

It's measured in tokens, and it covers both what I send in and what the model writes back.

Tokens, not words

A token is a chunk of text, often part of a word. For English, a rough rule is about 4 characters, or about three quarters of a word, per token. So 1,000 tokens is around 750 words. Code, other languages, and unusual words usually take more tokens.

Current models have windows of hundreds of thousands of tokens, and some go up to a million. That's a lot, but it fills faster than I expected.

What fills it

It's not just my message. In a single request, the window holds:

WhatExample
System promptThe instructions the app gives the model before I type anything
Conversation historyEvery earlier message, mine and the model's
Tool definitionsDescriptions of tools the model is allowed to call
Attached contentFiles, documents, pasted logs
Tool resultsOutput from searches, file reads, commands
The replyThe tokens the model is writing right now

The model doesn't remember, the app resends

This was the part I had right. The model itself is stateless. It remembers nothing between requests. When a chat feels like it remembers what I said ten messages ago, it's because the app sends all ten messages again with every new one.

What I hadn't thought about is that it's not always the whole conversation. It's whatever the app decides to put into the window on each request, and once the conversation gets long, the app has to start choosing.

What happens when it fills up

Long conversations eventually hit the limit. Apps deal with it in a few ways:

  • Drop the oldest messages, so the start of the conversation is forgotten.
  • Summarize older parts into a shorter note and keep going.
  • Return an error and ask me to start over.

That explains why a long chat can suddenly "forget" something from early on.

Bigger isn't automatically better

  • Cost and speed: every token in the window is processed on every request, so a huge context is slower and costs more each turn.
  • Lost in the middle: it is found that models use information at the start and end of a long context better than information buried in the middle.
  • Noise: stuffing in everything "just in case" can distract the model from what matters.

So a good prompt gives the model what it needs, not everything available.

What it is not

  • Not memory. Features that "remember" me across chats store notes outside the model and insert them into the window when needed.
  • Not training data. What the model learned in training is baked into its weights, up to its knowledge cutoff. The context window is what it's given right now.
  • Not the output limit. Models also have a separate, smaller cap on how long a single reply can be. That lives inside the context window.

Takeaway

The context window is the model's working space for one request, not a memory. If I want the model to know something, it has to be in the window, and keeping the window focused gets better answers than filling it up.