PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb
The GenAI API provides the convenience methods described in this section under theml namespace. These methods act as wrappers for theLLM methods; rather than being invoked asLLM instance methods, they take the model ID as one of the options passed to them.ml.generate() andml.rag() return only the text portions of the values returned by their LLM counterparts.
This method is a wrapper forLLM.generate(). It loads the model specified by themodel_id specified as one of theoptions, generates a response based on the prompt using this model, and returns the response. The defaultmodel_id ("llama3.2-3b-instruct-v1") is used if one is not specified. Like theLLM 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): The desired promptoptions(Object) (default{}): The options employed for generation; these follow the same rules as the options used withLLM.generate()
Return type
String: The text of the response
Usage
// Both invocations use "llama3.2-3b-instruct-v1" as the model_idlet response = ml.generate("What is Mysql?", {max_tokens: 10})let response = ml.generate("What is Mysql?", {model_id: "llama3.2-3b-instruct-v1", max_tokens: 10})
Signature (batch processing)
undefined ml.generate( TableinputTable, StringinputColumn, StringoutputColumn, Objectoptions)
Arguments
inputTable(Table): Table to use for operationsinputColumn(String): Name of column frominputTableto be embeddedoutputColumn(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 nameoptions(Object) (optional; default{}): An object containing the options used for embedding; see the description ofML_EMBED_ROWfor 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 forLLM.embed(). Like theLLM 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 queryoptions(Object) (default{}): The options employed for generation; these follow the same rules as the options used withLLM.embed(); the defaultmodel_idis"all_minilm_l12_v2"
Return type
Float32Array(MySQLVECTOR): The embedding
Usage
// These produce the same resultlet 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 operationsinputColumn(String): Name of column frominputTableto be embeddedoutputColumn(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 nameoptions(Object) (optional; default{}): An object containing the options used for embedding; see the description ofML_EMBED_ROWfor 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) MySQL HeatWave AutoML model having the name specified. An error is thrown if model with the given name does not exist.
Signature
Object ml.load( Stringname)
Arguments
name(String): The name of the model.
Return type
Object: Any ofClassifier,Regressor,Forecaster,AnomalyDetector, orRecommender, depending on the type of model loaded.
For more information, seeML_MODEL_LOAD.
This is a wrapper forLLM.rag(). Like theLLM 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 queryoptions(Object) (default{}): The options employed for generation; these follow the same rules as the options used withLLM.rag(); the defaultmodel_idis"llama3.2-3b-instruct-v1"
Return type
String: Response text
Usage
// These produce the same resultlet result = ml.rag("What is MySql?", {schema: ["vector_store"], n_citations: 1, model_options: {model_id: "llama3.2-3b-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 operationsinputColumn(String): Name of column frominputTableto be embeddedoutputColumn(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 nameoptions(Object) (optional; default{}): An object containing the options used for embedding; see the description ofML_EMBED_ROWfor 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: "llama3.2-3b-instruct-v1"}});
PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb