2.Phase 2
Tokens and context window
Step 1: Every conversation becomes tokens
When you type:
What is Docker?
The AI doesn't see it as a sentence.
It first converts it into tokens (small pieces of text).
For example (not exact):
"What"
" is"
" Docker"
"?"
Suppose these are 4 tokens.
Now imagine you write a long paragraph.
Can you explain Docker, Kubernetes, containers, networking...
That might become 200 tokens.
The AI doesn't count messages.
It counts tokens.
Step 2: The AI has limited working memory
Imagine you're solving a math problem on a whiteboard.
Your whiteboard can only hold 100 words.
You start writing.
Question
Formula
Step 1
Step 2
Step 3
Eventually the board becomes full.
If you need more space, what do you do?
You erase the oldest writing.
The AI works exactly like this.
Its whiteboard is called the Context Window.
The context window is the maximum number of tokens the AI can keep in its working memory at one time.
Step 3: Why is it called a "window"?
Imagine looking through a train window.
You can only see what's inside the window.
Everything behind the train is gone.
Similarly, the AI can only "see" the tokens that fit inside its context window.
Older tokens fall outside the window.
Step 4: Example Conversation
Suppose an AI has a context window of 20 tokens (real models are much larger).
You start chatting.
Message 1
My name is Rahul.
Uses 5 tokens.
Memory:
My
name
is
Rahul
.
Message 2
I live in Mumbai.
Uses another 5 tokens.
Now memory contains 10 tokens.
My name is Rahul.
I live in Mumbai.
Message 3
I like football and cricket.
Another 8 tokens.
Now memory contains 18 tokens.
Everything still fits.
The AI remembers all three messages.
Message 4
Now you send
Explain machine learning in detail...
This message adds 15 more tokens.
Total becomes
18 + 15 = 33 tokens
But the AI can only hold 20 tokens.
So it removes the oldest tokens first.
Now the memory becomes something like
I like football and cricket.
Explain machine learning in detail...
The first message
My name is Rahul.
has disappeared.
Now you ask
What is my name?
The AI may answer
"I don't know."
Not because it forgot forever.
But because those tokens were pushed out of the context window.