AI Context Windows
Table of Contents + β
In the last lesson, you learned AI Transformers and Attention. Now we need context windows. This simply means: how much information the model can see at one time.
Here is what fits inside context:
π§ What Is Context?
In an AI request, context means the information available to the model right now.
In normal English, context means background information.
Example:
- If I say βit is too expensiveβ, you need context to know what βitβ means.
- Am I talking about a phone, a course, a car, or a server?
- Without context, the sentence is unclear: The listener cannot know what βitβ refers to.
AI works in a similar way. The model needs enough background information to answer properly.
Instructions
System and developer instructions can say things like `answer in simple English`, `return JSON`, or `do not reveal private data`.
Conversation
Recent messages let the model know what `this`, `that`, or `make it shorter` refers to.
Documents
RAG apps add selected document chunks into context before asking the model.
Context can include:
| Context part | What it means |
|---|---|
| System instructions | Hidden instructions that tell the model how it should behave, like βanswer safelyβ or βbe conciseβ. |
| Developer instructions | App-level rules written by the developer, like βanswer only from provided documentsβ. |
| Conversation history | Old messages from the same chat, so the model knows what was already discussed. |
| The userβs latest question | The new message the user just typed. |
| Retrieved documents | Document parts the app finds and adds, so the model can answer from real information. |
| Tool results | Results from outside systems, like a database lookup, weather API, or search result. |
The model uses this information to generate the next answer.
π Context Is the Modelβs Working Area
The model can only work with what is in front of it.
- If the refund policy is in context, the model can use it.
- If the refund policy is not in context, the model may guess.
- If old chat history is removed, the model may not know what was discussed.
- If the context contains wrong data, the model may repeat wrong data.
So context quality matters as much as model quality.
π Context in ChatGPT, Claude, and Gemini
Pasting a document
When you paste a long document into a chat app, it must fit inside the model context window.
Long conversation
If old messages do not fit in the context window, the model cannot use them in the next answer.
App-added context
AI apps can silently add instructions, selected document text, or user settings before sending the final request to the model.
πͺ What Is a Context Window?
A context window is the maximum amount of text the model can handle in one request.
Window does not mean a browser window here. It means the limited space available for information.
+--------------------------------+| Context window || || System instructions || Conversation || Retrieved documents || User question || Space for output |+--------------------------------+The size is measured in tokens.
So a context window is like a fixed-size notebook page. You can write only so much on it.
So if the request is too large, the app must remove, summarize, or retrieve less information.
π What Happens When Context Is Too Large?
The application must make a decision.
- Reject and ask for smaller input: If the user pastes a huge document, the app can ask them to upload a smaller part.
- Summarize older messages: If the chat is long, the app can keep a short summary instead of sending every old message.
- Remove irrelevant chunks: If some document parts do not help the question, the app should not send them.
- Retrieve fewer documents: In RAG, the app can fetch only the top useful sections instead of many weak sections.
- Split the task: If one request is too big, the app can handle it in smaller steps.
Bad apps hide this problem. Good apps manage it clearly.
Context decides what the model can use
If the answer depends on a document, that document must be available in the current context.
User asks: What is our refund policy?
Good context:Refund policy document included or retrieved
Bad context:No policy document includedWithout the right context, the model may guess.
π§ Context Window Is Not Memory
This distinction is very important.
- Context window is the information sent in the current request.
- Memory is information saved somewhere for later use.
An LLM does not automatically remember everything forever.
This point is very important for beginners:
- Chat history shown on screen is not always fully sent to the model.
- Old details may be summarized: The app can keep a short version instead of every old message.
- Some details may be removed: Less useful messages may be left out to save context space.
- Long conversations can exceed the limit: If the chat becomes too long, it cannot all fit into one request.
If an application has memory, that memory is usually implemented by software around the model:
- Database: The app stores facts or user data in tables and fetches them when needed.
- User profile: The app stores preferences like language, role, or learning level.
- Vector store: The app stores searchable document chunks for RAG.
- Conversation summary: The app saves a short version of old chat so it can fit into context later.
- Settings file: The app stores configuration like preferred model, tone, or output format.
π§© Types of Context in an AI App
Not all context has the same job.
- Instructions: These tell the model how to behave, like βanswer simplyβ or βuse only the provided documentβ.
- Conversation tells the model what has already happened, so it does not answer like every message is brand new.
- Documents provide factual grounding, so the model can answer from trusted text instead of guessing.
- Tool results provide live or private information, like account status or current price.
- Examples show the desired format, like βreturn answer in three bullet pointsβ.
When debugging an AI answer, check which type of context was missing or weak.
Do not assume the model remembers
If your application needs stable user preferences or past facts, store them explicitly and decide when to add them back into context.
π€ Why Context Windows Matter
Context affects:
| Area | Why context matters |
|---|---|
| Long document question answering | The app must choose which parts of the document fit into context. |
| Long conversations | Old messages may not all fit, so the app needs summaries or memory. |
| RAG quality | If the wrong document chunks enter context, the answer will also be weak. |
| Cost | More context usually means more tokens, and more tokens can cost more. |
| Latency | More context means the model has more text to process, so the response can become slower. |
| Safety | If the model does not have enough trusted information, it should not guess. |
More context is useful only when it is relevant. Too much unrelated context can confuse the model.
π§© What Youβve Learned
- β Context is the information the model can see in the current request.
- β Context window and memory are different: context is sent now, memory is stored for later.
Check Your Knowledge
Test what you learned. Pick an answer for each question, then click Check.
- 1
What is a context window?
Why: The context window is the token-limited space for instructions, conversation, documents, and output.
- 2
Is context window the same as memory?
Why: Memory is stored by the application; context is what is sent in the current request.
- 3
What should an app do with very long documents?
Why: Relevant chunks usually work better than sending everything.
- 4
Why reserve room for output?
Why: The model's reply also uses tokens, so input text and output text both count toward the limit.
π Whatβs Next?
When we build a support bot, we want steady answers. When we build a story bot, we may want creative answers. Next, let us learn the settings that control this.