Semantic Data Processing at Scale with AI-Powered Query Optimization

docetl · Research & Academia · 2025 · source Agentic: yes · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Semantic data processing over unstructured documents

DocETL addresses the problem of running natural-language semantic operators over large unstructured corpora while controlling cost, accuracy, latency, and user steerability.

Constraints:

Architecture

DocETL represents text workloads as semantic operators such as map, reduce, filter, and join; rewrites them using a registry of rewrite directives instantiated by LLM agents; searches candidate plans with cost, accuracy, and latency estimates; applies task cascades and decomposition rewrites to reduce expensive model calls; and pairs the optimizer with Doc Wrangler, an interface that helps users inspect outputs, convert notes into better specifications, and trigger decomposition when complex prompts fail.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  A["Semantic operator pipeline"] --> B["Plan search optimizer"]
  B --> C["Rewrite directive registry"]
  C --> D["LLM rewrite agent"]
  D --> E["Candidate query plans"]
  E --> F["Sample evaluation harness"]
  F --> B
  A --> G["Doc Wrangler interface"]
  G --> H["Expensive LLM judge"]
  H --> A
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Semantic operator pipeline User-authored map, reduce, filter, or join pipeline expressed in natural language. Plan search optimizer, Doc Wrangler interface
Rewrite directive registry Collection of rewrite templates for data decomposition, task decomposition, task cascades, operator fusion, and code replacement. Plan search optimizer, LLM rewrite agent
LLM rewrite agent Instantiates rewrite directives into prompts, schemas, chunk sizes, and new operators. Rewrite directive registry, Candidate query plans
Plan search optimizer Searches the plan space using cost, accuracy, and latency estimates. Semantic operator pipeline, Rewrite directive registry, Candidate query plans, Sample evaluation harness
Candidate query plans Alternative rewritten semantic pipelines explored before full execution. LLM rewrite agent, Sample evaluation harness
Sample evaluation harness Runs samples to estimate accuracy, cost, and latency for candidate plans. Candidate query plans, Plan search optimizer
Doc Wrangler interface Interactive UI for output inspection, feedback notes, assisted specification, and decomposition suggestions. Semantic operator pipeline, Expensive LLM judge
Expensive LLM judge Samples operation results to identify inaccurate attributes and suggest decomposition rewrites. Doc Wrangler interface, Semantic operator pipeline

Data flow

Users author semantic-operator pipelines over document collections, the optimizer selects a pipeline to rewrite, LLM agents instantiate rewrite directives with prompts, schemas, chunk sizes, or synthesized operators, candidate plans are sampled for cost and accuracy estimates, and Doc Wrangler lets users inspect outputs, record feedback, revise specifications, and decompose complex operations before running at corpus scale.

3 supporting quotes
“the idea behind semantic data processing is you have your favorite data processing operators such as map reduce filter etc. You express each operator in natural language”transcript, stated
“First selecting the pipeline we want to rewrite, then rewriting the pipeline using the LLM agent, and then evaluating on samples when needed”transcript, stated
“we use LLM agents to come up with the prompts of the new operators that are substituted into the query plan the prompts the output schemas the chunk sizes”transcript, stated

Why this architecture

DocETL borrows database optimizer ideas because semantic pipelines need plan search, but it extends them with LLM-instantiated rewrites and accuracy modeling because LLM plans vary in quality as well as cost.

3 supporting quotes
“how do we run this at scale and make sure that it works, that people actually get value out of it?”transcript, stated
“how do you make sure it's accurate and how do you make sure it's cheap?”transcript, stated
“Plans vary in accuracy, in quality, and cost, right?”transcript, stated

Models used: LLM agents · LLM judges · proxy models · state-of-the-art LLMs

Scale

Alternatives considered (roads not taken)

Run the original semantic operator plan with the most expensive model

Rejected because: The original plan is treated as the Oracle fallback but is too expensive to apply to every document when cheaper proxy or decomposed tasks can resolve many items.

“Now the Oracle task or the pre-rewritten plan is as follows just running that operation as is with the most expensive model.”transcript, stated
“So you want to resolve as many documents early on so that very few documents pass to that oracle task.”transcript, stated

Let a general GPT agent search for the best pipeline without DocETL rewrite directives

Rejected because: The reported GPT5 agent baseline had access to the query engine and documentation, but DocETL's designed rewrite directives found more accurate and cheaper plans.

“This GPT5 agent baseline is basically I gave the docl query engine to GPT5 and the documentation for docket”transcript, stated
“having these carefully designed rewrite directives for data processing can outperform that agent”transcript, stated

Ask users to manually specify perfect prompts up front

Rejected because: Doc Wrangler assumes users discover requirements while inspecting data and therefore need assisted specification.

“People cannot specify the whole thing themselves. They need tools to assist in that specification.”transcript, stated

Patterns

query-rewriting (optimization)

DocETL rewrites semantic operator pipelines using rewrite directives for decomposition, fusion, cascades, and operator substitution.

“rewrite directives are these kinds of templates that describe how to rewrite subsequences of operators.”transcript, stated
“we came up with rewrite directives to improve accuracy and cost.”transcript, stated

tool-use-orchestration (agent-architecture)

LLM agents are used as tooling inside the optimizer to instantiate prompts, schemas, and rewrite choices for new semantic operators.

“We use LLM agents to then instantiate the rewrite. So it figures out given our directive registry of 30 plus rewrite directives”transcript, stated

cost-aware-routing (optimization)

Task cascades route inputs through cheaper proxy tasks first and only escalate uncertain cases to the original expensive plan.

“route most of my queries through the proxy only like I can bypass going through the Oracle model”transcript, stated

llm-as-judge (evaluation)

Doc Wrangler runs an expensive LLM judge on samples to identify inaccurate attributes and suggest decomposition.

“every time the user actually runs an operation, we run an expensive LLM judge in the back and to run on a sample”transcript, stated

Tradeoffs

Use task cascades before the Oracle plan.

Chose cheap proxy tasks followed by escalation to the original plan over running the expensive original plan for every document.

Rationale: Task cascades reduce cost when proxy confidence can preserve target accuracy.

“if that cheap model is very confident in its prediction or its output, then I can just accept it.”transcript, stated
“if it's not, well then I can route it to the original plan or the Oracle plan and then accept that prediction.”transcript, stated

Spend money on rewrite exploration.

Chose instantiate and evaluate candidate rewrite directives over avoid exploration cost and keep the initial pipeline.

Rationale: Some rewrites can guarantee accuracy probabilistically while reducing full-run cost enough to justify exploration.

“because we can guarantee the accuracy probabilistically it's okay we don't it's okay to spend money instantiating this directive”transcript, stated

Use an interactive UI as part of the system.

Chose Doc Wrangler output inspection, feedback, and assisted prompt updates over pure backend optimization without user steering.

Rationale: Users discover missing requirements by inspecting data, so steering tools are part of production quality.

“How would they have known this? Right? They didn't know this at the time that they were writing the operation.”transcript, stated

Gotchas (what bit them)

Semantic operators can become too expensive at corpus scale.

Root cause: Naively running state-of-the-art models over tens of thousands of long transcripts is costly.

Resolution: Search rewritten plans, use task cascades, and route confident cases through cheaper proxy tasks.

“if you're going to run this with state-of-the-art models, it can cost you lots and lots of money”transcript, stated

Traditional optimizer assumptions break for LLM pipelines.

Root cause: Semantic plans vary not only by cost but by output accuracy and quality.

Resolution: Estimate cost, accuracy, and latency for candidate semantic plans instead of optimizing cost alone.

“cost is not just latency anymore right you these semantic operator plans can vary in accuracy a lot”transcript, stated

Prompts that work on small samples can break at full corpus scale.

Root cause: Users may overpack multiple attributes into one LLM call or miss edge cases in the data.

Resolution: Use Doc Wrangler feedback, LLM judging, and decomposition suggestions to split complex operations.

“Maybe if you try to generalize that to your entire document corpus, LLM simply make mistakes. They're imperfect and so it breaks at scale.”transcript, stated
“we'll suggest hey maybe you should decompose this operation and propose a decomposition law rewrite directives.”transcript, stated

Evaluation

DocETL evaluates candidate plans by sampling for cost and accuracy, comparing against baselines such as Lotus, Palyst/Abacus, and a GPT agent baseline, and using LLM judges in Doc Wrangler to detect inaccurate operation outputs.

Metrics: cost · accuracy · latency · target accuracy · Pareto frontier · sample pass rates

3 supporting quotes
“evaluating on samples when needed to get estimates of cost and accuracy.”transcript, stated
“we take some real workloads how well how accurate of plans are we able to find and how cheap of plans are we able to find?”transcript, stated
“we found that every time we produce the most accurate query plan, which is very exciting.”transcript, stated

Outcomes

The motivating workloads include tens of thousands of long transcripts and real document-processing users such as public defenders and medical analysts.

3 supporting quotes
“we're able to reduce cost compared to the pipeline before rewriting to 86% on average, which is awesome. Staying within a 90% target accuracy.”transcript, stated
“often it can be 2x times the accuracy of what the other systems can find.”transcript, stated
“But the point is here is assisted specification, right? People cannot specify the whole thing themselves.”transcript, stated