Documentation Home
MySQL 9.2 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.7Mb
PDF (A4) - 40.8Mb
Man Pages (TGZ) - 259.6Kb
Man Pages (Zip) - 366.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.2 Reference Manual  /  ...  /  ml Namespace, Classes, and Convenience Methods

27.3.9.2 ml Namespace, Classes, and Convenience Methods

While MySQL provides SQL stored functions and procedures to invoke AutoML features, accessing these can be uninituitive for JavaScript developers. The JavaScript API described in this section acts as a wrapper which invokes these SQL stored programs.

Note

The AutoML feature is supported only by MySQL HeatWave, and thus the JavaScript API described here is supported only when HeatWave is enabled. See HeatWave AutoML, for more information.

27.3.9.2.1 Classifier Class

This class encapsulates the classification task as described in Training a Model. Classifier supports methods for loading, training, and unloading models, predicting labels, calculating probabilities, producing explainers, and related tasks.

An instance of Classifier has three accessible properties, listed here:

  • name (String): The model name.

  • metadata (Object): Model metadata stored in the model catalog. See Model Metadata.

  • trainOptions (Object): The training options specified in the constructor.

You can obtain an instance of Classifier by invoking its constructor, shown here:

Classifier class constructor

  • Press CTRL+C to copy
    new ml.Classifier( String name[, Object trainOptions] )

Arguments

  • name (String): Unique identifier for this Classifier.

  • trainOptions (Object) (optional): Training options; these are the same as the training options used with sys.ML_TRAIN.

Return type

  • An instance of Classifier.

Classifier was added in MySQL 9.2.0.

Classifier.train()

Trains and loads a new classifier. This method acts as a wrapper for both sys.ML_TRAIN and sys.ML_MODEL_LOAD, but is specific to the HeatWave AutoML classification task.

Signature

  • Press CTRL+C to copy
    Classifier.train( Table trainData, String targetColumnName )

Arguments

  • trainData (Table): A Table containing a training dataset. The table must not take up more than 10 GB space, or hold more than 100 million rows or more than 1017 columns.

  • targetColumnName (String): Name of the target column containing ground truth values. The type used for this column cannot be TEXT.

Return type

  • None.

Classifier.fit()

An alias for train(), and identical to it in all respects save the method name. See Classifier.train(), for more information.

Classifier.predict()

This method predicts labels; it has two variants, one of which predicts labels from data found in the indicated table and stores them in an output table; this is a wrapper for sys.ML_PREDICT_TABLE. The other variant of this method acts as a wrapper for sys.ML_PREDICT_ROW, and predicts a label for a single set of sample data and returns it to the caller. Both versions of predict() are shown here.

Version 1

Predicts labels and saves them in the specified output table.

Signature

  • Press CTRL+C to copy
    Classifier.predict( Table testData, Table outputTable[, Object options] )

Arguments

  • testData (Table): Table containing test data.

  • outputTable (Table): Table in which to store labels. The content and format of the output is the same as that generated by ML_PREDICT_TABLE.

  • options (Object) (optional): Set of options in JSON format. See ML_PREDICT_TABLE, for more information.

Return type

Version 2

Predicts a label for a single sample of data, and returns it. See ML_PREDICT_ROW, for more information.

Signature

  • Press CTRL+C to copy
    String Classifier.predict( Object sample )

Arguments

  • sample (Object): Sample data. This argument must contain members that were used for training; extra members may be included, but these are ignored during prediction.

Return type

  • String. See the documentation for ML_PREDICT_ROW for more information.

Classifier.predictProba()

Obtains the probabilities for all classes of the passed sample data. Like the single-argument version of predict(), this method is a wrapper for sys.ML_PREDICT_ROW, but unlike predict(), predictProba() returns the probabilities only.

Signature

  • Press CTRL+C to copy
    Classifier.predict( Object sample )

Arguments

  • sample (Object): Sample data, in the form of a JSON object. As with the single-argument version of Classifier.predict(), this argument must contain members that were used for training; extra members may be included, but these are ignored during prediction.

Return type

  • Object. The probabilities for the sample data, in JSON format.

Classifier.score()

Returns the score for the test data in the indicated table and column. For possible metric values and their effects, see Optimization and Scoring Metrics.

This method serves as a JavaScript wrapper for sys.ML_SCORE.

Signature

  • Press CTRL+C to copy
    score( Table testData, String targetColumnName, String metric[, Object options] )

Arguments

  • testData (Table): Table containing test data to be scored; this table must contain the same columns as the training dataset.

  • targetColumnName (String): Name of the target column containing ground truth values.

  • metric (String): Name of the scoring metric. See Optimization and Scoring Metrics, for information about the metrics compatible with AutoML classification.

  • options (Object) (optional): A set of options in JSON format. See the description of ML_SCORE for more information.

Return type

  • Number.

Classifier.explain()

Given a Table containing a labeled, trained dataset and the name of a table column containing ground truth values, this method returns the newly trained explainer.

This method serves as a wrapper for the HeatWave AutoML sys.ML_EXPLAIN routine; see the description of that routine for further information.

Signature

  • Press CTRL+C to copy
    explain( Table data, String targetColumnName[, Object options] )

Arguments

  • data (Table): A table containing trained data.

  • targetColumnName (String): The name of the column containing ground truth values.

  • options (Object) (optional): A set of optional parameters, in JSON format.

Return type

  • None. Adds a model explainer to the model catalog; see ML_EXPLAIN, for more information.

Classifier.getExplainer()

Returns an explainer for this classifier, if one exists.

Signature

  • Press CTRL+C to copy
    Object Classifier.getExplainer()

Arguments

  • None.

Return type

  • Object

Classifier.unload()

Unloads the model. This method is a wrapper for sys.ML_MODEL_UNLOAD.

Signature

  • Press CTRL+C to copy
    Classifier.unload()

Arguments

  • None.

Return type

  • undefined

27.3.9.2.2 Regressor Class

This class is similar to Classifier and Forecaster in that it represents an AutoML training model, but encapsulates the regression task as described in the MySQL HeatWave documentation (see Training a Model).

Like other such classes in the ml namespace, Regressor supports methods for loading, training, and unloading models, predicting labels, calculating probabilities, producing explainers, and related tasks; it also has three accessible instance properties, listed here:

  • name (String): The model name.

  • metadata (Object): Model metadata stored in the model catalog. See Model Metadata.

  • trainOptions (Object): The training options specified in the constructor (shown following).

To obtain an instance of Regressor, simply invoke its constructor, shown here:

Regressor class constructor

  • Press CTRL+C to copy
    new ml.Regressor( String name[, Object trainOptions] )

Arguments

  • name (String): Unique identifier for this instance of Regressor.

  • trainOptions (Object) (optional): Training options. These are the same as those used with sys.ML_TRAIN.

Return type

  • An instance of Regressor.

Regressor was added in MySQL 9.2.0.

Regressor.train()

Trains and loads a new regressor, acting as a wrapper for sys.ML_TRAIN and sys.ML_MODEL_LOAD, specific to the AutoML regression task.

Signature

  • Press CTRL+C to copy
    Regressor.train( Table trainData, String targetColumnName )

Arguments

  • trainData (Table): A Table which contains a training dataset. The table must not exceed 10 GB in size, or contain more than 100 million rows or more than 1017 columns.

  • targetColumnName (String): Name of the target column containing ground truth values; TEXT columns are not supported for this purpose.

Return type

  • undefined.

Regressor.fit()

This is merely an alias for train(). In all respects except for their names, the two methods are identical. See Regressor.train(), for more information.

Regressor.predict()

This method predicts labels. predict() has two variants, listed here:

  • Stores labels predicted from data found in the indicated table and stores them in an output table; a wrapper for sys.ML_PREDICT_TABLE.

  • A wrapper for sys.ML_PREDICT_ROW; predicts a label for a single set of sample data and returns it to the caller.

Both versions of predict() are shown in this section.

Version 1

This version of predict() predicts labels, then saves them in an output table specified when invoking the method.

Signature

  • Press CTRL+C to copy
    Regressor.predict( Table testData, Table outputTable[, Object options] )

Arguments

  • testData (Table): A table containing test data.

  • outputTable (Table): A table for storing the predicted labels. The output's content and format are the same as for that produced by ML_PREDICT_TABLE.

  • options (Object) (optional): Set of options in JSON format. See ML_PREDICT_TABLE, for more information.

Return type

  • undefined.

Version 2

Predicts a label for a single sample of data, and returns it to the caller. See ML_PREDICT_ROW, for more information.

Signature

  • Press CTRL+C to copy
    String Regressor.predict( Object sample )

Arguments

  • sample (Object): Sample data. This argument must contain members that were used for training; while extra members may be included, these are ignored for purposes of prediction.

Return type

Regressor.score()

Returns the score for the test data in the table and column indicated by the user, using a specified metric; a JavaScript wrapper for sys.ML_SCORE.

Signature

  • Press CTRL+C to copy
    score( Table testData, String targetColumnName, String metric[, Object options] )

Arguments

  • testData (Table): Table containing test data to be scored; this table must contain the same columns as the training dataset.

  • targetColumnName (String): The name of the target column containing ground truth values.

  • metric (String): Name of the scoring metric to be employed. Optimization and Scoring Metrics, provides information about metrics compatible with the AutoML regression task.

  • options (Object) (optional): A set of options, as keys and values, in JSON format. See the description of ML_SCORE for more information.

Return type

  • Number.

Regressor.explain()

This method takes a Table containing a labeled, trained dataset and the name of a table column containing ground truth values, and returns the newly trained explainer; a wrapper for the MySQL HeatWave sys.ML_EXPLAIN routine.

Signature

  • Press CTRL+C to copy
    explain( Table data, String targetColumnName[, Object options] )

Arguments

  • data (Table): Table containing trained data.

  • targetColumnName (String): Name of column containing ground truth values.

  • options (Object) (optional): Set of optional parameters, in JSON format.

Return type

  • Adds a model explainer to the model catalog; does not return a value. See ML_EXPLAIN, for more information.

Regressor.getExplainer()

Returns an explainer for this Regressor.

Signature

  • Press CTRL+C to copy
    Object Regressor.getExplainer()

Arguments

  • None.

Return type

  • Object

Regressor.unload()

Unloads the model. This method is a wrapper for sys.ML_MODEL_UNLOAD.

Signature

  • Press CTRL+C to copy
    Regressor.unload()

Arguments

  • None.

Return type

  • undefined

27.3.9.2.3 Forecaster Class

This class encapsulates the forecasting task as described in Forecasting. Forecaster supports methods for loading, training, and unloading models, predicting labels, and related tasks.

Each instance of Forecaster has three accessible properties, listed here:

  • name (String): The model name.

  • metadata (Object): Model metadata stored in the model catalog. See Model Metadata.

  • trainOptions (Object): The training options that were specified in the constructor when creating this instance.

You can obtain an instance of Forecaster by invoking its constructor, shown here:

Forecaster class constructor

  • Press CTRL+C to copy
    new ml.Forecaster( String name[, Object trainOptions] )

Arguments

  • name (String): Unique identifier for this Forecaster.

  • trainOptions (Object) (optional): Training options; these are the same as the training options used with sys.ML_TRAIN.

Return type

  • An instance of Forecaster.

Forecaster was added in MySQL 9.2.0.

Forecaster.train()

Trains and loads a new forecast. This method acts as a wrapper for both sys.ML_TRAIN and sys.ML_MODEL_LOAD, but is specific to HeatWave AutoML forecasting.

Signature

  • Press CTRL+C to copy
    Forecaster.train( Table trainData, String index, Array[String] endogenousVariables[, Array[String] exogenousVariables] )

Arguments

  • trainData (Table): A Table containing a training dataset. The table must not take up more than 10 GB space, or hold more than 100 million rows or more than 1017 columns.

  • index (String): Name of the target column containing ground truth values. This must not be a TEXT column.

  • endogenousVariables (Array[String]): The name or names of the column or columns to be forecast.

  • exogenousVariables (Array[String]): The name or names of the column or columns of independent, predictive variables, and have not been forecast.

Return type

Forecaster.fit()

An alias for train(), and identical to it in all respects save the method name. See Forecaster.train(), for more information.

Forecaster.predict()

This method predicts labels, and has two variants, one of which predicts labels from data found in the indicated table and stores them in an output table; this variant of predict() acts as a JavaScript wrapper for sys.ML_PREDICT_TABLE. The other variant of this method is a wrapper for sys.ML_PREDICT_ROW, and predicts a label for a single set of sample data and returns it to the caller. Both versions are shown here.

Version 1

Predicts labels, saving them in the output table specified by the user.

Signature

  • Press CTRL+C to copy
    Forecaster.predict( Table testData, Table outputTable[, Object options] )

Arguments

  • testData (Table): Table containing test data.

  • outputTable (Table): Table in which to store labels. The output written to the table uses the same content and format as that generated by the AutoML ML_PREDICT_TABLE routine.

  • options (Object) (optional): Set of options in JSON format. For more information, see ML_PREDICT_TABLE.

Return type

  • None. (Inserts into a target table.)

Version 2

Predicts a label for a single sample of data, and returns it. See ML_PREDICT_ROW, for more information about type and format of the value returned.

Signature

  • Press CTRL+C to copy
    String Forecaster.predict( Object sample )

Arguments

  • sample (Object): Sample data containing members that were used for training; extra members may be included but are ignored during prediction.

Return type

Forecaster.score()

Returns the score for the test data in the indicated table and column, using the specified metric. For possible metric values and their effects, see Optimization and Scoring Metrics.

score() is a JavaScript wrapper for sys.ML_SCORE.

Signature

  • Press CTRL+C to copy
    score( Table testData, String targetColumnName, String metric[, Object options] )

Arguments

  • testData (Table): Table which contains the test data. The table must contain the same columns as the training dataset.

  • targetColumnName (String): Name of the target column containing ground truth values.

  • metric (String): Name of the scoring metric. See Optimization and Scoring Metrics, for information about metrics which can be used for HeatWave AutoML forecasting.

  • options (Object) (optional): A set of options in JSON key-value format. For more information, see ML_SCORE.

Return type

  • Number.

Forecaster.unload()

Unloads the model. This method is a wrapper for sys.ML_MODEL_UNLOAD; see the description of this routine in the HeatWave AutoML documentation for more information.

Signature

  • Press CTRL+C to copy
    Forecaster.unload()

Arguments

  • None.

Return type

  • None.

27.3.9.2.4 AnomalyDetector Class

This class encapsulates the anomaly detection task as described in Anomaly Detection. AnomalyDetector supports methods for loading, training, and unloading models, predicting labels, calculating probabilities, and related tasks.

AnomalyDetector provides the following accessible properties:

  • name (String): The model name.

  • metadata (Object): Model metadata in the model catalog. See Model Metadata.

  • trainOptions (Object): The training options specified in the constructor when creating an instance of AnomalyDetector.

The AnomalyDetector class constructor is shown here:

AnomalyDetector class constructor

  • Press CTRL+C to copy
    new ml.AnomalyDetector( String name[, Object trainOptions] )

Arguments

  • name (String): Unique identifier for this AnomalyDetector.

  • trainOptions (Object) (optional): Training options; the same as the training options which can be used with sys.ML_TRAIN.

Return type

  • An instance of AnomalyDetector.

The AnomalyDetector class was added in MySQL 9.2.0.

AnomalyDetector.train()

Trains and loads a new anomaly detector. This method acts as a wrapper for both sys.ML_TRAIN and sys.ML_MODEL_LOAD, but is specific to HeatWave AutoML anomaly detection.

Signature

  • Press CTRL+C to copy
    AnomalyDetector.train( Table trainData, String targetColumnName )

Arguments

  • trainData (Table): A Table containing a training dataset. The table must not take up more than 10 GB space, or hold more than 100 million rows or more than 1017 columns.

  • targetColumnName (String): Name of the target column containing ground truth values. The type used for this column cannot be TEXT.

Return type

  • None.

AnomalyDetector.fit()

An alias for train(), and identical to it in all respects other than name. See AnomalyDetector.train(), for more information.

AnomalyDetector.predict()

This method predicts labels, acting as a wrapper for sys.ML_PREDICT_ROW.

Predicts a label for a single sample of data, and returns the label. See ML_PREDICT_ROW, for more information.

Signature

  • Press CTRL+C to copy
    String AnomalyDetector.predict( Object sample[, Object options] )

Arguments

  • sample (Object): Sample data. This argument must contain members that were used for training; extra members may be included, but these are ignored during prediction.

  • options (Object) (optional): Set of one of more options.

Return type

  • String.

AnomalyDetector.score()

This method serves as a JavaScript wrapper for sys.ML_SCORE, returning the score for the test data in the specified table and column. For possible metrics, see Optimization and Scoring Metrics.

Signature

  • Press CTRL+C to copy
    score( Table testData, String targetColumnName, String metric[, Object options] )

Arguments

  • testData (Table): Table containing test data to be scored; must contain the same columns as the training dataset.

  • targetColumnName (String): Name of the target column containing ground truth values.

  • metric (String): Name of the scoring metric to use. See Optimization and Scoring Metrics, for information about metrics which can be used for AutoML anomaly detection.

  • options (Object) (optional): A set of options in JSON object format. See the description of ML_SCORE for more information.

Return type

  • Number.

AnomalyDetector.unload()

This method is a wrapper for sys.ML_MODEL_UNLOAD, and Unloads the model.

Signature

  • Press CTRL+C to copy
    AnomalyDetector.unload()

Arguments

  • None.

Return type

  • None.

27.3.9.2.5 Recommender Class

This class encapsulates the recommendation task as described in Recommendations. Recommender supports methods for loading, training, and unloading models, predicting labels, calculating probabilities, producing explainers, and related tasks.

An instance of Recommender has three accessible properties, listed here:

  • name (String): The model name.

  • metadata (Object): Model metadata stored in the model catalog. See Model Metadata.

  • trainOptions (Object): The training options specified in the constructor.

You can obtain an instance of Recommender by invoking its constructor, shown here:

Recommender class constructor

  • Press CTRL+C to copy
    new ml.Recommender( String name[, Object trainOptions] )

Arguments

  • name (String): Unique identifier for this Recommender.

  • trainOptions (Object) (optional): Training options; same as training options permitted for sys.ML_TRAIN.

Return type

  • An instance of Recommender.

Recommender was added in MySQL 9.2.0.

Recommender.train()

Trains and loads a new recommender. This method acts as a wrapper for both sys.ML_TRAIN and sys.ML_MODEL_LOAD, but is specific to the AutoML recommendation task.

Signature

  • Press CTRL+C to copy
    Recommender.train( Table trainData, String users, String items, String ratings )

Arguments

  • trainData (Table): A Table containing a training dataset. The maximum size of the table must not exceed 10 GB space, 100 million rows, or 1017 columns.

  • users (String): List of one or more users.

  • items (String): List of one or more items being rated.

  • ratings (String): List of ratings.

Return type

  • None.

Recommender.fit()

This is an alias for train(), to which it is identical in all respects other than the method name. See Recommender.train(), for more information.

Recommender.predictRatings()

This method predicts ratings for one or more samples, and provides two variants. The first of these predicts ratings over a table and stores them in an output table, while the second predicts the rating of a single sample of data and returns the rating to the caller. Both versions are covered in this section.

See also Using a Recommendation Model.

Version 1

Predicts ratings over an entire table and stores them in the specified output table. A wrapper for the HeatWave AutoML ML_PREDICT_TABLE routine.

Signature

  • Press CTRL+C to copy
    Recommender.predictRatings( Table testData, Table outputTable[, Object options])

Arguments

  • testData (Table): Table containing sample data.

  • outputTable (Table): Table in which to store predicted ratings.

  • options (Object) (optional): Options used for prediction.

Return type

  • None.

Version 2

Returns the rating predicted for a single sample of data. This is a wrapper for ML_PREDICT_ROW.

Signature

  • Press CTRL+C to copy
    Object Recommender.predictRatings( Object sample[, Object options] )

Arguments

Return type

Recommender.predictItems()

This method predicts items for users, as described in Using a Recommendation Model. Like other Recommender prediction methods, predictItems() exists in two versions. The first predicts items over an entire table of users and stores the predictions in an output table, while the second predicts items for a single sample of data. Both versions are described in this section.

Version 1

Predicts items over a table of users and stores the predictions in an output table; JavaScript wrapper for ML_PREDICT_TABLE.

Signature

  • Press CTRL+C to copy
    Recommender.predictItems( Table testData, Table outputTable[, Object options])

Arguments

  • testData (Table): Table containing data.

  • outputTable (Table): Table for storing predictions.

  • options (Object) (optional): Set of options to use when making predictions; see Options for Generating Predictions and Scores, for more information about possible options.

Return type

  • None.

Version 2

Predicts items for a single sample of user data. This form of the method is a wrapper for ML_PREDICT_ROW.

Signature

  • Press CTRL+C to copy
    Object Recommender.predictItems( Object sample[, Object options] )

Arguments

  • sample (Object): Sample data.

  • options (Object) (optional): One or more options to employ when making predictions.

Return type

  • Object; a set of predictions.

Recommender.predictUsers()

Depending on which version of the method is called, predictUsers() either predicts users over an entire table of items and stores them in an output table, or predicts users for a single set of sample item data and returns the result as an object. (See Using a Recommendation Model.) Both versions are described in the following paragraphs.

Version 1

Predicts users over a table of items and stores them in an output table. A wrapper for ML_PREDICT_TABLE specific to AutoML user prediction.

Signature

  • Press CTRL+C to copy
    Recommender.predictUsers( Table testData, Table outputTable[, Object options] )

Arguments

  • testData (Table): Table containing item data.

  • outputTable (Table): Table for storing user predictions.

  • options (Object) (optional): Set of options to use when making predictions; see Options for Generating Predictions and Scores, for information about possible options.

Return type

  • None.

Version 2

Predicts users for a single sample of item data and returns the result; a JavaScript wrapper for the HeatWave AutoML ML_PREDICT_ROW routine, intended for user prediction.

Signature

  • Press CTRL+C to copy
    Object Recommender.predictUsers( Object sample[, Object options] )

Arguments

  • sample (Object): Sample item data.

  • options (Object) (optional): One or more options to employ when making predictions.

Return type

  • Object; this is a set of user predictions in JavaScript object format.

Recommender.predictSimilarItems()

From items given, predict similar items. Two variants of this method are supported, as described in the rest of this section: the first predicts similar items for an entire table containing items, and stores the predictions in an output table; the other returns a set of predicted similar items for a single set of items.

predictSimilarItems(Table testData, Table outputTable[, Object options]) predicts similar items over the whole table of items and stores them in outputTable. Refer to docs for more information.

predictSimilarItems(Object sample[, Object options]) -> Object predicts similar items from the single item. Refer to docs for more information.

Version 1

Predicts similar items over a table of items and stores the predicted items in an output table. A wrapper for ML_PREDICT_TABLE specific to AutoML the recomendation task for user prediction.

Signature

  • Press CTRL+C to copy
    Recommender.predictSimilarItems( Table testData, Table outputTable[, Object options] )

Arguments

  • testData (Table): Table which contains item data.

  • outputTable (Table): Table used for storing user predictions.

  • options (Object) (optional): Set of options to use when making predictions. For information about the options available, see Options for Generating Predictions and Scores.

Return type

  • None.

Version 2

This version of predictSimilarUsers() predicts similar items for a single sample of item data and returns the result; a JavaScript wrapper for the HeatWave AutoML ML_PREDICT_ROW routine, intended for recommendation for similar item prediction.

Signature

  • Press CTRL+C to copy
    Object Recommender.predictSimilarItems( Object sample[, Object options] )

Arguments

  • sample (Object): Sample item data.

  • options (Object) (optional): One or more options to employ when making predictions.

Return type

  • Object; a set of predicted similar items.

Recommender.predictSimilarUsers()

Predicts similar users from a given set of users (see Using a Recommendation Model). Two versions of this method are supported; both are described in this section.

Version 1

Options for Generating Predictions and Scores

Signature

  • Press CTRL+C to copy
    predictSimilarUsers( Table testData, Table outputTable[, Object options] )

Arguments

  • testData (Table): Table which contains item data.

  • outputTable (Table): Table used for storing user predictions.

  • options (Object) (optional): Set of options to use when making predictions. For information about the options available, see Options for Generating Predictions and Scores.

Return type

  • None.

Version 2

Predicts similar users from a sample and returns the predictions to the caller.

Signature

  • Press CTRL+C to copy
    Object predictSimilarUsers( Object sample[, Object options] )

Arguments

  • sample (Object): Sample item data.

  • options (Object) (optional): One or more options to employ when making predictions.

Return type

  • Object; this is a set of predicted similar users.

Recommender.score()

Returns the score for the test data in the indicated table and column. For possible metrics and their effects, see Optimization and Scoring Metrics.

This method serves as a JavaScript wrapper for the HeatWave AutoML sys.ML_SCORE routine.

Signature

  • Press CTRL+C to copy
    score( Table testData, String targetColumnName, String metric[, Object options] )

Arguments

  • testData (Table): Table containing test data to be scored; this table must contain the same columns as the training dataset.

  • targetColumnName (String): Name of the target column containing ground truth values.

  • metric (String): Name of the scoring metric. See Optimization and Scoring Metrics, for information about the metrics compatible with AutoML recommendation.

  • options (Object) (optional): A set of options in JSON format. See the description of ML_SCORE for more information.

Return type

  • Number.

Recommender.unload()

Unloads the model. This method is a JavaScript wrapper for sys.ML_MODEL_UNLOAD; see the description of this function in the HeatWave AutoML documentation for related information.

Signature

  • Press CTRL+C to copy
    Recommender.unload()

Arguments

  • None.

Return type

  • None.

27.3.9.2.6 Explainer Class

This class is an abstraction of the AutoML explainer model as described in Training Explainers. It has no explicit constructor, but rather is obtained by invoking Classifier.getExplainer() or Regressor.getExplainer().

Explainer exposes a single method, explain(), in two variants, both of which are described in this section.

Explainer.explain()

Version 1

This form of explain() is a JavaScript wrapper for ML_EXPLAIN_TABLE, and explains the training data from a given table using any supplied options, and placing the results in an output table.

Signature

  • Press CTRL+C to copy
    Explainer.explain( Table testData, Table outputTable[, Object options] )

Arguments

  • testData (Table): Table containing data to be explained.

  • outputTable (Table): Table used for storing results.

  • options (Object) (optional): Set of options to use when explaining. For more information, see Table Explanations.

Return type

  • None. (Inserts into a table.)

Version 2

Explains a sample containing training data, which must contain members used in training; extra members are ignored. This form of explain() is a wrapper for ML_EXPLAIN_ROW.

Signature

  • Press CTRL+C to copy
    explain( Object sample[, Object options] )

Arguments

  • sample (Object): A sample containing training data.

  • options (Object) (optional): Options to be used; see Row Explanations, for more information.

Return type

  • None.

27.3.9.2.7 ml Convenience Methods

The GenAI API provides the convenience methods described in this section under the ml namespace. These methods act as wrappers for the LLM methods; rather than being invoked as LLM instance methods, they take the model ID as one of the options passed to them. ml.generate() and ml.rag() return only the text portions of the values returned by their LLM counterparts.

ml.generate()

This method is a wrapper for LLM.generate(). It loads the model specified by the model_id specified as one of the options, generates a response based on the prompt using this model, and returns the response. The default model_id ("cohere.command") is used if one is not specified. Like the LLM method, ml.generate() supports two variants, one for a single invocation, and one for batch processing.

Signature (single job)

  • Press CTRL+C to copy
    String ml.generate( String prompt, Object options )

Arguments

  • prompt (String) (default "cohere.command"): The desired prompt

  • options (Object) (default {}): The options employed for generation; these follow the same rules as the options used with LLM.generate()

Return type

  • String: The text of the response

Usage

  • Press CTRL+C to copy
    // Both invocations use "cohere.command" as the model_id let response = ml.generate("What is Mysql?", {max_tokens: 10}) let response = ml.generate("What is Mysql?", {model_id: "cohere.command", max_tokens: 10})

Signature (batch processing)

  • Press CTRL+C to copy
    undefined ml.generate( Table inputTable, String inputColumn, String outputColumn, Object options )

Arguments

  • inputTable (Table): Table to use for operations

  • inputColumn (String): Name of column from inputTable to be embedded

  • outputColumn (String): Name of column in which to store embeddings; this can be either a fully-qualified name of a column or the name of the column only; in the latter case, the input table and its schema are used to construct the fully-qualified name

  • options (Object) (optional; default {}): An object containing the options used for embedding; see the description of ML_EMBED_ROW for available options

Return type

  • undefined

Usage

  • Press CTRL+C to copy
    let schema = session.getSchema("mlcorpus") let table = schema.getTable("genai_table") ml.generate(table, "input", "mlcorpus.predictions.response", {max_tokens: 10})
ml.embed()

This method is a wrapper for LLM.embed(). Like the LLM method, it supports two variants, one for a single invocation, and one for batch processing.

Signature (single job)

  • Press CTRL+C to copy
    Float32Array ml.embed( String query, Object options )

Arguments

  • query (String): Text of a natural-language query

  • options (Object) (default {}): The options employed for generation; these follow the same rules as the options used with LLM.embed(); the default model_id is "all_minilm_l12_v2"

Return type

  • Float32Array (MySQL VECTOR): The embedding

Usage

  • Press CTRL+C to copy
    // These produce the same result let embedding = ml.embed("What is Mysql?", {model_id: "all_minilm_l12_v2"}) let embedding = ml.embed("What is Mysql?", {})

Signature (batch processing)

  • Press CTRL+C to copy
    undefined ml.embed( Table inputTable, String inputColumn, String outputColumn, Object options )

Arguments

  • inputTable (Table): Table to use for operations

  • inputColumn (String): Name of column from inputTable to be embedded

  • outputColumn (String): Name of column in which to store embeddings; this can be either a fully-qualified name of a column or the name of the column only; in the latter case, the input table and its schema are used to construct the fully-qualified name

  • options (Object) (optional; default {}): An object containing the options used for embedding; see the description of ML_EMBED_ROW for available options

Return type

  • undefined

Usage

  • Press CTRL+C to copy
    let schema = session.getSchema("mlcorpus") let table = schema.getTable("genai_table") ml.embed(table, "input", "mlcorpus.predictions.response", {model_id: "all_minilm_l12_v2"})
ml.load()

This static method loads an existing (and already trained) HeatWave AutoML model having the name specified. An error is thrown if model with the given name does not exist.

Signature

  • Press CTRL+C to copy
    Object ml.load( String name )

Arguments

  • name (String): The name of the model.

Return type

ml.load() was added in MySQL 9.2.0. For more information, see ML_MODEL_LOAD.

ml.rag()

This is a wrapper for LLM.rag(). Like the LLM method, it supports two variants, one for a single invocation, and one for batch processing.

Signature (single job)

  • Press CTRL+C to copy
    String ml.rag( String query, Object options )

Arguments

  • query (String): Text of a natural-language query

  • options (Object) (default {}): The options employed for generation; these follow the same rules as the options used with LLM.rag(); the default model_id is "mistral-7b-instruct-v1"

Return type

  • String: Response text

Usage

  • Press CTRL+C to copy
    // These produce the same result let result = ml.rag("What is MySql?", {schema: ["vector_store"], n_citations: 1, model_options: {model_id: "mistral-7b-instruct-v1"}}) let result = ml.rag("What is MySql?", {schema: ["vector_store"], n_citations: 1})

Signature (batch processing)

  • Press CTRL+C to copy
    undefined ml.rag( Table inputTable, String inputColumn, String outputColumn, Object options )

Arguments

  • inputTable (Table): Table to use for operations

  • inputColumn (String): Name of column from inputTable to be embedded

  • outputColumn (String): Name of column in which to store embeddings; this can be either a fully-qualified name of a column or the name of the column only; in the latter case, the input table and its schema are used to construct the fully-qualified name

  • options (Object) (optional; default {}): An object containing the options used for embedding; see the description of ML_EMBED_ROW for available options

Return type

  • undefined

Usage

  • Press CTRL+C to copy
    let schema = session.getSchema("mlcorpus") let table = schema.getTable("genai_table") ml.rag(table, "input", "mlcorpus.predictions.response", {schema: ["vector_store"], n_citations: 1, model_options: {model_id: "mistral-7b-instruct-v1"}});