MySQL 9.3 Reference Manual Including MySQL NDB Cluster 9.3
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.
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.
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:
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
new ml.Classifier( Stringname
[, ObjecttrainOptions
] )
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
.
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
Classifier.train( TabletrainData
, StringtargetColumnName
)
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.
An alias for
train()
, and
identical to it in all respects save the method name. See
Classifier.train(), for more
information.
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.
Predicts labels and saves them in the specified output table.
Signature
Classifier.predict( TabletestData
, TableoutputTable
[, Objectoptions
] )
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
None. (Inserts into
outputTable
; see
ML_PREDICT_ROW.)
Predicts a label for a single sample of data, and returns it. See ML_PREDICT_ROW, for more information.
Signature
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.
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
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.
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
score( TabletestData
, StringtargetColumnName
, Stringmetric
[, Objectoptions
] )
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
.
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
explain( Tabledata
, StringtargetColumnName
[, Objectoptions
] )
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.
Returns an explainer for this classifier, if one exists.
Signature
Object Classifier.getExplainer()
Arguments
None.
Return type
Object
Unloads the model. This method is a wrapper for
sys.ML_MODEL_UNLOAD
.
Signature
Classifier.unload()
Arguments
None.
Return type
undefined
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:
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
new ml.Regressor( Stringname
[, ObjecttrainOptions
] )
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
.
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
Regressor.train( TabletrainData
, StringtargetColumnName
)
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
.
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.
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.
This version of predict()
predicts
labels, then saves them in an output table specified when
invoking the method.
Signature
Regressor.predict( TabletestData
, TableoutputTable
[, Objectoptions
] )
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
.
Predicts a label for a single sample of data, and returns it to the caller. See ML_PREDICT_ROW, for more information.
Signature
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
String
. See
ML_PREDICT_ROW.
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
score( TabletestData
, StringtargetColumnName
, Stringmetric
[, Objectoptions
] )
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
.
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
explain( Tabledata
, StringtargetColumnName
[, Objectoptions
] )
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.
Returns an explainer for this Regressor
.
Signature
Object Regressor.getExplainer()
Arguments
None.
Return type
Object
Unloads the model. This method is a wrapper for
sys.ML_MODEL_UNLOAD
.
Signature
Regressor.unload()
Arguments
None.
Return type
undefined
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:
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
new ml.Forecaster( Stringname
[, ObjecttrainOptions
] )
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
.
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
Forecaster.train( TabletrainData
, Stringindex
, 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
Does not return a value. After invoking this method, you
can observe its effects by selecting from the
MODEL_CATALOG
and
model_object_catalog
tables, as
described in
the examples
provided in the HeatWave documentation.
An alias for
train()
, and
identical to it in all respects save the method name. See
Forecaster.train(), for more
information.
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.
Predicts labels, saving them in the output table specified by the user.
Signature
Forecaster.predict( TabletestData
, TableoutputTable
[, Objectoptions
] )
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.)
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
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
String
. See the documentation for
ML_PREDICT_ROW
for
details.
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
score( TabletestData
, StringtargetColumnName
, Stringmetric
[, Objectoptions
] )
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
.
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
Forecaster.unload()
Arguments
None.
Return type
None.
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:
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
new ml.AnomalyDetector( Stringname
[, ObjecttrainOptions
] )
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
.
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
AnomalyDetector.train( TabletrainData
, StringtargetColumnName
)
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.
An alias for
train()
,
and identical to it in all respects other than name. See
AnomalyDetector.train(), for more
information.
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
String AnomalyDetector.predict( Objectsample
[, Objectoptions
] )
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
.
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
score( TabletestData
, StringtargetColumnName
, Stringmetric
[, Objectoptions
] )
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
.
This method is a wrapper for
sys.ML_MODEL_UNLOAD
, and
Unloads the model.
Signature
AnomalyDetector.unload()
Arguments
None.
Return type
None.
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:
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
new ml.Recommender( Stringname
[, ObjecttrainOptions
] )
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
.
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
Recommender.train( TabletrainData
, Stringusers
, Stringitems
, Stringratings
)
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.
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.
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.
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
Recommender.predictRatings( TabletestData
, TableoutputTable
[, Objectoptions
])
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.
Returns the rating predicted for a single sample of data.
This is a wrapper for
ML_PREDICT_ROW
.
Signature
Object Recommender.predictRatings( Objectsample
[, Objectoptions
] )
Arguments
sample
(Object
): Data sample. Refer to
Using a Recommendation Model,
for format and other information.
options
(Object
)
(optional): One or more options, as
described under
Options for Generating Predictions and Scores,
in the HeatWave AutoML documentation.
Return type
Object
. See
Generating Recommendations for Ratings and Rankings,
for details.
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.
Predicts items over a table of users and stores the
predictions in an output table; JavaScript wrapper for
ML_PREDICT_TABLE
.
Signature
Recommender.predictItems( TabletestData
, TableoutputTable
[, Objectoptions
])
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.
Predicts items for a single sample of user data. This form
of the method is a wrapper for
ML_PREDICT_ROW
.
Signature
Object Recommender.predictItems( Objectsample
[, Objectoptions
] )
Arguments
sample
(Object
): Sample data.
options
(Object
)
(optional): One or more options to
employ when making predictions.
Return type
Object
; a set of predictions.
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.
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
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.
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
Object Recommender.predictUsers( Objectsample
[, Objectoptions
] )
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.
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.
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
Recommender.predictSimilarItems( TabletestData
, TableoutputTable
[, Objectoptions
] )
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.
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
Object Recommender.predictSimilarItems( Objectsample
[, Objectoptions
] )
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.
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.
Options for Generating Predictions and Scores
Signature
predictSimilarUsers( TabletestData
, TableoutputTable
[, Objectoptions
] )
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.
Predicts similar users from a sample and returns the predictions to the caller.
Signature
Object predictSimilarUsers( Objectsample
[, Objectoptions
] )
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.
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
score( TabletestData
, StringtargetColumnName
, Stringmetric
[, Objectoptions
] )
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
.
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
Recommender.unload()
Arguments
None.
Return type
None.
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.
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
Explainer.explain( TabletestData
, TableoutputTable
[, Objectoptions
] )
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.)
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
explain( Objectsample
[, Objectoptions
] )
Arguments
sample
(Object
): A sample containing
training data.
options
(Object
)
(optional): Options to be used; see
Row Explanations,
for more information.
Return type
None.
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.
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)
String ml.generate( Stringprompt
, Objectoptions
)
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
// 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)
undefined ml.generate( TableinputTable
, StringinputColumn
, StringoutputColumn
, Objectoptions
)
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
let schema = session.getSchema("mlcorpus") let table = schema.getTable("genai_table") ml.generate(table, "input", "mlcorpus.predictions.response", {max_tokens: 10})
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)
Float32Array ml.embed( Stringquery
, Objectoptions
)
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
// 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)
undefined ml.embed( TableinputTable
, StringinputColumn
, StringoutputColumn
, Objectoptions
)
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
let schema = session.getSchema("mlcorpus") let table = schema.getTable("genai_table") ml.embed(table, "input", "mlcorpus.predictions.response", {model_id: "all_minilm_l12_v2"})
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
Object ml.load(
String name
)
Arguments
name
(String
): The name of the model.
Return type
Object
: Any of
Classifier
,
Regressor
,
Forecaster
,
AnomalyDetector
, or
Recommender
,
depending on the type of model loaded.
For more information, see ML_MODEL_LOAD.
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)
String ml.rag( Stringquery
, Objectoptions
)
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
// 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)
undefined ml.rag( TableinputTable
, StringinputColumn
, StringoutputColumn
, Objectoptions
)
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
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"}});