Moving Beyond Row-Level AI Analysis
Traditional AI functions in BigQuery (such as classification or scoring) operate on a row-by-row basis. While effective for individual data points, these functions struggle to provide a high-level "big picture" view of large datasets. The AI.AGG function addresses this by acting as an aggregate function, allowing the model to reason over an entire group of rows simultaneously to produce a single, synthesized output.
How AI.AGG Works
The function requires only two primary inputs to operate:
- The Data: A column (or set of columns) containing the information to be analyzed, such as customer reviews, product descriptions, or image references.
- The Instruction: A natural language prompt that defines the task (e.g., "Summarize the overall sentiment" or "Categorize these products").
Because it functions as an aggregate, it integrates seamlessly with standard SQL GROUP BY clauses. This enables users to generate distinct AI-driven insights for different segments of their data—such as summarizing reviews for every product in a catalog—in a single query execution.
Multimodal Reasoning Capabilities
A key feature of AI.AGG is its ability to process multimodal data. It can ingest both text and image data (using object references) to perform complex reasoning tasks. For example, a user can pass a product name alongside an image to have the model categorize inventory or compare customer-written reviews against uploaded product photos to identify discrepancies. This capability allows for deeper contextual analysis that would otherwise require complex ETL pipelines or external model orchestration.