What Is Context? Context Windows & Tokens for LLMs
Your bar: explain why an LLM cannot see your whole codebase, what actually fills the context window, and why context retrieval — not the model — is where modern AI systems win or lose.
Your bar: explain why an LLM cannot see your whole codebase, name what actually competes for the context window, and argue, against an interviewer pushing back, why context retrieval usually beats model choice. By the end you can answer the north-star question: why does one AI system feel far smarter than another when both run the same LLM? 1
The whole answer fits in one sentence. Each chip is one thing this lesson makes permanent:
What Is Context?
Context = the model’s entire world for one call. It has no other access to your data — no DB connection, no filesystem, no memory of last time. Only what you pack into the window.
The window is a fixed budget — and you don’t own all of it
The four words, pinned down
| Term | Simple definition | Unit / shape | One-line analogy |
|---|---|---|---|
| Context | Everything the model can see for one call: prompt + history + retrieved data + tools + the question. | text | The model’s entire RAM at runtime. |
| Context window | The fixed maximum tokens per call (input + output together). | tokens (a hard ceiling) | Total installed RAM — physical limit. |
| Token | The sub-word chunk the model counts in (~4 chars / ~¾ of a word). | ~0.75 words | The byte the budget is measured in. |
| Working context | The curated subset you actually assemble for this turn — the relevant few, not all that exists. | text (selected) | The pages you put on the desk, not the whole library. |
answer = f(context). Change nothing but the context and you change the answer.Why an LLM can’t just “see the whole codebase”
Memory check
- What are the four budget tenants of the window besides retrieved context? → system prompt, tool/function definitions, conversation history, and the reserve for the answer
- Why can't a bigger window fully fix retrieval? → real systems exceed any window; bigger costs more + slower; models recall the middle of long contexts poorly (position bias)
- A token is roughly how many words? → ~¾ of an English word; ~4 characters
An engineer says “let’s just use the 1M-token model and paste the whole repo in.” Where is this wrong?
Hit these points: real repos exceed even 1M tokens, so you still choose a subset → cost and latency scale with tokens sent, so you’d pay 5× for mostly-irrelevant text → long-context recall is uneven — relevant lines in the middle get “lost in the middle” → noise lowers signal: irrelevant code actively degrades answers, it isn’t free padding → the right framing is “select the smallest sufficient context,” not “fit more in.”
Context Is the New Database Query
In classic software, the query fetches from the DB and the engine answers. In AI, the model is fixed — so the context-retrieval step is the new query, and that’s where the engineering value (and the bugs) moved.
The inversion that matters
| Classic software | AI system | |
|---|---|---|
| Fixed / commodity part | The query language (SQL is SQL) | The model (everyone can rent the same LLM) |
| Where the value lives | Schema + indexes + the DB’s data | Retrieval + selection + assembly of context |
| Your competitive moat | Your data & how you model it | Your data & how you retrieve and pack it |
| A “bad query” causes | Wrong rows / slow scan | Wrong answer — silently, with full confidence |
Why retrieval quality usually beats model quality
| answer quality | Right context | Wrong context |
|---|---|---|
| Best model | ✓✓ excellent | ✗ confidently wrong |
| Smaller model | ✓ surprisingly good | ✗ wrong |
Memory check
- In the pipeline mapping, SQL query corresponds to what? → the context-retrieval step (it decides what the answering engine sees)
- Why is a context bug more dangerous than a SQL bug? → it fails silently — the model answers confidently from wrong input instead of erroring
- One sentence: why does retrieval often beat model choice? → the model only reasons over what it's given; the model is rentable and shared, the context is yours to design
Your AI feature gives wrong answers. A teammate wants to swap to the most expensive model. How do you push back as the senior in the room?
Hit these points: first ask “is this a retrieval problem or a reasoning problem?” → instrument what context was actually sent for the failing cases — usually the right document wasn’t retrieved, so a bigger model just reasons better over the wrong input → “right context + cheaper model often beats wrong context + flagship,” and it’s cheaper and faster → only after retrieval is verified good is model capability the bottleneck worth paying for → name the trade-off: model upgrade is a flat tax on every call; fixing retrieval compounds across every feature.
Frame “context is the new database query” for a VP who knows backend but not LLMs.
Hit these points: in our stack the DB is the source of truth and the SQL query decides what a request sees → with LLMs the model is a rented, commodity engine — the same one our competitors use → so the leverage moves to the “query” that feeds it: which of our data we retrieve and how we pack it into a fixed token budget → that pipeline is where our differentiation, our cost, and most of our bugs now live → therefore we invest in retrieval & context quality the way we’d invest in schema and indexing, not in chasing model versions.
Retrieval practice — test the two modules
Q1. "Context" for an LLM call is best described as…
- A persistent connection the model keeps open to your application's primary database
- The model's long-term memory of every conversation it has previously had with users
- The complete set of text passed in for one call — the model's entire world for that inference
- A cache of recent answers the model replays when it sees a similar question again later
Q2. Besides retrieved data, what else competes for the same fixed window budget?
- System prompt, tool definitions, conversation history, and reserved room for the answer
- The model's weights, the GPU memory, the network buffer, and the API rate limiter
- The embedding index, the vector database, the reranker, and the chunk overlap setting
- Only the user's current question — everything else is stored outside the window entirely
Q3. A bigger context window does NOT fully solve retrieval because…
- Larger windows are only available on open-source models that teams cannot deploy in production
- The model refuses to read more than a few thousand tokens regardless of the window size
- Token budgets are a billing concept only and have no effect on the quality of the answer
- Real systems still exceed it, cost and latency rise, and middle-of-context recall degrades
Q4. In "context is the new database query," the context-retrieval step plays the role of…
- The database engine itself — the durable store that holds the source-of-truth records
- The SQL query — it decides what the answering engine ever gets to see for this request
- The connection pool — it throttles how many requests reach the model concurrently
- The response cache — it stores prior model outputs so identical questions skip the model
Q5. Two products use the identical LLM, yet one feels far smarter. The most likely reason is…
- The smarter one secretly fine-tuned the model on a large private proprietary dataset
- The smarter one pays for priority API access that returns higher-quality model responses
- The smarter one retrieves and assembles better context into the window before each call
- The smarter one simply uses a much larger context window for every single request made
Interview — pick your bar
Answer out loud in ~60s, then reveal. Core = recall · Senior = trade-offs & failure modes · Staff = synthesis under ambiguity · System Design = open design round (a different axis, not a harder level).
Define context, context window, token, and working context, and how they relate.
Besides the documents you retrieve, what else competes for the context window?
What is a token, and why are both the window limit and the bill measured in tokens rather than words or characters?
What's the difference between the context window and the working context?
Why can't an LLM "just read" a 5-million-line codebase to answer a question about it?
A context bug and a SQL bug both return wrong data. Why is the context bug operationally scarier?
"Just use a bigger window and the problem goes away." Why isn't that a real fix?
An answer is wrong. How do you tell whether the context was wrong versus the model being incapable?
Make the case that retrieval quality matters more than model quality — then steelman the opposite.
A teammate wants to "fix" wrong answers by switching to a 1M-token model and pasting the whole repo in. Where does this break at scale?
A strong engineer wants to spend the quarter upgrading the model to fix quality. Make the principal-level call on model-vs-retrieval investment.
- Clarify scale: window size vs total corpus tokens, latency & cost budget.
- Candidate generation — lexical (BM25) + semantic (embeddings), hybrid.
- Rank, then re-rank the top-N for precision.
- Assemble within budget — signatures over full bodies; order for primacy/recency.
- Freshness — index invalidation; fetch volatile/exact data live, don't embed it.
- Observability — log the assembled context per call; measure retrieval hit-rate, not just answers.
- Failure modes & guardrails — missing / wrong / stale / conflicting / excessive.