Skip to main content
Back

Google Cloud Replaces LLM Queries With Logistic Regression for 792x Cost Savings

Google researchers show that swapping LLM calls for tiny classifiers over embeddings can cut SQL semantic operator cost and latency by more than 100x.

Pro

Paper, Full Access
  • Google's SIGMOD 2026 paper replaces LLM calls in SQL AI queries with logistic regression over embeddings.
  • Delivers up to 991x latency and 792x cost cuts on 10M-row semantic filter workloads.
  • Proxy matches or beats the LLM on 13 classification benchmarks including FEVER, IMDB, and Amazon Polarity.
  • Ships in two flavors: online training in BigQuery, offline in AlloyDB.
  • Falls back to the LLM automatically when proxy accuracy drops below a set threshold.
  • Struggles on needle-in-haystack retrieval and hard reasoning tasks like HellaSwag.

Running an LLM inside a SQL WHERE clause is intoxicating in a demo and terrifying on a bill. A new paper from Google Cloud, accepted to SIGMOD 2026, argues that most of those LLM calls never needed to happen in the first place. By training a boring logistic regression on top of text embeddings, the team gets up to 991x latency and 792x cost reductions on semantic filter queries over a 10 million row table, while matching or beating the LLM on accuracy.

The work is a production study inside Google BigQuery and AlloyDB AI, evaluating what happens when you take the AI query features that BigQuery, Snowflake, and Databricks have shipped, and quietly replace the LLM with a proxy model whenever it is safe to do so.

The problem with AI queries at warehouse scale

Cloud warehouses now let you write things like WHERE AI.IF("The review is positive:", review) and let a model decide row by row. In large-scale OLAP databases, the computational cost makes LLM-based semantic processing economically unfeasible on millions of rows, and in HTAP databases, the latency from those calls severely restricts practical applications. Prior optimization work like LOTUS, ThalamusDB, DocETL, and Abacus mostly tries to reduce the number of LLM calls through row skipping, operator reordering, or cascading to smaller models.

The Google authors argue that this still leaves orders of magnitude on the table. Their approach introduces a lightweight proxy that directly replaces LLM invocations, and only falls back to the LLM when the proxy's approximation drops below a predetermined threshold. Nothing is sampled and extrapolated; the entire table is processed by the cheap model.

How the proxy model works

The recipe is deliberately dull, which is the point. For every incoming AI.IF or AI.RANK operator, the engine automatically:

  1. Parses the operator into its type, prompt, and input column.
  2. Generates embeddings for the unstructured column using Gecko (text-embedding-005).
  3. Draws a small sample of rows and labels them with Gemini 2.5 Flash.
  4. Fits an off-the-shelf logistic regression on those embeddings.
  5. Measures the proxy's accuracy against the LLM labels. If it is within a threshold (about 10 percent absolute), the proxy scores the whole table. Otherwise the system falls back to the LLM.

The system uses a single set of default sklearn parameters for logistic regression, except with class_weight set to balanced, and explicitly avoids the need for specialized ML expertise or hyperparameter tuning. An ablation shows why: tuning yielded negligible or even slightly negative changes to the F1 score, with logistic regression holding at 0.867 after tuning. SVM would have cost roughly 50x more training time for no quality gain.

Two flavors ship. BigQuery does online training, where the proxy is built inside the query and the high cost of that training is amortized across processing millions or billions of rows. AlloyDB does offline training for known query patterns so latency-critical HTAP workloads never pay the sampling and labeling tax at query time.

Numbers that raise eyebrows

On a 10 million row table running the Amazon Polarity positive-review filter, the OLAP proxy hits 329x latency improvement and 728x cost savings; the offline HTAP version reaches 991x latency and 792x cost. Savings compound with size: latency gains scale superlinearly as larger tables give BigQuery more opportunity to parallelize execution, and since the number of samples to label is independent of the input table size, cost reduction also scales superlinearly with input rows.

Stacked bar chart showing sampling, labeling, training, and prediction time shares across 10K to 10M row datasets

Quality holds up across a wide sweep. On thirteen classification benchmarks including IMDB, Amazon Polarity, BBC News, Banking77, Toxic Conversations, and FEVER, the macro F1 ratio between proxy and LLM sits close to 1.0. On Amazon Reviews 10k the proxy actually beats the LLM (0.860 vs 0.739 macro F1), and on the SPAM email dataset it hits 99 percent accuracy versus the LLM's 96 percent. The authors attribute this to the simple, low-complexity logistic regression decision function acting as a regularizer on top of embeddings.

Where it breaks

The approach is no universal LLM killer. Two failure modes are documented in detail:

  • Needle-in-a-haystack retrieval. On IR benchmarks like SciFact, SCIDOCS, and FIQA-2018, there are only 1 to 5 relevant documents per query out of tens of thousands. A random or top-K sample simply cannot find enough positive examples, and the proxy collapses. The adaptive selector correctly falls back to the LLM here.
  • Hard reasoning tasks. On HellaSwag, which needs commonsense reasoning to pick the right ending, proxy nDCG@10 lands at only 54 percent of the LLM's score. When the LLM's own labels are noisy, the proxy inherits the noise.

Embedding quality matters more than model complexity. Gecko (text-embedding-005) at 768 dimensions provides consistently high-quality embeddings and can outperform the more expensive 3072-dimensional Gemini embedding on the Tweet Sentiment benchmark, while the open-source Gemma embeddinggemma-300m consistently exhibits the lowest performance. Cost savings at the embedding layer can translate into an unacceptable loss of accuracy downstream.

Line graph comparing Gecko, Gemini, and Gemma embedding macro F1 across dimensions on three classification datasets

Kicking the LLM out of the hot path

The bigger idea here runs orthogonal to what LOTUS, DocETL, and Palimpzest have been doing. Plan optimization tries to make LLM calls cheaper or rarer. This work argues that for the common case of semantic filter and rank, the LLM should not be in the hot path at all, and its role is to be a labeler and a fallback. The proxy models are light enough to deliver high performance on commodity hardware without expensive accelerators, running on plain 8 vCPU instances with no GPUs.

The authors also test whether a proxy trained on the full table generalizes to sliced queries (filter by age group, then apply semantic predicate). Surprisingly, the general proxy usually beats a slice-specific one, because tiny slices do not have enough labels to train reliably. That makes the approach practical for interactive BI dashboards where users constantly slice and dice.

No public code release accompanies the paper, but both BigQuery ML AI functions and AlloyDB AI are the productionization targets, and the techniques are simple enough to reimplement: any team already storing embeddings and running Postgres or a warehouse can replicate the pipeline with sklearn and a few hundred labeled samples. Semantic joins and multi-class AI.CLASSIFY are flagged as the next frontiers, both bottlenecked by the same sampling problem that trips up retrieval today.