Generative AI Tables
MindsDB empowers organizations to harness the power of AI by abstracting AI models as Generative AI Tables. These tables are capable of learning from the input data and generating predictions from the underlying model upon being queried. This abstraction makes AI highly accessible, enabling development teams to use their existing SQL skills to build applications powered by AI.
What are Generative AI Tables?
Generative AI is a subfield of artificial intelligence that trains AI models to create new content, such as realistic text, forecasts, images, and more, by learning patterns from existing data.
MindsDB revolutionizes machine learning within enterprise databases by introducing the concept of Generative AI tables. These essentially abstract AI models as virtual AI tables, capable of producing output when given certain input.
Working with Generative AI Tables
AI tables, introduced by MindsDB, abstract AI models as virtual tables so you can simply query AI models for predictions.
With MinsdDB, you can join multiple AI tables (that abstract AI models) with multiple data tables (that provide input to the models) to get all predictions at once.
Let’s look at some examples.
Deploying AI Models as AI Tables
You can deploy an AI model as a virtual AI table using the CREATE MODEL
statement.
Here we create a model that classifies sentiment of customer reviews as instructed in the prompt template message. The required input is the review and output is the sentiment predicted by the model.
Next we create a model that generates responses to the reviews. The required input includes review, product name, and sold product quantity, and output is the response generated by the model.
Follow this doc page to configure the OpenAI engine in MindsDB.
Now let’s look at the data tables that we’ll use to provide input data to the AI tables.
Preparing Input Data
The amazon_reviews
table stores the following columns:
It provides sufficient input data for the sentiment_classifier_model
, but not for the response_generator_model
.
The products_sold
table stores the following columns:
The reponse_generator_model
requires the two tables to be joined to provide it with sufficient input data.
Making Predictions
You can query the AI tables directly or join AI tables with data tables to get the predictions.
There are two ways you can provide input to the models:
-
If you query the AI table directly, you can provide input data in the
WHERE
clause, like this: -
You can provide input data to AI tables from the joined data tables, like this:
The
sentiment_classifier_model
requires a parameter namedreview
, so the data table should contain a column namedreview
, which is picked up by the model.Note that, when joining data tables, you must provide the
ON
clause condition, which is implemented implicitly when joining the AI tables.
Moreover, you can combine these two options and provide the input data to the AI tables partially from the data tables and partially from the WHERE
clause, like this:
Here the sentiment_classifier_model
takes input data from the amazon_review
table, while the response_generator_model
takes input data from the amazon_reviews
table and from the WHERE
clause.
Furthermore, you can make use of subqueries to provide input data to the models via the WHERE
clause, like this:
Difference between AI Tables and Standard Tables
To understand the difference, let’s go over a simpler example. Here we will see how traditional database tables are designed to give you a deterministic response given some input, and how Generative AI Tables are designed to generate an approximate response given some input.
Let’s consider the following income_table
table that stores the income
and debt
values.
On execution, we get:
A simple visualization of the data present in the income_table
table is as follows:
Querying the income table to get the debt
value for a particular income
value results in the following:
On execution, we get:
And here is what we get:
But what happens when querying the table for an income
value that is not
present there?
On execution, we get:
When the WHERE
clause condition is not fulfilled for any of the rows, no value is returned.
When a table doesn’t have an exact match, the query returns an empty set or null value. This is where the AI Tables come into play!
Let’s create a debt_model
model that allows us to approximate the debt
value for any income
value. We train the debt_model
model using the data from the income_table
table.
On execution, we get:
MindsDB provides the CREATE MODEL
statement. On execution of this statement, the predictive model works in the background, automatically creating a vector representation of the data that can be visualized as follows:
Let’s now look for the debt
value of some random income
value. To get the approximated debt
value, we query the mindsdb.debt_model
model instead of the income_table
table.
On execution, we get:
And here is how it looks: