MySQL HeatWave User Guide
The following sections in this topic describe how to generate new text-based content using MySQL HeatWave GenAI:
Review the MySQL HeatWave GenAI requirements and privileges.
If you want to use the OCI Generative AI Service LLMs, complete the steps to authenticate OCI Generative AI Service.
To Run Batch Queries, add the natural-language queries to a column in a new or existing table.
To generate text-based content using MySQL HeatWave GenAI, perform the following steps:
To define your natural-language query, set the
@query
variable:
mysql> SET @query="QueryInNaturalLanguage
";
Replace QueryInNaturalLanguage
with a natural-language query of your choice. For example:
mysql> SET @query="Write an article on Artificial intelligence in 200 words.";
To generate text-based content, pass the query to the LLM
using the
ML_GENERATE
routine with the task
parameter set to
generation
:
mysql> SELECT sys.ML_GENERATE(@query,
JSON_OBJECT("task", "generation", "model_id", "ModelID
", "language", "Language
"));
Replace the following:
ModelID
: LLM to use.
Language
: the two-letter
ISO 639-1
code for the language you
want to use. Default language is
en
, which is English. To view the
list of supported languages, see
Languages.
The language
parameter is supported
as of MySQL 9.0.1-u1.
For example:
mysql> SELECT sys.ML_GENERATE(@query,
JSON_OBJECT("task", "generation", "model_id", "mistral-7b-instruct-v3", "language", "en"));
Text-based content that is generated by the LLM in response to your query is printed as output. It looks similar to the text output shown below:
| {"text": "\nTitle: Artificial Intelligence in 2023: A New Era of Innovation\n\nArtificial Intelligence (AI) has been a transformative force, reshaping various sectors and revolutionizing our daily lives. In 2023, AI continues to evolve at an unprecedented pace, offering unparalleled opportunities for innovation and growth.\n\nOne significant development is the advancement of machine learning algorithms, enabling AI systems to learn from vast amounts of data more efficiently than ever before. This progress has led to improvements in areas such as image recognition, natural language processing, and predictive analytics, making AI more intuitive and user-friendly.\n\nAnother notable trend is the increasing integration of AI into everyday devices, from smartphones to home appliances. These advancements not only enhance convenience but also contribute to energy savings and improved safety features.\n\nIn the realm of healthcare, AI is playing a crucial role in diagnostics, drug discovery, and personalized treatment plans. By analyzing vast amounts of medical data, AI can help doctors make more accurate diagnoses and develop targeted therapies, ultimately improving patient outcomes.\n\nHowever, with great power comes great responsibility. As AI becomes more pervasive,"} |
To run multiple generation
queries in
parallel, use the
ML_GENERATE_TABLE
routine. This method is faster than running the
ML_GENERATE
routine multiple times.
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
.
The ML_GENERATE_TABLE
routine is supported
as of MySQL 9.0.1-u1.
To run the steps in this section, you can create a new
database demo_db
and table
input_table
:
mysql>CREATE DATABASE demo_db;
mysql>USE demo_db;
mysql>CREATE TABLE input_table (id INT AUTO_INCREMENT, Input TEXT, primary key (id));
mysql>INSERT INTO input_table (Input) VALUES('Describe what is MySQL in 50 words.');
mysql>INSERT INTO input_table (Input) VALUES('Describe Artificial Intelligence in 50 words.');
mysql>INSERT INTO input_table (Input) VALUES('Describe Machine Learning in 50 words.');
To run batch queries using
ML_GENERATE_TABLE
, perform the following
steps:
In the ML_GENERATE_TABLE
routine,
specify the table columns containing the input queries and
for storing the generated text-based responses:
mysql> CALL sys.ML_GENERATE_TABLE("InputDBName.InputTableName.InputColumn
", "OutputDBName.OutputTableName.OutputColumn
",
JSON_OBJECT("task", "generation", "model_id", "ModelID
", "language", "Language
"));
Replace the following:
InputDBName
: the name of
the database that contains the table column where your
input queries are stored.
InputTableName
: the name of
the table that contains the column where your input
queries are stored.
InputColumn
: the name of
the column that contains input queries.
OutputDBName
: the name of
the database that contains the table where you want to
store the generated outputs. This can be the same as
the input database.
OutputTableName
: the name
of the table where you want to create a new column to
store the generated outputs. This can be the same as
the input table. If the specified table doesn't exist,
a new table is created.
OutputColumn
: the name for
the new column where you want to store the output
generated for the input queries.
ModelID
: LLM to use.
Language
: the two-letter
ISO 639-1
code for the language you
want to use. Default language is
en
, which is English. To view the
list of supported languages, see
Languages.
For example:
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"));
View the contents of the output table:
mysql> SELECT * FROM output_table\G
*************************** 1. row ***************************
id: 1
Output: {"text": "\nMySQL is an open-source relational database
management system (RDBMS) that uses SQL (Structured Query
Language) to manage and manipulate data. It's widely used for
web-based applications, including those built with PHP, Python,
and Java. MySQL offers high performance, reliability, and
scalability, making it a popular choice for developers
worldwide.\n\n[DONE]", "error": null}
*************************** 2. row ***************************
id: 2
Output: {"text": "\nArtificial Intelligence (AI) refers to the
simulation of human intelligence in machines that are programmed
to think, learn, and make decisions like humans. AI can perform
tasks such as visual perception, speech recognition,
decision-making, and language translation. It's a rapidly
evolving field with applications in various sectors including
healthcare, finance, and entertainment.\n\n[END]",
"error": null}
*************************** 3. row ***************************
id: 3
Output: {"text": "\nMachine Learning is a method of data
analysis that automates the building of analytical models. It's
based on algorithms and statistical models that computer
systems use to perform tasks without being explicitly programmed,
learning from data instead.\n\n[END]", "error": null}
As of MySQL 9.3.0, the output table generated using the
ML_GENERATE_TABLE
routine contains an
additional details for error reporting. In case the
routine fails to generate output for specific rows,
details of the errors encountered and default values used
are added for the row in the output column.
If you created a new database for testing the steps in this section, ensure that you delete the database to avoid being billed for it:
mysql> DROP DATABASE demo_db;
To learn more about the available routine options, see ML_GENERATE_TABLE Syntax.
Learn how to Summarize Existing Content.