The ML_GENERATE_TABLE routine runs multiple
text generation or summarization queries in a batch, in
parallel. The output generated for every input query is the same
as the output generated by the
ML_GENERATE
routine.
In versions older than MySQL 9.2.1, to alter an existing table
or create a new table, MySQL requires you to set the
sql-require-primary-key
system variable to 0.
This routine is available as of MySQL 9.0.1-u1.
This topic contains the following sections:
To learn about the privileges you need to run this routine, see Section 7.3, “MySQL HeatWave GenAI Roles and Privileges”.
mysql> CALL sys.ML_GENERATE_TABLE('InputTableColumn', 'OutputTableColumn'[, options]);
options: JSON_OBJECT(keyvalue[, keyvalue]...)
keyvalue:
{
'task', {'generation'|'summarization'}
|'model_id', 'ModelID'
|'context_column', 'ContextColumn'
|'language', 'Language'
|'temperature', Temperature
|'max_tokens', MaxTokens
|'top_k', K
|'top_p', P
|'repeat_penalty', RepeatPenalty
|'frequency_penalty', FrequencyPenalty
|'presence_penalty', PresencePenalty
|'stop_sequences', JSON_ARRAY('StopSequence'[, 'StopSequence'] ...)
|'batch_size', BatchSize
|'speculative_decoding', {true|false}
|'image_column', InputTableImageColumn
}
Following are ML_GENERATE_TABLE parameters:
-
InputTableColumn: specifies the names of the input database, table, and column that contains the natural-language queries. TheInputTableColumnis specified in the following format:DBName.TableName.ColumnName.The specified input table can be an internal or external table.
The specified input table must already exist, must not be empty, and must have a primary key.
The input column must already exist and must contain
textorvarcharvalues.The input column must not be a part of the primary key and must not have
NULLvalues or empty strings.There must be no backticks used in the
DBName,TableName, orColumnNameand there must be no period used in theDBNameorTableName.
-
OutputTableColumn: specifies the names of the database, table, and column where the generated text-based response is stored. TheOutputTableColumnis specified in the following format:DBName.TableName.ColumnName.The specified output table must be an internal table.
If the specified output table already exists, then it must be the same as the input table. And, the specified output column must not already exist in the input table. A new JSON column is added to the table. External tables are read only. So if input table is an external table, then it cannot be used to store the output.
If the specified output table doesn't exist, then a new table is created. The new output table has key columns which contains the same primary key values as the input table and a JSON column that stores the generated text-based responses.
There must be no backticks used in the
DBName,TableName, orColumnNameand there must be no period used in theDBNameorTableName.
-
options: specifies optional parameters as key-value pairs in JSON format. It can include the following parameters:-
task: specifies the task expected from the large language model (LLM). Default value isgeneration. Possible values are:generation: generates text-based content.summarization: generates a summary for existing text-based content.
-
model_id: specifies the LLM to use for the task.As of MySQL 9.3.1, default value is
llama3.2-3b-instruct-v1. In earlier versions of MySQL, default value ismistral-7b-instruct-v1. Possible values are:As of MySQL 9.4.0, to use an OCI Generative AI service Dedicated AI Cluster model, specify the model endpoint OCID. For more information, see Creating an Endpoint in Generative AI.
-
The following MySQL HeatWave In-Database LLMs are available as of MySQL 9.3.1:
llama3.1-8b-instruct-v1llama3.2-1b-instruct-v1llama3.2-3b-instruct-v1mistral-7b-instruct-v3
-
The following OCI Generative AI Service LLMs are available as of MySQL 9.2.2:
meta.llama-3.2-90b-vision-instructmeta.llama-3.3-70b-instruct
-
The following OCI Generative AI Service LLMs are available as of MySQL 9.1.2:
cohere.command-r-plus-08-2024cohere.command-r-08-2024meta.llama-3.1-405b-instruct
-
The following MySQL HeatWave In-Database LLMs are available as of MySQL 9.0.0:
-
mistral-7b-instruct-v1As of MySQL 9.4.0, support for
mistral-7b-instruct-v1is deprecated. -
llama2-7b-v1As of MySQL 9.0.1-u1, support for
llama2-7b-v1is deprecated. -
llama3-8b-instruct-v1As of MySQL 9.4.0, support for
llama3-8b-instruct-v1has been deprecated.
-
To view the lists of available LLMs, see MySQL HeatWave In-Database LLMs and OCI Generative AI Service LLMs.
NoteThe
summarizationtask supports MySQL HeatWave In-Database LLMs only. context_column: specifies the table column that contains the context to be used for augmenting the queries and guiding the text generation of the LLM. The specified column must be an existing column in the input table. Default value isNULL.-
language: specifies the language to be used for writing queries, ingesting documents, and generating the output. To set the value of thelanguageparameter, use the two-letterISO 639-1code for the language.Default value is
en.For possible values, to view the list of supported languages, see Languages.
-
temperature: specifies a non-negative float that tunes the degree of randomness in generation. Lower temperatures mean less random generations.Default value is
0for all LLMs.Possible values are float values between:
0and5For the MySQL HeatWave In-Database LLMs.0and1for the Cohere OCI Generative AI Service LLMs.0and5for the Meta OCI Generative AI Service LLMs.
It is suggested that:
To generate the same output for a particular prompt every time you run it, set the temperature to
0.To generate a random new statement for a particular prompt every time you run it, increase the temperature.
-
max_tokens: specifies the maximum number of tokens to predict per generation using an estimate of three tokens per word. Default value is256. Possible values are:For Llama 3.1 and 3.2 LLMs, integer values between
1and128256.For Mistral V3 LLM, integer values between
1and32000.For Mistral V1 LLM, integer values between
1and8000.For Llama 2 and 3 LLMs, integer values between
1and4096.For OCI Generative AI Service LLMs, integer values between
1and4000.
top_k: specifies the number of top most likely tokens to consider for text generation at each step. Default value is40, which means that top 40 most likely tokens are considered for text generation at each step. Possible values are integer values between0and32000.-
top_p: specifies a number,p, and ensures that only the most likely tokens with the sum of probabilitiespare considered for generation at each step. A higher value ofpintroduces more randomness into the output. Default value is0.95. Possible values are float values between0and1.To disable this method, set to
1.0or0.To eliminate tokens with low likelihood, assign
pa lower value. For example, if set to0.1, tokens within top 10% probability are included.To include tokens with low likelihood, assign
pa higher value. For example, if set to0.9, tokens within top 90% probability are included.
If you are also specifying the
top_kparameter, the LLM considers only the top tokens whose probabilities add up toppercent. It ignores the rest of thektokens. -
repeat_penalty: assigns a penalty when a token appears repeatedly. High penalties encourage less repeated tokens and produce more random outputs. Default value is1.1. Possible values are float values between0and2.NoteThis parameter is supported for MySQL HeatWave In-Database LLMs only.
frequency_penalty: assigns a penalty when a token appears frequently. High penalties encourage less repeated tokens and produce more random outputs. Default value is0. Possible values are float values between0and1.-
presence_penalty: assigns a penalty to each token when it appears in the output to encourage generating outputs with tokens that haven't been used. This is similar tofrequency_penalty, except that this penalty is applied equally to all tokens that have already appeared, irrespective of their exact frequencies.NoteThis parameter is supported for OCI Generative AI Service LLMs only.
Default value is
0. Possible values are:For Cohere LLMs, float values between
0and1.For Meta LLMs, float values between
-2and2.
stop_sequences: specifies a list of characters such as a word, a phrase, a newline, or a period that tells the LLM when to end the generated output. If you have more than one stop sequence, then the LLM stops when it reaches any of those sequences. Default value isNULL.batch_size: specifies the batch size for the routine. This parameter is supported for internal tables only. Default value is1000. Possible values are integer values between1and1000.-
speculative_decoding: enables or disables speculative decoding when generating tokens with an LLM. If set totrue, speculative decoding enables faster response token generation, which speeds up LLM text generation. Speculative decoding is supported for thellama3.1-8b-instruct-v1LLM, which usesllama3.2-1B-instruct-v1as the draft LLM. Default value istrue.This parameter is available as of MySQL 9.3.2.
-
image_column: specifies the name of the column in the input table where the the base64 encoding of images are stored.The image column must exist in the same table as the
InputTableColumnand must containtextorvarcharvalues.The image column must not be a primary key, part of the primary key, and must be different from the input column used for providing text inputs. And, the image column must not have
NULLvalues or empty strings.The image column name must not contain back ticks (
`).
This parameter is available as of MySQL 9.4.1.
-
-
Generate English text-based content in a batch using the
mistral-7b-instruct-v3model for queries stored indemo_db.input_table:mysql> CALL sys.ML_GENERATE_TABLE("demo_db.input_table.Input", "demo_db.output_table.Output", JSON_OBJECT("task", "generation", "model_id", "mistral-7b-instruct-v3", "language", "en")); -
Generate text-based content in a batch pertaining to images stored in the
demo_db.input_table.Imagescolumn using queries stored in thedemo_db.input_table.Inputcolumn:mysql> CALL sys.ML_GENERATE_TABLE("demo_db.input_table.Input", "demo_db.output_table.Output", JSON_OBJECT("task", "generation", "model_id", "mistral-7b-instruct-v3", "language", "en", "image_column", "Images"));