Loading...

Loading...

Understanding Context Window
Loading like and share buttons...
#llm#ai#context#artificialintelligence

Understanding Context Window

Tomer Raitz
Tomer Raitz
Jan 294 min read

In our previous posts, we talked about prompting techniques Basic Prompting Techniques and Reasoning Prompting Techniques. Now, let’s understand: What is context? Why is it so important? And how does it work? There are three main concepts we need to grasp.

1. What are tokens and how do they impact context?

Each time we ask an LLM a question, it calculates the number of tokens involved. Every model has a maximum limit of tokens—known as the Context Window—that it can process at any given time.

How does it work? When an LLM is trained, a "dictionary" of tokens is created. For example, the word "hello" might be assigned the ID 57. When the LLM receives text, it breaks the string down, finds the corresponding IDs in its dictionary, and processes those numbers.

2. What is the Context Window?

As we mentioned earlier, each model has a limit on the number of tokens it can handle in a single session. This is called the Context Window. For example, Claude ops 4.5 has a max context window of 200k tokens.

Why is it important? It means you cannot overload the LLM with infinite questions or data. You are always limited by the maximum capacity of the model's "memory."

3. What is "Context Rot" and why does it matter?

We’ve covered the technical side, but what is "context" in a practical sense? Context represents the connections between subjects discussed in a conversation. When we start a new session with an LLM, we should aim to stay focused on a specific subject with specific data. This helps avoid Context Rot.

What is Context Rot? Context rot occurs when an LLM is forced to process too many tokens or too many unrelated topics. As the window fills up, the LLM's responses often become less accurate or "forgetful." Furthermore, adding unrelated tangents to a chat increases noise, which accelerates this decay in quality.

There is a interesting research about the subject - link

Example: High-Noise Context (Messy):

📝Markdown
1
2
3
4
5
6
7
8
9
John: Hey Dani, how’s it going? 
Dani: Good! How about you? 
John: Doing well, just a bit sleepy. I stayed up until 2 a.m. finishing "Stranger Things". 
Dani: I’ve never seen it—is it any good? 
John: It’s great! I’m a huge sci-fi fan. Have you seen any of the Marvel movies? 
Dani: Yeah, but they’re not really my thing. 
John: No way! I love Spider-Man. I used to watch the animated show all the time as a kid. 
Did you ever see that one?
....

In this exchange, John jumped between three subjects: Stranger Things, Marvel, and the Spider-Man TV show. If John later asks a specific technical question, Dani has to filter through all this unrelated "noise."

Example: Clean Context (Focused):

📝Markdown
1
2
3
4
5
6
7
8
9
10
11
John: Hey Dani, how’s it going? 
Dani: Good! How about you? 
John: Doing well, just a bit sleepy. I stayed up until 2 a.m. finishing Stranger Things. 
Dani: I’ve never seen it—is it any good? 
John: It’s great! I’m a huge sci-fi fan. It starts with a group of kids 
playing Dungeons and Dragons, and the cool part is that the monsters from 
the game actually come to life. 
Dani: How many seasons are there? 
John: There are five, and each episode is about an hour long. 
They’re all connected, so every episode really impacts the next one. 
Dani: Sounds interesting! Maybe I’ll check it out.

Comments

0 comments

Enter your comment. Maximum 2000 characters.

No comments yet. Be the first to share your thoughts!
Vibki logo wave icon
Vibki Surfing Bot
Vibki

Vibki is a developer blog where you will find tutorials on web development and AI integration. Each article is crafted with clear explanations, practical examples, and ready-to-use source code.

Talk to me
Copy email
LinkedIn
GitHub
Dev.to