AI Engineer World's Fair 2026
Beyond RAG: A Relational Context Engine That Cuts Token Burn — Unblocked
Read the talk
Beyond RAG: A Relational Context Engine That Cuts Token Burn
Peter Werry explains how Unblocked connects code with organizational history, then builds a document query engine that turns natural-language questions into validated, time-scoped database queries.
From a talk by Peter Werry
At a glance
Ideas worth remembering
Task-specific context connects code with architecture documents, PRs and conversations, reducing the discovery work an agent must perform.
Identity, time, state and aggregation questions require structured queries alongside semantic retrieval.
Schema discovery and identity matching can use procedural methods, reserving the model for query synthesis or ambiguous matches.
Validate model-generated operations and inject tenant constraints outside the model’s control.
Retries can produce an allowed query that misses the intended meaning. The authentication example needed full-text search as well as error feedback.
The local context engine simulator tests task-specific bundles through A/B comparisons on the same task.
The new employee problem follows agents into the codebase
A new employee can read the code and still miss why it works that way. Architecture documents explain some decisions; pull requests and conversations explain others. Incident history carries the “battle scars” that make an apparently straightforward change risky. Peter Werry, founding engineer at Unblocked, starts with this familiar discovery problem: before coding agents, people assembled that context themselves.
A context engine pulls that scattered institutional knowledge together. In Werry’s definition, the output is grounded context: information connected across sources, selected for the task, personalized to the user and aware of permissions. The useful unit is therefore more than a relevant document. It is a set of related evidence that helps explain the work in front of the agent.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Give Claude the architecture and the discussion behind the code
The first comparison asks Claude to plan an optimization of an internal component. Without a context engine, Claude starts by searching the codebase and assembling its own understanding. It eventually produces a recommendation, although Werry adds the familiar qualification: it at least “confidently projects” that it has figured things out.
With Unblocked attached, Claude calls the context engine and receives a task-specific bundle. The bundle connects source code with Notion architecture documents, pull requests and Slack conversations about optimizing the component. Those links also give Claude places to investigate further. Instead of discovering every relationship through successive searches, the agent starts with related material already assembled.
Werry reports $1.29 and about a minute and thirty seconds for the session with context, compared with up to $2.60 and three minutes without it—approximately a 50% cost reduction. These are results from the displayed sessions, rather than a general benchmark. They illustrate the proposed economy: useful context can reduce the exploration an agent performs before it can produce a plan.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
A regression needs history as well as code
The next example starts with a change in product behavior. Richie, a colleague working on Unblocked’s code review product, notices that it is surfacing fewer issues. Unblocked narrows the investigation to a likely cause: a model switch changed the review behavior. That remains a diagnosis presented in the demonstration; the recording does not establish a controlled causal test.
Richie then asks Unblocked to fix it. The system creates a pull request whose description connects the earlier PR associated with the regression, a Slack discussion and relevant data. The important relationship runs across systems: a code change records what changed, a conversation supplies the surrounding interpretation, and product data helps explain the symptom. Together, those sources inform the proposed fix.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
“My PRs last week” requires a query
The build portion begins with a distinction inside the same organizational data. PRs, reviews, comments, tickets, documents and conversations contain searchable content, but they also have structure. RAG can find code, the PR that changed it and the thread debating it. An agent loop with additional file-search tools can carry that investigation further.
Other questions require selecting and computing over records:
- Identity and time: Which PRs did I merge last week?
- Counts and rankings: Who reviewed payments the most?
- State: Which PRs are open?
- Time series: Show a weekly ratio chart since January 1st.
The time-series request was how Richie’s investigation began. Retrieving semantically similar text does not itself compute a weekly series over the underlying records. That requires a query engine. Werry describes retrieval as having two halves: semantic retrieval for relevant content, and structured retrieval for filters, temporal conditions and aggregations.
Generating the query is the easy part of this design. The surrounding system must tell the model which fields exist, resolve a person’s name to the identifier used by the source system, validate the proposed operations and recover from errors. A fluent query can still be dangerous or cross tenant boundaries. Natural language makes the interface convenient; it does not make the resulting database operation trustworthy.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Discover the schema, resolve the person, then synthesize
The open-source Document Query Engine starts as an unwired demo: a question produces nothing. Werry adds the surrounding capabilities in stages. The first is automatic schema discovery. For the Mongo document store, the engine samples documents and derives a schema at runtime, giving the model a description of the data it can query.
Inferring enums—fields with a limited set of possible values—is one tricky part of that discovery. An LLM can help, but Werry’s preference is to get as far as possible with procedural methods. Work that looks uncertain at first can still admit a deterministic solution. The resulting demo exposes the schema of a GitHub pull-request collection along with indexes that can help query performance. Because discovery uses samples, it describes the sampled documents rather than guaranteeing that every possible document shape has been seen.
Identity resolution follows the same preference for simple machinery. A human name in a question may differ from a GitHub username or an identity in another system. Procedural matching, including fuzzy matching, connects those identities. If several candidates remain, the model can act as a tiebreaker over a supplied list rather than inventing an identifier.
Query synthesis then receives the discovered schema, the current date and time, and potentially information about the requesting user. Each input removes an ambiguity: the schema constrains field choices, the clock grounds relative periods, and user information lets “my PRs” refer to the right person. With these pieces connected, the demo generates a query and pulls documents.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Keep database permissions outside the model’s proposal
Validation is the most important stage in Werry’s account. The proposed query is untrusted even when synthesis has the right schema. Two kinds of control matter:
- Operator restrictions: Reject dangerous operations, such as a function operator that executes raw JavaScript on the database server.
- Protected fields and tenant constraints: Keep hidden metadata out of the model’s choices. If a tenant ID must constrain every query, inject that constraint behind the scenes rather than asking the model to manage it.
The next question makes validation observable: find PRs with authentication in the title. The model produces a regular-expression approach, and the demo’s validator rejects it because regular expressions are disallowed. This is an application policy demonstrated by this engine. Rejection preserves the restriction, but it also leaves the user’s useful question unanswered.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
A safe retry can still answer the wrong question
The retry mechanism feeds the error back to the LLM and asks for a revised query. Technically, it is a loop with a maximum retry count. Validation errors—and, in the broader design, database execution errors—become information the model can use to correct its next attempt.
The authentication-title question now gets through after a couple of attempts, but the correction introduces a different problem. The query uses an exact title match, and no PR has that exact title. The model has found an allowed operation while losing the intended search behavior. Passing validation establishes that a query is permitted; it does not establish that the query expresses the user’s intent.
Adding full-text search supplies the missing capability, and the next attempt succeeds in the demonstration. The same request—find PRs with authentication-related text in their titles—produces three different outcomes:
| Proposed query behavior | Validation or result | What changes next |
|---|---|---|
| Regular-expression title search | Rejected by the demo’s validation policy | Return the error to the model |
| Exact title equality | Allowed, but finds no matching PRs | Recognize that a permitted query can still miss the intent |
| Full-text title search | The next demonstration succeeds | Supply a permitted search capability, rather than retrying exact equality |
The relationship to notice is that feedback and capability do different jobs. Error feedback helps the model stop using a forbidden operation. Full-text search gives it an operation capable of answering the original question. The completed engine combines structured retrieval with a text-search capability rather than expecting retries alone to solve the problem.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Turn retrieved records into an answer—and test context locally
The final agent demonstration combines the capabilities in a broader question: “What authentication-related things have we been working on last week?” The engine supports filters, aggregations and time-scoped queries; the chat interface shows the queries it creates, then reasons over the retrieved data. Structured retrieval supplies the records that the answer needs, while the agent turns those records into an explanation.
The ending returns to the practical question raised by the first cost comparison: does pre-gathered context help your agent on your tasks? Werry introduces an open-source context engine simulator for environments where connecting Unblocked immediately is impractical. It runs locally, creates a context bundle for each task, and uses that bundle in an A/B test against the same task. That offers a way to investigate the value of context in a particular workflow before wiring in the full product.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Resources
From the talk
Unblocked’s open-source tool for comparing coding-agent runs with and without gathered context.
Read the transcript and explore slides
Loading transcript and slides…