Building an Ultra-High Throughput AI-SQL Engine Researchers are building AI-SQL query engines that push LLM inference into the database, but executing AI functions remains extremely expensive because a single query can trigger hundreds of thousands or millions of model calls, with a filter requiring one LLM call per row and a naive join requiring one call for every pair of rows. The work, spanning UC Berkeley's DocETL, Stanford's LOTUS, MIT's Palimpzest, and Cornell's ThalamusDB, primarily cuts cost by eliminating LLM calls and using cheaper models, and the team is building the QUAIL-B benchmark to evaluate these engines, using a BIO-4 query over 5,000 long medical reports and 4,144 reaction terms. The authors argue query plans themselves should control LLM inference rather than sending millions of related calls to a general-purpose engine such as vLLM as separate requests. Back to blog https://fsdatalab.github.io/blog/ Building an Ultra-High Throughput AI-SQL Engine 1. AI-SQL makes unstructured data useful, but it is expensive. Fast LLM classifiers have been taking over the internet lately. Jev https://typesafe.ai/blog/introducing-system-one-models-and-jev is the clearest example: give a model a small, bounded decision and get an answer almost immediately. What better place to run millions of those decisions than… inside the database Indeed, database vendors have recently begun to offer this kind of intelligence at scale through AI-SQL, also called AI functions. AI-SQL extends SQL with user-defined functions that invoke LLMs. Users specify each function with a natural-language prompt. A query can look like this: SELECT FROM reviews AS r WHERE AI.IF PROMPT 'Does this review discuss the ending?\n\n{0}', r.review ; Many database vendors support AI-SQL. For example, Snowflake Cortex AISQL https://docs.snowflake.com/en/user-guide/snowflake-cortex/aisql , BigQuery AI functions https://cloud.google.com/bigquery/docs/generative-ai-overview , Databricks AI Functions https://docs.databricks.com/aws/en/large-language-models/ai-functions , and, recently, MotherDuck https://motherduck.com/blog/motherduck-supports-jev/ all support it. Unfortunately, executing AI-SQL is extremely expensive. An AI function evaluates its prompt row by row, so one SQL query can create hundreds of thousands or millions of model calls. A filter needs one LLM call per row. A naive join needs one LLM call for every pair of rows in its two input tables. This line of work has become extremely popular in the database research community. A number of open-source academic systems have emerged, including our work on DocETL https://docetl.org/ from UC Berkeley, LOTUS https://lotus-data.github.io/ from Stanford, Palimpzest https://palimpzest.org/ from MIT, and ThalamusDB https://github.com/itrummer/thalamusdb from Cornell. These systems and database vendors primarily reduce cost by eliminating as many LLM calls as possible e.g., MOAR https://arxiv.org/abs/2512.02289 , Task Cascades https://arxiv.org/abs/2601.05536 , and Abacus https://arxiv.org/abs/2505.14661 and by using cheaper models when possible e.g., BARGAIN https://arxiv.org/abs/2509.02896 . Even after these optimizations, a query plan may still require hundreds of thousands or millions of LLM calls. 2. Key Idea: Query plans should control LLM inference A natural thought is to use a general-purpose inference engine such as vLLM to execute the query plan. However, sending millions of related model calls to vLLM as separate requests has a large cost We’ll illustrate with the following query: Given a dataset of medical reports and a dataset of possible adverse reactions, find serious adverse event reports that mention both a cardiovascular reaction and a neurological reaction. 1 note-1 We call this query BIO-4 in QUAIL-B https://github.com/fsdatalab/quail-bench , a benchmark we are building to evaluate AI-SQL query engines. Its inputs contain 5,000 long reports and 4,144 reaction terms the latter is used twice, as there are two joins . The logical plan, shown in Figure 1 figure-1 , works as follows: 1. It filters the reports for serious adverse events. 2. It filters the two reaction term dataset inputs i.e., lists of possible adverse reaction terms for cardiovascular and neurological reactions. 3. It joins the surviving reports with the cardiovascular terms, then with the neurological terms. How might we execute BIO-4 with vLLM? Following what databases do, we’d render one prompt for each filter input, and, for the join, one prompt for candidate report and reaction pair . Each prompt would be a separate inference request.