Weaviate - Context Engineering - Designing System Architectures Beyond Prompting for Robust LLM Applications
If Large Language Models are the new CPUs, what is the operating system that makes them truly work?
Weaviate-Context-Engineering-ebook.pdf
Beyond Prompts: Welcome to the Era of Context Engineering
Virtually every practitioner developing with Large Language Models (LLMs) has hit the same wall. You begin with a powerful model, one with a staggering capacity for writing, summarization, and reasoning. But the moment you try to apply it to a real-world problem, the cracks begin to show: it can’t answer questions about your private documents, remains oblivious to events that happened yesterday, and will confidently "hallucinate" when it doesn’t know an answer.
The root of the problem isn't that the model isn't smart enough; it's that it exists in a fundamentally isolated state. It's like a powerful but disconnected brain, unable to access your specific data, the real-time internet, or even remember your last conversation.
The Model's Dilemma Under the Context Window

This isolation is a direct consequence of a fundamental architectural limitation: the "Context Window." Think of the context window as the model's active working memory—a finite space where it holds the instructions and information for the current task. Every word, number, and punctuation mark consumes a piece of this space. It’s like a whiteboard: once it’s full, old information is wiped away to make room for new instructions, and crucial details can be lost in the process.
Simply writing better prompts cannot fix this fundamental limitation. You have to build a system around the model.
What is Context Engineering?
This is where Context Engineering comes into play. It is the discipline of designing system architectures that provide the right information to the LLM at the right time. It doesn’t seek to change the model itself but rather to build bridges connecting it to the outside world—retrieving external data, accessing real-time tools, and giving it a memory, so its responses are grounded in fact, not just its training data.
Mastering this discipline is the key to distinguishing a passable demo from a truly intelligent system. We are no longer just "prompters" talking to a model; we are becoming the designers and "architects" of the world it operates in.
A complete context engineering system is typically composed of the following core components:
Core Components of Context Engineering

- Agents: Acting as the system's decision-making brain, coordinating how and when information is used.
- Query Augmentation: Transforming users' ambiguous, messy requests into precise, machine-readable intent.
- Retrieval: The bridge connecting the LLM to your specific documents and knowledge bases.
- Memory: Giving the system a sense of history and the ability to learn from interactions.
- Tools: Enabling your application to take direct action and interact with real-time data sources.
Agents: The System's Intelligent Brain
As we begin to build real LLM systems, static pipelines quickly reveal their limitations. For a simple Retrieval Augmented Generation (RAG) task, a fixed "retrieve, then generate" workflow might suffice. But as soon as a task requires judgment, adaptation, or multi-step reasoning, this model breaks down.
This is where Agents enter the scene. In context engineering, agents are responsible for managing the flow of information efficiently and effectively. They don't just blindly execute a script; they can assess known information, identify missing pieces, select the right tools, and adjust their strategy when things go wrong. Simply put, an AI agent is a system capable of dynamic decision-making, maintaining state across interactions, adapting its methods based on outcomes, and using tools autonomously.
Architecture of an Agentic System

However, this brings greater challenges. As context windows grow, new problems emerge, such as context poisoning (erroneous information is introduced and circulated), context distraction (past information interferes with current reasoning), and context conflicts (contradictory information leads to decision paralysis). Therefore, an agent needs not only tools and memory but also a robust "Context Hygiene" mechanism—a way to monitor and manage the quality of its own context, avoid overload, detect irrelevant or conflicting information, and keep its working memory clear for effective reasoning.
Query Augmentation: Turning "Garbage In" into Valuable Instructions
The "garbage in, garbage out" principle is especially salient in LLM applications. No matter how sophisticated the subsequent retrieval algorithms are, if the user's intent is misunderstood from the start, all efforts are in vain. Query Augmentation is the key to solving this problem.
Users' queries are often far from ideal, filled with ambiguity and colloquialisms. Furthermore, different parts of the system, like a vector database and the LLM itself, have different formatting requirements for queries. Thus, we need to augment the original query to suit different tools and processes.
Common query augmentation techniques include:
- Query Rewriting: Reconstructing a user's informal question into a more structured, information-dense query suitable for machines.
- Query Expansion: Generating multiple related queries from a single user input to improve retrieval coverage, especially useful for keyword-based systems.
- Query Decomposition: Breaking down a complex, multifaceted question into several simpler sub-questions that can be processed independently.
Query Decomposition Flow

The most advanced form is the Query Agent, which intelligently handles the entire query process. It leverages an AI agent to dynamically construct queries based on its understanding of the database and data structures, iterating and refining based on the results until the most accurate answer is found.
Retrieval: Finding the Needle in an Ocean of Information
An LLM is only as valuable as the information it can access. To enable a model to leverage your private documents or the latest information, you need an effective Retrieval system. The challenge is that the raw document set is often far larger than the LLM's limited context window. We must find the most crucial snippet within the documents to answer the user's query.
The foundational step to achieving this is Chunking—breaking down large documents into smaller, more manageable parts. This is one of the most critical decisions for the performance of a retrieval system.
The core of any chunking strategy is finding a balance between two competing goals:
The Trade-off Matrix for Chunking Strategies

- Retrieval Precision: Chunks need to be small and topically focused so that a vector search system can find a precise match. Large chunks that mix multiple topics create "noisy" embeddings that are difficult to retrieve accurately.
- Contextual Richness: Chunks must also be large enough to contain complete context, enabling the LLM to understand and generate a meaningful response after retrieval.
From simple fixed-size chunking to more intelligent, structure-aware recursive chunking, and on to semantically-aware semantic chunking and LLM-based chunking, the right strategy depends on the nature of your documents and application needs. It's an engineering decision with no single right answer, but it is a critically important one.
Memory: Giving the System the Ability to Learn and Adapt
If an agent is the brain of the AI, then memory is the soul that gives it life. Without memory, an LLM is just a stateless text processor. Renowned AI scholar Andrej Karpathy once compared an LLM's context window to a computer's RAM and the model itself to the CPU. In this analogy, the context window is the agent's "immediate consciousness," but just like a computer with too many browser tabs open, this "RAM" fills up quickly.
The art of context engineering lies in designing systems that make the most efficient use of this immediate memory while gracefully offloading other information to more persistent storage. This leads to two core tiers of memory architecture:
- Short-Term Memory: This is the agent's immediate workspace, typically the context window itself. It supports instant decision-making and reasoning, with the challenge being how to maintain efficiency within its limited space.
- Long-Term Memory: This involves storing information outside the context window (e.g., in a vector database) and retrieving it quickly when needed via techniques like RAG. This allows the agent to build a persistent understanding of the world and the user across multiple conversations.
Hybrid Memory Architecture

In practice, most advanced systems employ a hybrid memory architecture, combining the speed of short-term memory with the depth of long-term memory. Effective memory management isn't a "write-once" affair; it requires periodic pruning and distillation, selectively storing high-quality information, and mastering the art of efficient retrieval.
Tools: Connecting Virtual Intelligence to the Physical World
If memory gives an agent self-awareness, then Tools give it superpowers. An LLM on its own cannot check the live weather, book a flight, or look up a stock price. Tools are the bridges that connect the LLM to the outside world, enabling it to take real action.
The breakthrough in this area is Function Calling, also known as Tool Calling. This feature allows an LLM to output structured JSON containing the name of a function to call and its parameters. This enables a travel-planning agent, when asked about "flights to Tokyo next Tuesday," to generate a call to a real airline API instead of guessing an answer.
The context engineering work here lies in how these tools are "presented" to the agent. A well-written tool description acts like a micro-prompt, clearly informing the model of the tool's function, required inputs, and expected outputs. The entire process follows a powerful feedback loop, often called the "Thought-Action-Observation" cycle. The agent thinks, selects a tool, acts, observes the result, and then uses that result to inform its next thought.
The future of tool use is moving toward standardization. The Model Context Protocol (MCP), introduced by Anthropic in late 2024, aims to provide a universal standard for connecting AI applications with external data sources and tools. Dubbed "the USB-C for AI," it aims to simplify the complex N×M integration problem into a more manageable N+M problem.
Traditional Integration vs. The MCP Approach

Conclusion: From Prompter to Architect
Context engineering is far more than a simple collection of prompts, retrieval systems, or AI architectures. It is a systemic discipline for building interconnected, dynamic, and reliable systems.
We are transitioning from being "prompters" who talk to models to "architects" who build the worlds they operate in. The competitive edge of the future will not come merely from bigger models, but from superior engineering. This is the era of context engineering.