Ilmu Komputer & AI editorial
Open AccessOA2026
Larch: Learned Query Optimization for Semantic Predicates
A framework for optimizing semantic filter execution in AI SQL queries, reducing token costs by 3x–19x
Fuheng Zhao; Pawel Liskowski; Zihan Li; Benjamin Han; Puxuan Yu; Varich Boonsanong; Dimitris Tsirogiannis; Anupam Datta· 2026· DOI 10.48550/arXiv.2606.07923
The core problem
The integration of Large Language Models (LLMs) into database systems has enabled semantic operators that allow analytical queries over unstructured data such as text, images, and videos. However, these semantic operators incur high inference costs and latencies, making AI SQL queries challenging to apply on large-scale datasets. Their semantic nature leads database engines to treat them as black boxes, hindering optimization. This paper introduces Larch, a framework for optimizing the execution of semantic filters in AI SQL queries. Larch is inspired by two key observations: (i) the high latency of semantic operators leaves significant room for computationally-heavy runtime optimization techniques, and (ii) unstructured data are typically accompanied by semantic information in the form of embeddings, allowing for efficient semantic comparisons between AI_FILTER prompts and data values. Based on these observations, the authors present two Larch variants: Larch-A2C and Larch-Sel.
Innovation
The authors evaluated Larch across diverse real-world datasets and comprehensive synthetic workloads. Both Larch variants consistently outperformed existing semantic filter optimization techniques in terms of token usage. Specifically, Larch reduced total token cost overhead by 3x to 19x compared to Palimpzest and Quest. The results demonstrate that Larch is robust across diverse workloads, effectively optimizing semantic filter execution. The experiments included various filter types, data modalities, and query complexities, showing that Larch adapts to different scenarios. The token cost reduction is attributed to the learned evaluation order that prioritizes filters with high selectivity and low cost, minimizing expensive LLM calls.
The integration of Large Language Models (LLMs) into database systems has enabled semantic operators that allow analytical queries over unstructured data such as text, images, and videos. However, these semantic operators incur high inference costs and latencies, making AI SQL queries challenging to apply on large-scale datasets. Their semantic nature leads database engines to treat them as black boxes, hindering optimization. This paper introduces Larch, a framework for optimizing the execution of semantic filters in AI SQL queries. Larch is inspired by two key observations: (i) the high latency of semantic operators leaves significant room for computationally-heavy runtime optimization techniques, and (ii) unstructured data are typically accompanied by semantic information in the form of embeddings, allowing for efficient semantic comparisons between AI_FILTER prompts and data values. Based on these observations, the authors present two Larch variants: Larch-A2C and Larch-Sel.
Larch-A2C encodes arbitrary semantic filter expression trees using an embedding-augmented Gated Graph Neural Network (GGNN) and formulates the filter evaluation order as a Markov decision process (MDP). The GGNN processes the expression tree, where each node is augmented with embeddings of the prompt and data values. The MDP state represents the current evaluation status, and actions correspond to selecting the next filter to evaluate. A reinforcement learning agent is trained to minimize the expected token cost.
Why it matters
The key insight behind Larch is that semantic filters are not black boxes; their selectivities can be predicted using embeddings and learned models. By reordering filter evaluations, Larch significantly reduces the number of LLM invocations, leading to substantial cost savings. Larch-A2C and Larch-Sel offer complementary approaches: Larch-A2C uses reinforcement learning to handle complex expression trees, while Larch-Sel employs supervised learning and dynamic programming for simpler, row-wise optimization. The framework's robustness across workloads suggests it can be integrated into various database systems. However, the paper does not address potential overhead of model inference for selectivity prediction, which could be a trade-off. Future work could explore adaptive switching between variants based on workload characteristics. Overall, Larch represents a significant step towards making AI SQL queries practical at scale.
Who should read this
CS practitioners and researchers
Opening member content…