All skills
google avatar

/bigquery-ai-ml

@d6b9f75
by googlegoogle/skills21k stars
1,698

Leverages BigQuery's built-in machine learning and GenAI capabilities for advanced data analytics. Use when you need to write SQL queries that perform time-series forecasting, predict values, detect outliers or anomalies, find key drivers, perform semantic search or vector search, classify text, calculate similarity, summarize content, translate language, evaluate models, filter by semantic conditions, measure the causal effect of an intervention, compute correlations between columns, detect change points or structural breaks, extract trend or seasonality components, or leverage generative AI capabilities in BigQuery. Do not use for general BigQuery dataset, table, or job management requests.

Use this Skill: https://skilld.dev/gh/google/skills/bigquery-ai-ml

This session only. Nothing lands on disk.

referencesai_detect_anomalies.md

≈955 tokens on demand. Your agent reads this file only when SKILL.md points to it.

BigQuery AI.Detect_Anomalies

AI.DETECT_ANOMALIES uses the pre-trained TimesFM model to identify deviations in time series data without needing to train a custom model.

Syntax Reference

This function compares a target dataset against a historical dataset to identify anomalies.

SELECT *
FROM AI.DETECT_ANOMALIES(
  { TABLE `project.dataset.history_table` | (SELECT * FROM history_query) },
  { TABLE `project.dataset.target_table` | (SELECT * FROM target_query) },
  data_col => 'DATA_COL',
  timestamp_col => 'TIMESTAMP_COL'
  [, model => 'MODEL']
  [, id_cols => ID_COLS]
  [, anomaly_prob_threshold => ANOMALY_PROB_THRESHOLD]
)

Input Arguments

Argument Requirement Type Description
historical_data Required Table/Query The source table or subquery containing historical data for training context.
target_data Required Table/Query The source table or subquery containing data to analyze for anomalies.
data_col Required String The numeric column to analyze.
timestamp_col Required String The column containing dates/timestamps.
id_cols Optional Array<String> Grouping columns for multiple series (e.g., ['store_id']).
anomaly_prob_threshold Optional Float64 Threshold for anomaly detection (0 to 1). Defaults to 0.95.
model Optional String Model version. Defaults to 'TimesFM 2.0'.

Output Schema

Column Type Description
id_cols (As Input) Original identifiers for the series.
time_series_timestamp TIMESTAMP Timestamp for the analyzed points.
time_series_data FLOAT64 The original data value.
is_anomaly BOOL TRUE if the point is identified as an anomaly.
lower_bound FLOAT64 Lower bound of the expected range.
upper_bound FLOAT64 Upper bound of the expected range.
anomaly_probability FLOAT64 Probability that the point is an anomaly.
ai_detect_anomalies_status STRING Error messages or empty string on success. A minimum of 3 data points is required.

Examples

Basic Anomaly Detection

Detect anomalies in daily bike trips for a specific 2-month window based on prior history.

WITH bike_trips AS (
  SELECT EXTRACT(DATE FROM starttime) AS date, COUNT(*) AS num_trips
  FROM `bigquery-public-data.new_york.citibike_trips`
  GROUP BY date
)
SELECT *
FROM AI.DETECT_ANOMALIES(
  -- Historical context (Training data equivalent)
  (SELECT * FROM bike_trips WHERE date <= DATE('2016-06-30')),
  -- Target range (Data to inspect for anomalies)
  (SELECT * FROM bike_trips WHERE date BETWEEN '2016-07-01' AND '2016-09-01'),
  data_col => 'num_trips',
  timestamp_col => 'date'
);

Multivariate Detection (Multiple Series)

Use id_cols to detect anomalies separately for different user types (e.g., Subscriber vs. Customer) in the same query.

WITH bike_trips AS (
    SELECT
      EXTRACT(DATE FROM starttime) AS date, usertype, gender,
      COUNT(*) AS num_trips
    FROM `bigquery-public-data.new_york.citibike_trips`
    GROUP BY date, usertype, gender
  )
SELECT *
FROM
  AI.DETECT_ANOMALIES(
    # Historical data from a query
    (SELECT * FROM bike_trips WHERE date <= DATE('2016-06-30')),
    # Target data from a query
    (SELECT * FROM bike_trips WHERE date BETWEEN '2016-07-01' AND '2016-09-01'),
    data_col => 'num_trips',
    timestamp_col => 'date',
    id_cols => ['usertype', 'gender'],
    model => "TimesFM 2.5",
    anomaly_prob_threshold => 0.8);

Source: SKILL.md on GitHub

No alerts9d3 checks · Risk SAFE
  • Gen Agent Trust Hub9d

    This skill provides a comprehensive reference for BigQuery's built-in AI and machine learning functions. It includes a security consideration regarding potential indirect prompt injection when processing untrusted data with generative AI functions. These patterns are standard for the intended data analysis use cases and can be managed through proper prompt design and data validation.

  • Socket9d

    No alerts

  • Snyk9d

    Risk: LOW · No issues

Signed by skilld at d6b9f75. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last week
metadata
{
  "version": "1.1.0",
  "category": "AiAndMachineLearning"
}

README badge

README badge for google/skills/bigquery-ai-ml