arXiv:2610.28551cs.DBOct 2026

Manuscript Offprint

arXiv:2610.28551

NousDB - A Fast Query Engine for Semantic Analytics

Christos Tsapelas, Georgia Koutrika, Yannis Ioannidis

Christos Tsapelas

Department of Informatics and

Telecommunications, National and

Kapodistrian University of Athens

Archimedes, Athena Research Center

Athens, Greece

ctsapelas@athenarc.gr

ctsapelas@di.uoa.gr

Georgia Koutrika

Archimedes, Athena Research Center

Athens, Greece

georgia@athenarc.gr

Yannis Ioannidis

Department of Informatics and

Telecommunications, National and

Kapodistrian University of Athens

Archimedes, Athena Research Center

Athens, Greece

yannis@athenarc.gr

yannis@di.uoa.gr

Abstract

Semantic data analytics systems integrate AI-powered operators into query pipelines, enabling declarative queries over structured and unstructured data. However, existing systems rely on per-tuple model invocations, ad hoc operator designs, and lack principled cost models, resulting in poor scalability and limited optimization. We present NousDB, a high-performance semantic analytics engine built on Apache DataFusion[22]. Through NousDB we propose an extended relational algebra with three semantic operators and formal algebraic properties that enable principled query rewriting and cross-operator optimization. We further propose a token-based cost model using equi-depth token histograms to optimize batch sizing under context-window constraints and provide statistical guarantees for safe batching. Experiments show that NousDB achieves up to ×86 speedups with both local and enterprise LLMs, while leading competitors in token efficiency and accuracy. These gains extend to complex JOB and Stack workloads augmented with semantic operators, supporting both traditional and semantic analytics.

1 Introduction

Foundation models [2, 33, 45] have showcased strong capabilities in processing unstructured data, such as language and images. This new form of data processing has given rise to semantic query engines (SQEs), which treat models as query operators and allow users to filter, join, extract information from, and summarize textual content in combination with conventional relational operations. However, they challenge several fundamental assumptions underlying database systems, including operator semantics, cost estimation, and parallel execution, among others.

Motivating example. Consider the query “which actors are mentioned in movie reviews?” over the IMDB schema extended with a relation of reviews. Figure 1 shows this query, denoted Q11 in our evaluation, expressed in NousDB. Its natural execution plan first extends each review with the actors mentioned in its text, join the result with the name relation on whether the extracted mention and a person’s name refer to the same actor, and projects the review, movie title and actor name. A naive execution invokes the model once per review for extraction and once per review-name pair for matching, with each invocation processing only one tuple or tuple pair. Avoiding this costly tuple-at-a-time execution requires the planner to reason about semantic operators, for which existing SQEs provide insufficient foundations. Using this query as a running example, we next identify the following problems.

// Q11: which actors are mentioned in movie reviews? let reviews = ctx.nousdb_sql("SELECT * FROM reviews") .extend("mentioned_actor",Utf8), model, "Extract the actor name mentioned in this review", &["review"); let names = ctx.nousdb_sql("SELECT * FROM name"); let result = reviews semantic_join(names, &["mentioned_actor"], &["name"], model, "Does the extracted actor match this person?") .select_columns(&["review", "title", "name"]); result.show().await;

Figure 1: NousDB example program.

Problem 1: Semantic operators without semantics. Existing SQEs expose semantic operators to the query planner as opaque model invocations that use task-specific prompts [11, 29, 36]. This limitation hinders query optimization in SQEs because it prevents the definition of algebraic properties to reason about result-preserving rewrites. In our example, treating semantic operators as black boxes prevents the planner from determining whether it can safely push a selective filter on name below the semantic join, fuse mention extraction and matching into a single model invocation, or partition the work across threads. Missing such rewrites can incur substantial model work, often linear in the input cardinality and far costlier per invocation than conventional tuple comparisons.

Challenge 1: Defining semantics that enable sound plan transformations. A semantic operator is jointly determined by its model and prompt, may behave stochastically, and may be undefined for some inputs. Classical relational-algebra properties therefore cannot be assumed. The challenge is to define semantics that make these behaviors explicit and identify which properties, and thus which plan transformations, are valid under which assumptions.

Problem 2: Finite context windows. Singleton calls underutilize the context window. In our running example, invoking the model separately for every review and review-name pair repeatedly pays the fixed cost of the prompt while leaving most of the context window unused. Batching multiple tuples into each invocation amortizes this cost and reduces the number of model calls, but risks exceeding the model's capacity. Thus, batching must respect a hard token budget determined by the prompt and the model's context window, and becomes a critical optimization decision.

Challenge 2: Token-distribution estimation. Enforcing this budget requires estimating the token footprint of the input tuples without tokenizing the entire input in advance. The engine therefore needs compact per-column token statistics that can be collected and maintained at negligible time and space overhead.

Challenge 3: Probabilistic batch sizing. Given these statistics and the available token budget, the engine must select the largest batch that fits with high probability. The sizing algorithm must balance invocation efficiency against the risk of truncation or rejection, particularly under skewed token-length distributions.

Problem 3: Over-batching can degrade result quality. Although a batch may fit within the model's context window, batching can change the output produced for each tuple relative to singleton execution due to leakage from neighboring tuples, tuple position in the batch, or formatting errors that misalign inputs and outputs. In our experiments, batching without checking output fidelity reduces F1 by up to 0.42 for a selection query with Qwen3-8B. The engine must therefore determine the largest batch size that preserves fidelity, meaning agreement with singleton execution, rather than merely the largest batch that fits within the context window.

Challenge 4: Safe batch sizes cannot be predicted a priori. The batch size at which output quality degrades depends on the model, prompt, and data. At query time, fidelity must be assessed without ground truth or independence assumptions and at a cost substantially lower than the execution being validated.

Problem 3: Token-skew in row-balanced partitions. Classical engines distribute rows evenly across workers, assuming similar per-row costs. In SQEs, cost depends on token volume, so row-balanced partitions may have highly unequal loads. In our example, a partition containing longer reviews carries several times the token load of its peers, becoming a straggler while other workers sit idle. We call this imbalance token skew. Existing SQEs inherit row-based partitioning from their host engines and do not account for it.

Challenge 5: Token-aware partitioning. The challenge is to detect token skew and partition tuples by expected processing cost rather than count, while keeping repartitioning overhead below the gains from improved load balance.

NousDB Contributions. NousDB addresses all four problems. It defines semantic operators declaratively as relation-to-relation functions parameterized by a model and a prompt. These definitions provide engine-independent reference semantics for evaluating implementations and reasoning about plan equivalence. We define these semantics at the tuple level, separating what an operator computes from how its inputs are grouped into model invocations. Singleton execution, in which each tuple is evaluated independently, serves as the reference semantics. Batching is therefore a physical execution choice whose fidelity can be evaluated against this reference, rather than an implicit change to the operator's meaning. NousDB is built as an extension of Apache DataFusion [22] over Apache Arrow's [3] columnar format (Figure 2). Its semantic operators are first-class DataFusion operators, enabling vectorized, columnar, and partition-parallel execution. In a nutshell, NousDB makes the following contributions:

• An algebra for semantic operators. We define three tuple-level semantic operators (Extend, Selection, Join) under an explicit oracle assumption, which allows us to derive a set of algebraic properties, along with four rewrite rules, two push-downs and two fusions, that NousDB's optimizer applies.

• Token-aware batch sizing. We introduce equi-depth token histograms as the catalog statistic of token-priced operators, an iterative algorithm that maximizes k subject to an overflow probability α\alpha, and batched streaming operators that keep a window of packed requests in flight.

• A fidelity certificate. We define batch fidelity as the probability that a tuple has the same output in a batch as in a singleton

Figure

Figure 2: NousDB system architecture.

invocation and certify it at query time with a one-probe-per-batch calibration that restores independent samples and an exact Clopper–Pearson test. In query execution, certified runs agree with singleton execution on at least 86% of the tuples of every query.

• Token-aware repartitioning. We implement a token repartition operator with list-scheduling and zigzag assignment, a corrected balance guarantee, and a wave-barrier protocol that embeds it in DataFusion execution engine.

• Strong performance. On IMDB and SemBench, against LOTUS, Palimpzest, Abacus and per-row DataFusion, with a local (Qwen3-8B) and a hosted (GPT-5.4-nano) model, NousDB is the fastest system, up to 86×, uses up to 19× fewer tokens, and lies on the quality–runtime Pareto frontier. On JOB and STACK augmented with semantic operators (43 queries, up to 17 relations) it keeps its lead, up to 35×.

References (30)