# What is context engineering?

Context engineering is deciding what goes into a language model's context window, in what form and in what order, so that scarce tokens carry signal.

Context engineering is the practice of deciding what information goes into a language model's context window, in what form and in what order: retrieved documents, tool results, instructions and history. Because context is finite and every token costs money and attention, the discipline focuses on selecting high-signal content and cutting noise.

## How is context engineering different from prompt engineering?

Prompt engineering is about wording: phrasing instructions so the model behaves. Context engineering is about curation: assembling everything else in the window. Which documents get retrieved, how they are trimmed, which tool outputs are kept, how much conversation history survives, and what gets summarized instead of quoted. As models improved, clever phrasing mattered less and the quality of the supplied material mattered more. In agentic and [RAG](https://millionshort.com/docs/glossary/what-is-rag) systems, much of the engineering effort now goes into assembling context.

## Why does it matter?

Three constraints make the context window a scarce resource:

- **It is finite.** Even large windows fill quickly once you add system instructions, tool definitions, history and retrieved pages.
- **Attention degrades.** Models tend to use a small, relevant context better than a large, padded one, and a key passage buried under filler is easier to miss.
- **Tokens are money and latency.** Every token is paid for on every call, so junk context is a recurring cost.

The upshot: adding more context is not free and is often not even helpful. The job is to maximize signal per token.

## What are the core techniques?

- **Selection.** Retrieve fewer, better documents. Rerank. Remove near-copies before they reach the prompt.
- **Compression.** Strip boilerplate, summarize long documents, and keep quotes only where the wording matters.
- **Ordering.** Put critical evidence where it is least likely to be overlooked, commonly near the start or the end of the window, and group related material.
- **Budgeting.** Give each component (instructions, history, retrieval, tool output) an explicit token allowance and enforce it.
- **Isolation.** In agent systems, keep the context of a sub-task in a sub-agent and pass back conclusions, not transcripts.

## Where do most context budgets leak?

Retrieval. A single noisy web fetch can put thousands of tokens of navigation, filler and duplicated rewrites into the window. This failure mode is called [RAG noise](https://millionshort.com/docs/glossary/what-is-rag-noise). That is why context engineering starts at the retrieval layer, before any trimming: cleaner, deduplicated sources shrink the problem at its origin.

## Where MillionShort fits

MillionShort search gives you a few direct levers on the retrieval budget. `max_chars_per_result` sets the longest snippet (up to 2,000 characters, 800 by default), and `num_results` sets the length of the one merged list. Duplicates across sources are removed before the list is returned. `remove_top_sites` and domain rules change which sites can appear at all. See [low-noise RAG](https://millionshort.com/docs/use-cases/low-noise-rag) for how these combine.

## Related terms

- [What is LLM grounding?](https://millionshort.com/docs/glossary/what-is-llm-grounding)
- [What is source diversity in RAG?](https://millionshort.com/docs/glossary/what-is-source-diversity)
