A model reads only a fixed number of tokens at once. As a chat grows, the oldest words fall out of the window, and the model can no longer see them.
AI · beginner · 6 min · 17 steps · free
What you'll learn
Explain what a context window is
See old tokens drop out as a chat grows
Name ways apps work around the limit
context_window.py
# A model can only read a fixed number of tokens at once: its context window.
window = 6
chat = []
for message in ["my name is asha", "i like tea", "what is my name"]:
chat += message.split(" ")
seen = chat[-window:] # anything older falls out of the window
print(seen)
remembers = "asha" in seen
print("can it still see the name?", remembers)
Step by step
This model can read 6 tokens at once. Real models read thousands to millions, but the limit always exists.
The whole conversation so far.
The user's first message.
Add its words to the chat.
The model sees the last 6 words. The chat has only 4, so it sees everything, including "asha".
It prints ['my', 'name', 'is', 'asha'].
message changes from 'my name is asha' to 'i like tea'.
Three more words: the chat now has 7.
7 words but a window of 6: the first word, "my", has fallen out.
It prints ['name', 'is', 'asha', 'i', 'like', 'tea'].
message changes from 'i like tea' to 'what is my name'.
Four more words: 11 in all.
The model now sees "like tea what is my name". The name has gone.
It prints ['like', 'tea', 'what', 'is', 'my', 'name'].
Python moves to the next item of the loop: for message in ["my name is asha", "i like tea", "what is my name"].
Is "asha" anywhere in what the model can see?
No. Asked "what is my name", this model cannot know: the answer has fallen out of its window. Apps work around this by summarising old messages, keeping key facts pinned, or looking things up (RAG).
Common mistakes
Thinking a chat model remembers everything you ever said to it
Pasting huge documents and expecting every detail to be used
Best practices
Repeat key facts, summarise long chats, or retrieve only what is needed (RAG)
Key takeaways
A model can only read a fixed number of tokens: its context window.
In a long chat, the oldest tokens fall out of the window.
Anything outside the window is invisible to the model.
Summaries, pinned facts and retrieval help work around the limit.
Check yourself
A model's window is 4 tokens. The chat is "a b c d e f". What can it see?
Answer: c d e f. It keeps the most recent 4 tokens.
Which does NOT help with a small context window?
Answer: Asking the same question louder. Only putting the right information inside the window helps.