MySQL AI User Guide
The following sections in this topic describe how to summarize exiting content using the GenAI:
Review the GenAI requirements and privileges.
For Running Batch Queries, add the natural-language queries to a column in a new or existing table.
To summarize text, perform the following steps:
To define the text that you want to summarize, set the
@text
variable:
mysql> SET @text="TextToSummarize
";
Replace TextToSummarize
with
the text that you want to summarize.
For example:
mysql> SET @text="Artificial Intelligence (AI) is a rapidly growing field that has the potential
to revolutionize how we live and work. AI refers to the development of computer systems
that can perform tasks that typically require human intelligence, such as visual perception,
speech recognition, decision-making, and language translation. One of the most significant
developments in AI in recent years has been the rise of machine learning, a subset of AI that
allows computers to learn from data without being explicitly programmed. Machine learning
algorithms can analyze vast amounts of data and identify patterns, making them increasingly
accurate at predicting outcomes and making decisions. AI is already being used in a variety
of industries, including healthcare, finance, and transportation. In healthcare, AI is being
used to develop personalized treatment plans for patients based on their medical history and
genetic makeup. In finance, AI is being used to detect fraud and make investment
recommendations In transportation, AI is being used to develop self-driving cars and improve
traffic flow. Despite the many benefits of AI, there are also concerns about its potential impact
on society. Some worry that AI could lead to job displacement, as machines become more capable
of performing tasks traditionally done by humans. Others worry that AI could be used for
malicious ";
To generate the text summary, pass the original text to
the LLM using the
ML_GENERATE
routine, with the task
parameter set to
summarization
:
mysql> SELECT sys.ML_GENERATE(@query,
JSON_OBJECT("task", "summarization", "model_id", "LLM
", "language", "Language
"));
Replace the following:
LLM
: LLM to use, which must
be the same as the one you loaded in the previous
step. To view the lists of available LLMs, see
In-Database LLM.
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> SELECT sys.ML_GENERATE(@text,
JSON_OBJECT("task", "summarization", "model_id", "llama3.2-3b-instruct-v1", "language", "en"));
A text summary generated by the LLM in response to your query is printed as output. It looks similar to the text output shown below:
| {"text": "\nHere is a concise summary of the text:\n\nArtificial Intelligence (AI) has the potential to revolutionize various aspects of life and work. AI systems can perform tasks that typically require human intelligence, such as visual perception, speech recognition, and decision-making. Machine learning, a subset of AI, enables computers to learn from data without explicit programming. AI is already being applied in healthcare, finance, and transportation, with applications including personalized treatment plans, fraud detection, and self-driving cars. However, there are concerns about the impact of AI on society, including job displacement and potential misuse for malicious purposes.", "license": "Your use of this llama model is subject to your Oracle agreements and this llama license agreement: https://downloads.mysql.com/docs/LLAMA_32_3B_INSTRUCT-license.pdf"} |
To run multiple summarization
queries in
parallel, use the
ML_GENERATE_TABLE
routine. This method is faster than running the
ML_GENERATE
routine multiple times.
To run the steps in this section, 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( CONCAT( 'MySQL is a widely used open-source relational database management system or RDBMS that ', 'is based on the SQL standard. It is designed to be highly scalable, reliable, and secure, ', 'making it an ideal choice for businesses of all sizes. MySQL uses a client-server ', 'architecture, where the server stores and manages the data, while clients connect to the ', 'server to access and manipulate the data. The MySQL server can be installed on a variety ', 'of operating systems, including Linux, Windows, and macOS. One of the key features of MySQL ', 'is its support for stored procedures, which allow developers to create reusable blocks of ', 'code that can be executed multiple times. This makes it easier to manage complex database ', 'operations and reduces the amount of code that needs to be written. MySQL also supports ', 'a wide range of data types, including integers, floating-point numbers, dates, and strings. ', 'It also has built-in support for encryption, which helps to protect sensitive data from ', 'unauthorized access. Another important feature of MySQL is its ability to handle large ', 'amounts of data. It can scale horizontally by adding more servers to the cluster, or ', 'vertically by upgrading the hardware.' ) );
mysql>INSERT INTO input_table (Input) VALUES( CONCAT( 'Artificial Intelligence or AI refers to the simulation of human intelligence in machines ', 'that are programmed to think and act like humans. The goal of AI is to create systems that ', 'can function intelligently and independently, exhibiting traits associated with human ', 'intelligence such as reasoning, problem-solving, perception, learning, and understanding ', 'language. There are two main types of AI: narrow or weak AI, and general or strong AI. ', 'Narrow AI is designed for a specific task and is limited in its abilities, while general ', 'AI has the capability to understand or learn any intellectual task that a human being can. ', 'AI technologies include machine learning, which allows systems to improve their performance ', 'based on data, and deep learning, which involves the use of neural networks to model complex ', 'patterns. Other AI techniques include natural language processing, robotics, and expert systems. ', 'AI has numerous applications across various industries, including healthcare, finance, ', 'transportation, and education. It has the potential to revolutionize the way we live and work ', 'by automating tasks, improving efficiency, and enabling new innovations. However, there are ', 'also concerns about the impact of AI on employment, privacy, and safety.' ) );
mysql>INSERT INTO input_table (Input) VALUES( CONCAT( 'Machine learning is a subset of artificial intelligence that involves the development of ', 'algorithms and statistical models that enable systems to improve their performance on a ', 'specific task over time by learning from data. At its core, machine learning is about ', 'using data to train machines to make predictions or decisions without being explicitly ', 'programmed to do so. There are many different types of machine learning, including ', 'supervised learning, unsupervised learning, and reinforcement learning. In supervised learning, ', 'the algorithm is trained on labeled data, meaning that the input data has been categorized or ', 'classified by a human. The goal of supervised learning is to enable the machine to make predictions ', 'based on this training data. Unsupervised learning, on the other hand, involves training the ', 'algorithm on unlabeled data. In this case, the algorithm must identify patterns and relationships ', 'in the data on its own. This type of learning is often used for tasks such as clustering or anomaly ', 'detection. Reinforcement learning involves an agent interacting with an environment and learning by ', 'trial and error. The agent receives feedback in the form of rewards or punishments, which it uses ', 'to improve its behavior over time. This type of learning is often used in game playing or robotics.' ) );
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 summaries:
mysql> CALL sys.ML_GENERATE_TABLE("InputDBName.InputTableName.InputColumn
", "OutputDBName.OutputTableName.OutputColumn
",
JSON_OBJECT("task", "summarization", "model_id", "LLM
", "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.
LLM
: LLM to use, which must
be the same as the LLM you loaded in the previous
step.
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", "summarization", "model_id", "llama3.2-3b-instruct-v1", "language", "en"));
View the contents of the output table:
mysql> SELECT * FROM output_table\G
*************************** 1. row ***************************
id: 1
Output: {"text": "\nHere is a concise summary:\n\nMySQL is an
open-source relational database management system (RDBMS) that
is widely used for its scalability, reliability, and security.
It uses a client-server architecture and supports various
operating systems. Key features include stored procedures for
efficient code reuse, support for multiple data types,
encryption for data protection, and the ability to handle large
amounts of data through horizontal or vertical scaling.",
"error": null,
"license": "Your use of this llama model is subject to
your Oracle agreements and this llama license agreement:
https://downloads.mysql.com/docs/LLAMA_32_3B_INSTRUCT-license.pdf"}
*************************** 2. row ***************************
id: 2
Output: {"text": "\nHere is a concise summary:\n\nArtificial
Intelligence (AI) refers to the simulation of human
intelligence in machines. There are two types: narrow AI
(limited to specific tasks) and general AI (capable of
understanding any intellectual task). AI technologies include
machine learning, deep learning, natural language processing,
robotics, and expert systems. With numerous applications
across industries, AI has the potential to revolutionize
various aspects of life, but also raises concerns about
employment, privacy, and safety.",
"error": null}
*************************** 3. row ***************************
id: 3
Output: {"text": "\nHere is a concise summary:\n\nMachine
learning is a subset of AI that enables systems to improve
their performance over time by learning from data. It involves
developing algorithms and statistical models to make predictions
or decisions without explicit programming. There are three main
types: supervised, unsupervised, and reinforcement learning.
Supervised learning uses labeled data for prediction, while
unsupervised learning identifies patterns in unlabeled data.
Reinforcement learning involves an agent interacting with its
environment, receiving feedback to improve behavior through trial
and error.",
"error": null}
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, delete the database to free up space:
mysql> DROP DATABASE demo_db;
To learn more about the available routine options, see ML_GENERATE_TABLE Syntax.
Learn how to Set Up a Vector Store.
Learn how to Generate Vector Embeddings.