AI News

BigQuery’s AI.AGG() Lets You Summarize Millions of Rows in SQL

Quick answer

BigQuery's new AI.AGG() function lets you summarize millions of rows of unstructured data with one line of SQL. Analyze logs, images, and more using natural language.

Google Cloud just dropped a new BigQuery function that feels like cheating: AI.AGG(). It lets you summarize or synthesize millions of rows of unstructured or multimodal data using a single line of SQL with natural-language instructions. No more drowning in logs or product descriptions—just ask and ye shall receive.

Think of it as a capybara that wades through the swamp of your data, filtering out the muck and surfacing the juicy bits. While BigQuery already had AI functions for row-level analysis, AI.AGG() is built for the big picture. It’s in preview now, so you can start playing with it today.

What Can You Do With AI.AGG()?

The function shines on unstructured data like logs, product descriptions, and even images. Here are a few examples from the announcement:

  • Analyze system logs: Spot hidden inefficiencies like memory thrashing or clock drift without manually sifting through thousands of INFO messages.
  • Extract product categories: Feed it product names and descriptions, and it returns a list of categories—or even a structured JSON array for downstream pipelines.
  • Summarize images: Point it at a bucket of product photos, and it tells you what categories they fall into.

For a deeper dive into how BigQuery compares to other data platforms, check out our Google Cloud Review and Supabase Review.

How It Works Under the Hood

AI.AGG() automatically batches your input rows to stay within the LLM’s context window, then aggregates those batches into a final answer. It handles NULLs gracefully (skips them), but watch out: if you pass a STRUCT with a NULL field, the whole row gets skipped. Use IFNULL() to provide fallbacks.

You can specify the model endpoint—defaults to a recent Gemini model, but you can pin to gemini-2.5-flash or a fully-qualified name. Output is always a string, but you can prompt for JSON or Markdown.

Best Practices

  • Filter first: Use LIMIT or pre-filter to reduce token usage and cost.
  • Handle NULLs: Use IFNULL() to avoid silent row drops.
  • Structured output: Ask for JSON arrays to feed into AI.CLASSIFY() for automated labeling.

For more on AI-powered data tools, see our Model Pricing Comparison and Neon Database Review.

Give It a Try

AI.AGG() is available in preview to all BigQuery users. Head over to the official docs to get started. And if you’re building data pipelines, don’t miss our Windmill Review for a different take on automation.

Original announcement published on Google Cloud.