bigquery-ai-ml

Write BigQuery SQL queries using built-in AI and ML functions for forecasting, anomaly detection, and generative analysis.

Updated Jul 7, 2026
One-click install
npx skills add https://github.com/ricardolui/gcp-custom-agent-skills --skill bigquery-ai-ml-ricardolui
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bigquery-ai-ml
Source: https://github.com/ricardolui/gcp-custom-agent-skills/tree/main/bigquery-ai-ml
Command: npx skills add https://github.com/ricardolui/gcp-custom-agent-skills --skill bigquery-ai-ml-ricardolui

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Analysts often need machine learning and generative AI capabilities like forecasting, anomaly detection, and text generation but lack the infrastructure to train and deploy models. This Skill provides the syntax, constraints, and best practices to perform these tasks directly in BigQuery SQL using built-in AI functions. ## Core Features & Use Cases - Time-Series Analysis: Generate forecasts with AI.FORECAST, detect outliers with AI.DETECT_ANOMALIES, and evaluate model accuracy with AI.EVALUATE using the pre-trained TimesFM model. - Generative AI in SQL: Generate text with AI.GENERATE, classify content with AI.CLASSIFY, aggregate insights with AI.AGG, and extract structured data with AI.GENERATE_TABLE using Gemini endpoints. - Semantic Search & Key Drivers: Perform vector search with VECTOR_SEARCH and AI.SEARCH, compute similarity with AI.SIMILARITY, and identify metric drivers with AI.KEY_DRIVERS or contribution analysis models. - Use Case: A data analyst wants to forecast next month's bike trips per user type and detect anomalies in recent data. This Skill guides writing AI.FORECAST and AI.DETECT_ANOMALIES queries with correct TVF placement, named arguments, and chronological data splitting. ## Quick Start Ask the AI to write a BigQuery SQL query that forecasts the next 30 days of daily sales from your sales table using AI.FORECAST.

Frequently Asked Questions about bigquery-ai-ml

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I forecast time series data in BigQuery?

Use AI.FORECAST, a table-valued function that leverages the pre-trained TimesFM model without training a custom model. Place it in the FROM clause with data_col and timestamp_col as named arguments, and optionally set horizon, id_cols, and confidence_level.

How do I detect anomalies in BigQuery time series data?

Use AI.DETECT_ANOMALIES with a historical dataset and a target dataset to identify deviations. It requires data_col and timestamp_col arguments, supports grouping via id_cols, and needs a minimum of 3 data points per series.

What is the difference between AI.GENERATE and AI.GENERATE_TABLE in BigQuery?

AI.GENERATE is a scalar function returning a STRUCT with generated text, while AI.GENERATE_TABLE is a table-valued function called in the FROM clause that extracts information into a predefined output schema. AI.GENERATE_TABLE requires a remote model and an input column aliased as prompt.

Does BigQuery AI.FORECAST require training a custom model?

No, AI.FORECAST uses the pre-trained TimesFM foundation model, so no custom model training is needed. You only provide historical data, the numeric column to predict, and the timestamp column.

Why does my BigQuery AI function query fail with a syntax error?

Common causes include placing table-valued functions like AI.FORECAST or AI.GENERATE_TABLE outside the FROM clause, omitting the => operator for named arguments, or missing the prompt column alias in AI.GENERATE_TABLE input subqueries.

When should I use AI.KEY_DRIVERS versus a contribution analysis model?

Use AI.KEY_DRIVERS for quick key driver analysis directly as a table-valued function without creating a model. Use a CONTRIBUTION_ANALYSIS model with ML.GET_INSIGHTS when you need a persistent model entity for repeated insight retrieval.