- System prompt — instructions the application supplies to the model (for example, “Answer only from the supplied incident data”).
- User prompt — the question the user types (for example, “Why did our deployment fail?”).
Why context engineering matters
- A polished prompt cannot compensate for missing context — if logs or private documents never reach the model, the answer will be limited.
- Token limits force trade-offs: include more relevant data or longer instructions, but not both.
- Retrieval-augmented generation (RAG) is how you bring external knowledge into the model’s working memory without exhausting tokens.
Typical sources that occupy the context window
Retrieval-augmented generation (RAG) in brief
Because you can’t forward thousands of documents directly, RAG pipelines:- Index a large document collection using embeddings.
- Use vector search to find the most relevant passages (top-k).
- Insert only those passages into the context window alongside the system and user prompts.
Key distinctions
- Prompt engineering: improves instructions (system prompt) and the user’s explicit question.
- Context engineering: decides what the model actually sees before it generates a response (everything placed in the context window).
- Practical impact: better context (right logs, relevant document passages, concise history) yields better answers.
Practical techniques for context engineering
- Prioritize content
- Include the most relevant logs, error messages, or concise summaries first.
- Place the highest-value items near the beginning of the context block so they’re less likely to be trimmed.
- Chunk and summarize
- Break long documents into smaller passages and summarize each chunk.
- Use automated summarizers to compress repeated context.
- Use retrieval (RAG)
- Index content with embeddings and fetch the top-k relevant passages rather than sending entire documents.
- Tune k to balance breadth vs token cost.
- Control token usage
- Trim boilerplate, shorten system prompts, and remove unnecessary conversation history.
- Prefer structured outputs from tools (which can be summarized) over verbatim dumps.
- Use tools where appropriate
- Invoke log parsers, diagnostics, or structured APIs and insert only their essential outputs into the context.
- Cache useful summaries
- Store compressed context (e.g., summarized incident state or metadata) for quick reuse in follow-up queries to avoid re-retrieving everything.
Example RAG / API request pattern
A typical flow to assemble context before calling a model:- Retrieve top-k passages from the vector store.
- Summarize or filter those passages.
- Construct the system prompt, concatenated with prioritized passages and the user question.
- Send the assembled request to the model.
Practical tuning checklist
- Limit conversation history to recent, relevant turns.
- Place critical logs and error summaries near the top of the context.
- Compress repeated diagnostic content into short summaries.
- Use vector DBs and embeddings for fast, relevant retrieval.
- Monitor token usage and adjust top-k or passage lengths to stay within limits.
Tools & references
- Embeddings + vector stores: FAISS, Milvus, Chroma, Pinecone
- RAG patterns and engineering: see articles on retrieval-augmented generation and production pipelines
- Token considerations: use model documentation for exact context window sizes (e.g., ~8k, 32k tokens)
- Retrieval-Augmented Generation (overview)
- Vector search and similarity
- Pinecone vector DB
- FAISS (Facebook AI Similarity Search)
Context engineering = deciding what the model actually sees. You can tune prompts, but the answer is limited by the context window. Retrieval (RAG), summaries, and selective inclusion of logs/documents are the practical levers to improve answers.