# Context window

> A context window is the maximum amount of text, measured in tokens, that a language model can take in and produce in a single request, including instructions, documents, conversation history and its own reply.

Also called: context length, context size, token limit, context limit. Category: Models and training. Source: https://aibuildindex.com/glossary/context-window

## In the index

- Search over internal documents: median $2,150, middle half $300 to $8,800, 918 priced briefs (https://aibuildindex.com/cost/document-search-rag)
- Large language models: median $4,720, middle half $1,000 to $16,000, 605 priced briefs (https://aibuildindex.com/skills/large-language-models)

A language model has no memory between requests. Everything it knows about your task has to fit into one input: the instructions, any documents, the conversation so far and room for the answer. The context window is the size limit on that input, counted in [tokens](https://aibuildindex.com/glossary/token). It shapes what an AI build can do in one step, and it is one of the main reasons builds need retrieval, summarising or memory design rather than simply handing the model everything.

## How it works

Each request to a model is assembled from parts: a system prompt, perhaps some retrieved passages, the recent conversation, the user's latest message. The total, plus the tokens the model will write back, must stay within the window. If it does not, the request fails or older material has to be dropped.

Context windows have grown considerably, and some models now accept very long inputs such as whole contracts or code bases. A larger window does not mean the model uses all of it equally well. Models can overlook details buried in the middle of a long input, and a long input is slower and more expensive to process every time.

So builds usually manage context deliberately. A contract review tool might split documents into passages ([chunking](https://aibuildindex.com/glossary/chunking)), retrieve only the clauses relevant to a question, and keep a running summary of the conversation instead of the full transcript. Longer-running assistants use [agent memory](https://aibuildindex.com/glossary/agent-memory) to store facts outside the window and bring back only what is needed.

## What it means for cost

The context window affects cost in two directions. In running costs, every token placed in the window is billed on every request, so a design that sends a full manual with each question costs far more per answer than one that retrieves a few passages. [Prompt caching](https://aibuildindex.com/glossary/prompt-caching) can soften this when the same long prefix is reused.

In build costs, working within the window is real engineering. Deciding what to include, testing whether the model still finds the right detail, and handling inputs that are too long all take time. A builder who says the model's window is big enough to skip retrieval should be asked how answer quality, speed and per-request cost were tested at realistic document sizes.

## Common questions

### Is a bigger context window always better?

Not necessarily. It allows more material per request, but costs and response times rise with input length, and accuracy on details can drop in very long inputs. Many production builds deliberately send less than the maximum.

### Does a large context window replace RAG?

For a small, stable set of documents it can. For large or frequently changing collections, [retrieval-augmented generation](https://aibuildindex.com/glossary/retrieval-augmented-generation) is usually cheaper and more accurate, because it sends only the passages that matter and can cite where answers came from.

### What happens when a conversation exceeds the window?

The application has to decide what to drop or compress, for example older messages or a summary in place of the full history. If nothing manages this, the request fails, which is a common gap in quickly built chatbots.

## Related terms

- [Token](https://aibuildindex.com/glossary/token): A token is the small unit of text, often a word or part of a word, that a language model reads and writes, and the unit that most AI providers use to measure and bill usage.
- [Retrieval-augmented generation (RAG)](https://aibuildindex.com/glossary/retrieval-augmented-generation): Retrieval-augmented generation is a way of answering questions with a language model that first looks up relevant passages in your own documents, then writes an answer grounded in what it found.
- [Prompt caching](https://aibuildindex.com/glossary/prompt-caching): Prompt caching is a provider feature that stores the processed form of a repeated opening section of a prompt, such as long instructions or a reference document, so later requests that reuse it are cheaper and faster.
- [Agent memory](https://aibuildindex.com/glossary/agent-memory): Agent memory is the set of techniques that let an AI agent keep and reuse information beyond a single model call, such as the current conversation, facts about a user, past actions or lessons learned, so it can act consistently over time.
- [Chunking](https://aibuildindex.com/glossary/chunking): Chunking is the step in a retrieval system that splits long documents into smaller passages before they are embedded and indexed, so that a search can return the specific section that answers a question rather than a whole file.
