CREATE MODEL MONITOR

statementpartialAI & ML

docs.snowflake.com ↗

Object: MODEL MONITOR

Create or replace a model monitor in the current or specified schema. Snowflake currently supports two types of model monitors. See ML Observability for model version monitors and Gateway Monitoring & A/B Testing for gateway model monitors.

Syntax

supportedpartialnot supportednot scored

CREATE [ OR REPLACE ] MODEL MONITOR [ IF NOT EXISTS ] <monitor_name> WITH
    MODEL = <model_name>
    VERSION = '<version_name>'
    FUNCTION = '<function_name>'
    WAREHOUSE = <warehouse_name>
    REFRESH_INTERVAL = '<num> { seconds | minutes | hours | days }'
    AGGREGATION_WINDOW = '<num> days'
    [ SOURCE = <source_name> ]
    [ TIMESTAMP_COLUMN = <timestamp_name> ]
    [ BASELINE = <baseline_name> ]
    [ GROUND_TRUTH = <ground_truth_table> ]
    [ ID_COLUMNS = <id_column_name_array> ]
    [ PREDICTION_CLASS_COLUMNS = <prediction_class_column_name_array> ]
    [ PREDICTION_SCORE_COLUMNS = <prediction_column-name_array> ]
    [ ACTUAL_CLASS_COLUMNS = <actual_class_column_name_array> ]
    [ ACTUAL_SCORE_COLUMNS = <actual_column_name_array> ]
    [ SEGMENT_COLUMNS = <segment_column_name_array> ]
    [ CUSTOM_METRIC_COLUMNS = <custom_metric_column_name_array> ]
    [ COMMENT = '<string_literal>' ]
CREATE [ OR REPLACE ] MODEL MONITOR [ IF NOT EXISTS ] <monitor_name> WITH
    MODEL = <model_name>
    GATEWAY = <gateway_name>
    FUNCTION = '<function_name>'
    WAREHOUSE = <warehouse_name>
    REFRESH_INTERVAL = '<num> { seconds | minutes | hours | days }'
    AGGREGATION_WINDOW = '<num> { hours | days }'
    [ GROUND_TRUTH = <ground_truth_table> ]
    [ ID_COLUMNS = <id_column_name_array> ]
    [ PREDICTION_CLASS_COLUMNS = <prediction_class_column_name_array> ]
    [ PREDICTION_SCORE_COLUMNS = <prediction_score_column_name_array> ]
    [ ACTUAL_CLASS_COLUMNS = <actual_class_column_name_array> ]
    [ ACTUAL_SCORE_COLUMNS = <actual_score_column_name_array> ]
    [ COMMENT = '<string_literal>' ]

Parameters

NameRequiredDescription
monitor_namerequiredSpecifies the identifier for the model monitor; must be unique in the schema where the monitor is created. If the monitor identifier is not fully qualified (in the form of db_name.schema_name.name or schema_name.name), the command creates the model in the current schema for the session. In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example, "My object"). Identifiers enclosed in double quotes are also case-sensitive. For more information, see Identifier requirements.
MODEL = model_namerequiredThe name of the model to be monitored.
FUNCTION = 'function_name'requiredThe name of the model function to monitor. For model version monitors, must be a function in the specified model version. For gateway model monitors, must match a function exposed by each active inference service behind the gateway that backs the specified model.
WAREHOUSE = warehouse_namerequiredThe name of the Snowflake warehouse to use for the monitor’s internal compute operations.
REFRESH_INTERVAL = 'num { seconds | minutes | hours | days }'requiredThe interval at which the monitor refreshes its internal state. The value must be a string representing a time period, such as '1 day'. The minimum refresh interval is '60 seconds'. Supported units include seconds, minutes, hours, and days. You may use singular (“hour”) or plural (“hours”) for the interval name.
AGGREGATION_WINDOW = 'num { hours | days }'requiredThe window over which the monitor aggregates data. The value must be a string representing a time period, such as '1 day'. For model version monitors, only days are supported. For gateway model monitors, both hours and days are supported. You may use singular (“day”) or plural (“days”) for the interval name.
VERSION = 'version_name'requiredName of the model version to be monitored.
GATEWAY = gateway_namerequiredName of the Snowflake Gateway whose routed inference services you want to monitor.
GROUND_TRUTH = ground_truth_tableoptionalName of the ground truth table that contains labels for performance metrics. The table must include every column in ID_COLUMNS (type STRING) and exactly one additional column for the actual label or score, unless you specify ACTUAL_CLASS_COLUMNS or ACTUAL_SCORE_COLUMNS explicitly. Not supported for model version monitors that use a user-provided SOURCE.
ID_COLUMNS = id_column_name_arrayoptionalAn array of string column names that, together, uniquely identify each row in the source data. See ARRAY constants. For gateway model monitors and model version monitors that use the auto-captured inference table, specify ID_COLUMNS and GROUND_TRUTH together to enable performance metrics monitoring, or omit both. The column names must match the field names listed in extra_columns in inference requests to join the ground truth table with the auto-captured inference logs.
PREDICTION_CLASS_COLUMNS = prediction_class_column_name_arrayoptionalAn array of strings naming all prediction class columns in the SOURCE table if you provide one, or the output feature names in the auto-captured inference logs when they’re the source. See ARRAY constants. If the model task is TABULAR_BINARY_CLASSIFICATION or TABULAR_REGRESSION, the columns must be of type NUMBER. If the model task is TABULAR_MULTI_CLASSIFICATION, the columns must be of type STRING.
PREDICTION_SCORE_COLUMNS = prediction_column_name_arrayoptionalAn array of strings naming all prediction score columns in the SOURCE table if you provide one, or the output feature names in the auto-captured inference logs when they’re the source. See ARRAY constants. Columns must be of type NUMBER.
ACTUAL_CLASS_COLUMNS = actual_class_column_name_arrayoptionalAn array of strings naming all actual class columns in the SOURCE table if you provide one, or in the GROUND_TRUTH table when the auto-captured inference logs are the source. See ARRAY constants. If the model task is TABULAR_BINARY_CLASSIFICATION or TABULAR_REGRESSION, the columns must be of type NUMBER. If the model task is TABULAR_MULTI_CLASSIFICATION, the columns must be of type STRING.
ACTUAL_SCORE_COLUMNS = actual_column_name_arrayoptionalAn array of strings naming all actual score columns in the SOURCE table if you provide one, or in the GROUND_TRUTH table when the auto-captured inference logs are the source. See ARRAY constants. Columns must be of type NUMBER.
COMMENT = 'string_literal'optionalSpecifies a comment for the model monitor.
SOURCE = source_nameoptionalName of the source table or view that contains the features, inference results, and actual labels. If you omit SOURCE, the monitor reads the model’s auto-captured inference table for the features and inference results, and the optional ground truth table for the actual labels.
TIMESTAMP_COLUMN = timestamp_nameoptionalName of the column in the source data that contains the timestamps. Must be of type TIMESTAMP_NTZ. Required if you specify SOURCE. Don’t specify it when the source is the auto-captured inference table.
BASELINE = baseline_nameoptionalName of the baseline table that contains a snapshot of data similar to SOURCE, which is used to compute drift. A snapshot of this data is embedded within the monitor object. Although this parameter is optional, if it is not set, the monitor cannot detect drift. For a monitor that uses the auto-captured inference table, the baseline table schema must include the prediction columns, the actual columns if you specify GROUND_TRUTH, and the feature columns from the model function signature.
SEGMENT_COLUMNS = segment_column_name_arrayoptionalAn array of strings naming all segment columns in the data source. See ARRAY constants. Segment columns must be of type STRING in the source data, or STRING input features if the source is the auto-captured inference table. You can specify up to 5 segment columns per monitor. Each segment column should have fewer than 25 unique values for optimal performance. For more information about segments, see ML Observability: Monitoring model behavior over time.
CUSTOM_METRIC_COLUMNS = custom_metric_column_name_arrayoptionalAn array of strings naming columns in the source data that are used for custom metrics. These columns are not treated as features. See ARRAY constants. Columns must be of type NUMBER. Not supported when the source is the auto-captured inference table.

Usage notes

Access control requirements

A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes OWNERSHIP | Model monitor | OWNERSHIP is a special privilege on an object that is automatically granted to the role that created the object, but can also be transferred using the GRANT OWNERSHIP command to a different role by the owning role (or any role with the MANAGE GRANTS privilege). CREATE MODEL MONITOR | Schema | SELECT | Table or view specified by the SOURCE parameter | User-provided source only. USAGE | Model specified by the MODEL parameter | User-provided source only. OWNERSHIP | Model specified by the MODEL parameter | Auto-captured inference table source only. SELECT | Table specified by the GROUND_TRUTH parameter | Auto-captured inference table source only. SELECT | Table specified by the BASELINE parameter | USAGE | Warehouse specified by the WAREHOUSE parameter | Privilege | Object | Notes OWNERSHIP | Model monitor | OWNERSHIP is a special privilege on an object that is automatically granted to the role that created the object, but can also be transferred using the GRANT OWNERSHIP command to a different role by the owning role (or any role with the MANAGE GRANTS privilege). CREATE MODEL MONITOR | Schema | SELECT | Table specified by the GROUND_TRUTH parameter | USAGE | Warehouse specified by the WAREHOUSE parameter | OWNERSHIP | Model specified by the MODEL parameter | USAGE | Gateway specified by the GATEWAY parameter | Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema. For instructions on creating a custom role with a specified set of privileges, see Creating custom roles. For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

Known gaps

Parts not fully supported, and recorded divergences from Snowflake.

See also

Referenced by