Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Tokens, Context and Sampling  ›  Lesson

The Context Window

Context 12 minThe context window is the fixed number of tokens a model can handle in one call, shared by everything you send and everything it writes back.

The Context Window

A customer has been chatting with the Pedal Point assistant for half an hour about a wheel upgrade. Suddenly it forgets which bike they own, or the request fails with a "too long" error. Nothing is broken. The conversation has outgrown the model's context window.

The rule

The context window is the model's entire world for one call.

Every model can handle a fixed maximum number of tokens per request. That budget is shared by everything:

  • the instructions (system prompt)
  • the conversation history the app resends
  • retrieved documents and tool results
  • the new question
  • and the reply the model writes

The model sees nothing outside this window. If something is not in it, as far as the model is concerned it does not exist.

Window sizes vary a lot between models, from a few thousand tokens to very large ones. Bigger is not free, though. Longer inputs cost more and take longer, and models can overlook a detail buried inside a huge input. A focused context usually beats a stuffed one.

When a conversation grows, you have two main tools:

  • Context compaction. Replace older turns with a short summary ("Customer owns a 2021 gravel bike, wants tubeless wheels, budget about 300"). The key facts survive; the tokens shrink.
  • Context isolation. Give a side task its own fresh, clean window. For example, send a long spec sheet to a separate call that extracts just the tyre sizes, then pass only that short result back to the main conversation.

The shortcut

Write the budget as a sum: window ≥ instructions + history + retrieved + question + reserved reply. If the left side loses, cut the least valuable part first, usually old history.

Does this request fit in 8,000 tokens?Step 1 of 4
  1. List the parts

    Instructions 600, history 3,500, four chunks at 500 = 2,000, question 100, reply reserve 1,000.

The trap is forgetting to reserve room for the reply. A request that exactly fills the window leaves the model no space to answer.

Drills

Answer fast — trust the rule.

quick drill

Which of these does NOT use the context window of a call?

quick drill

Window 4,000. Instructions 500, history 1,800, question 100, reply reserve 800. How many tokens are left for retrieved chunks?

quick drill

A long chat keeps overflowing. Which fix keeps the important facts while saving tokens?

quick drill

Sending a 40-page manual to a separate call that returns only the three tyre sizes is an example of what?

Remember

  • The context window is the model's entire world for one call.
  • Window ≥ instructions + history + retrieved + question + reply.
  • Always reserve room for the reply; compact old history first.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainBudget the window

A model has a 16,000-token context window. Pedal Point sends 1,000 tokens of instructions, 6 retrieved chunks of 800 tokens each, a 9,000-token chat history and a 200-token question, and wants to reserve 1,500 tokens for the reply. Does it fit? If not, propose a fix and explain why you chose it.