BigQuery’s AI.AGG, in preview, summarizes grouped rows with Gemini inside SQL
A Google Cloud post dated Thursday describes one aggregate function that batches text or files, calls Gemini, and reduces the answers to a string per GROUP BY. A row over 10 MiB is dropped or errors. Output is capped at 10,000 tokens a group. Google recommends no more than 20 million rows and 1,000 groups in a query.
Short2 minIn-depth
Maya Chen2 min read
- Google Cloud
- BigQuery
- Gemini
- SQL

Photo: Google CloudSource page
Google Cloud on Thursday published a description of AI.AGG, a BigQuery function in preview that takes a natural-language instruction and returns one string per SQL group. The post, by Pramod Niralakeri and Shruti Malgatti and dated 5 November, says the function is for text and multimodal rows that do not fit in a single Gemini prompt: logs, transcripts, images, diagnostic reports. BigQuery already had row-level functions such as AI.GENERATE and AI.CLASSIFY. AI.AGG is the aggregate. The post’s account of the engine is a sequence. It checks that no row exceeds 10 MiB, and drops or errors on a larger payload. It batches the rows that fit the chosen Gemini endpoint, runs the instruction on each batch through Vertex AI, then feeds those intermediate strings back through the same instruction until one string remains for each GROUP BY.
The post says every stage uses a full Gemini model, not the distilled CPU proxies it says AI.CLASSIFY can use, because the function has to synthesize across batches. The token count sent to Gemini is larger than the source, since intermediate summaries are sent again. The post tells readers to filter with WHERE and LIMIT first, and to estimate with AI.COUNT_TOKENS. Gemini context caching is available for large static inputs. A null field inside a struct, it says, makes the whole row null, and the row is discarded unless the query wraps the field. On files, Object Tables and OBJ.GET_ACCESS_URL let the function read objects in Cloud Storage. The documentation says a row can hold at most 10 images, or one audio, video, or PDF file.
The preview limits in the post are concrete. The final string for a group is capped at 10,000 tokens. A multimodal row with more than 10 images can be skipped without an error. For stability, Google recommends at most 20 million rows and 1,000 groups in one query. A transient failure in a batch, the post says, skips the rejected rows rather than failing the query. The function stays inside BigQuery’s controls, including VPC Service Controls. The post is a description of a preview function and the caps around it. It does not announce a new Gemini model, and it does not publish a price for the calls beyond the warning that the recursive pass costs more tokens than the table.


