The craft of context, defined.
36 plain-English definitions for the techniques that decide what a model sees: retrieval, agent patterns, reliability, evaluation, and the ways long-context systems fail. Every applicable entry comes with a runnable, tested Vercel AI SDK example.
Foundations
What context engineering is, and the raw material it works with: the window, the tokens, the prompt.
Retrieval & RAG
Pulling the right information into the window at the right time, instead of hoping the model already knows it.
Chunking
Chunking is splitting a long document into smaller pieces before you embed and retrieve them. The size and overlap of the chunks decide what can be found as a unit, so it quietly makes or breaks a retrieval system.
Read definition →PatternValidatedContextual retrieval
Contextual retrieval prepends a short, generated description of where a chunk came from before embedding it. It fixes the fact that chunking strips away the context a chunk needs in order to be findable.
Read definition →ConceptEmbeddings
An embedding turns a piece of text into a list of numbers that captures its meaning, so that similar ideas land near each other. Embeddings are what let you search by meaning instead of by exact keyword.
Read definition →PatternEmergingGraphRAG
GraphRAG retrieves over a graph of entities and relationships rather than a flat pile of chunks, so the model can follow connections between facts. It answers questions that need several hops, which similarity search cannot reach.
Read definition →PatternValidatedHybrid search
Hybrid search runs a keyword search and a vector search over the same corpus and merges the two result lists. It exists because embeddings are good at meaning and bad at exact strings, and keyword search is the other way round.
Read definition →PatternProvenReranking
Reranking retrieves a generous set of candidates cheaply, then reorders them with a slower, more accurate model before any of it reaches the context. It buys precision at the top of the list without paying that cost across the whole corpus.
Read definition →PatternProvenRetrieval-augmented generation (RAG)
RAG is the workhorse pattern of context engineering: retrieve the material relevant to a request, put it in the context, and let the model generate an answer grounded in it rather than guessing from memory.
Read definition →ConceptVector database
A vector database stores embeddings and finds the nearest ones to a query vector quickly. It is an index for meaning, and for small corpora you very often do not need one.
Read definition →Agent patterns
The shapes an LLM system can take, from fixed workflows to autonomous agents that choose their own path.
Agents vs. workflows
A workflow follows a path you designed in advance; an agent decides its own path at run time by calling tools in a loop toward a goal. Knowing which one you actually need is the first context-engineering decision.
Read definition →PatternValidatedEvaluator-optimizer
Evaluator-optimizer pairs a generator with a separate critic that scores its output and sends it back for revision. It works when quality is easier to judge than to produce, which is more often than you would expect.
Read definition →PatternValidatedOrchestrator-workers
Orchestrator-workers has a central model decide how to break a task down at run time, dispatch the pieces to workers, and combine what comes back. It is parallelization for tasks whose shape you cannot know in advance.
Read definition →PatternProvenParallelization
Parallelization runs several model calls at once and combines the results, either by splitting a task into independent parts or by asking the same question repeatedly and aggregating. It buys latency in one form and reliability in the other.
Read definition →PatternValidatedPlan-and-execute
Plan-and-execute writes the whole plan first, then carries out the steps. Separating the two makes the plan reviewable before any work happens, which is the entire point.
Read definition →PatternProvenPrompt chaining
Prompt chaining breaks a task into a fixed sequence of steps, feeding each step’s output into the next. It is the simplest workflow pattern, and it beats one giant prompt whenever a task has natural stages.
Read definition →PatternProvenReAct
ReAct interleaves reasoning and acting: the model thinks, takes one action, reads the result, and thinks again. It is the loop underneath most agents, and its defining property is that the next step is chosen after seeing the last result.
Read definition →PatternValidatedRouting
Routing classifies an input and sends it to the handler built for it. It keeps each path specialised and lets you send easy cases to a cheap model and hard cases to an expensive one, without any of the cost of a full agent.
Read definition →PatternProvenTool use
Tool use lets a model do more than produce text: you expose named actions with typed inputs, and the model calls them to read data, run code, or reach the outside world. It is the bridge from talking to doing.
Read definition →Reliability techniques
Getting consistent, trustworthy output from a stochastic model that will not give the same answer twice.
Guardrail
A guardrail is a deterministic check that runs around a model call, on the way in or the way out, and refuses to pass something through. It is ordinary code enforcing what a prompt can only request.
Read definition →PatternValidatedRetry and repair
Retry and repair feeds a failed validation back to the model as the next input, so it fixes its own output instead of you regenerating blind. It converts a hard failure into one more turn, with the error as the instruction.
Read definition →PatternValidatedSelf-consistency
Self-consistency samples the same prompt several times and takes the majority answer. It trades a few extra calls for a big drop in variance, turning a model that sometimes slips into one that reliably lands on its best answer.
Read definition →PatternProvenStructured outputs
Structured outputs constrain a model to return data matching a schema you define, rather than prose you have to parse. It removes an entire class of failure: the model answered correctly and your code could not read it.
Read definition →Evaluation
Measuring whether your system is actually any good, so you can improve it on purpose rather than by vibes.
Eval set
An eval set is a fixed collection of real inputs with known-good outputs that you score your system against. It is what turns "that felt better" into a number you can compare across changes.
Read definition →AntipatternProvenGoodharting
Goodharting is optimising a system until it satisfies the metric rather than the goal the metric stood for. Your eval score climbs, real quality does not, and the number you trusted is now the thing hiding the problem.
Read definition →PatternValidatedLLM-as-judge
An LLM-as-judge uses one model call to score the output of another against a rubric. It is how you evaluate fuzzy, open-ended work at scale when there is no single correct answer to match against.
Read definition →PatternValidatedPairwise comparison
Pairwise comparison asks which of two outputs is better rather than scoring either in isolation. Relative judgements are far more consistent than absolute ones, which makes it the reliable way to tell whether a change actually helped.
Read definition →ConceptRubric
A rubric is the explicit set of criteria a judge scores against, with each level spelled out. Without one, asking a model to rate quality from 1 to 10 produces numbers that mean nothing and drift between runs.
Read definition →Failure modes
The predictable ways long-context systems break, so you can see them coming.
Context pollution
Context pollution is one wrong or irrelevant thing in the window steering everything downstream of it. Unlike context rot it is not gradual: a single bad passage is enough, and the model treats it as given.
Read definition →AntipatternProvenContext rot
Context rot is the gradual decay of a long session as stale, superseded, and irrelevant text accumulates in the window. Nothing breaks at any single step, which is why it is usually diagnosed as the model getting worse.
Read definition →AntipatternProvenLost in the middle
Lost in the middle is the tendency of models to use information at the start and end of a long context well, while missing what sits in the middle. It means a bigger context window does not automatically mean better recall.
Read definition →AntipatternProvenPrompt injection
Prompt injection is untrusted content in the context being followed as instruction. It is not a prompting bug to be patched but a structural consequence of putting data and instructions in the same channel.
Read definition →Memory
Carrying the right state across turns and sessions without drowning the window in history.
Checkpoint
A checkpoint is a deliberate save point holding enough state to resume a task from there. It turns a long run from something that either finishes or is lost into something that can be picked up.
Read definition →ConceptConversation history
Conversation history is the running list of past turns you re-send on every request so the model appears to remember. It is the simplest form of memory, and the first thing to overflow a context window if you never prune it.
Read definition →PatternProvenExternalized state
Externalized state keeps the durable facts of a task in files rather than in the conversation, so the window holds pointers instead of being the record. It is what makes a long task survive a context that cannot.
Read definition →ConceptMemory write policy
A memory write policy is the rule deciding what gets remembered, when, and for how long. Most memory systems fail on the write side rather than the read side: they save too much, and retrieval drowns.
Read definition →PatternValidatedScratchpad
A scratchpad is a place the model writes intermediate work it will read back later, rather than holding it in the answer. It separates thinking from output, and gives the working a home that is not the context window.
Read definition →