Tutorial to Get Started with MindsDB
Before we start, install MindsDB locally or sign up for MindsDB Cloud.
Get started with MindsDB in a few simple steps:
Connect a data source
Explore all available data sources here.
Configure an AI engine
Explore all available AI engines here.
Create and deploy an AI model
MindsDB abstracts AI Models as AI Tables. This step uses the configured AI engine.
Query for predictions
Join the data table with the AI table to get predictions.
Step 1. Connect a data source
Use the CREATE DATABASE
statement to connect a data source to MindsDB.
This is the input data used in the following steps:
Here is the output:
Step 2. Configure an AI engine
Use the CREATE ML_ENGINE
command to configure an AI engine. Here we use the OpenAI engine.
Step 3. Create and deploy an AI model
Use the CREATE MODEL
statement to create, train, and deploy an AI model based on the AI engine created in step 2.
This model expects {{question}}
and {{article_title}}
as input, and generates answer
as output.
Step 4. Query for predictions
Query for predictions by joining the AI Table (from step 3) with the data table (from step 1).
Here is the output data:
Step 5. Automate customized workflows
With MindsDB, you can create custom automation workflows. Let’s set up a workflow that uses Jobs and (re)creates a table with predicted answers to all questions.
CREATE JOB answer_questions (
CREATE OR REPLACE TABLE data_source.questions_answers ( SELECT input.article_title, input.question, output.answer FROM mysql_demo_db.questions AS input JOIN question_answering_model AS output ) ) EVERY 1 day;
The data_source
connection should be made using the CREATE DATABASE
statement to a data source with a user that has the write access.
This job creates the questions_answers
table inside the connected data source. This table is filled with questions from the input data table and answers generated by the AI table. Considering that new questions are added daily to the input data table, this job executes once a day.
Alternatively, you could use the LAST
keyword to fetch only the newly added questions to the input data table. That would enable you to insert new question-answer pairs into the questions_answers
table instead of recreating it. But to do that, the input data table must provide either a date/time or integer/float column that would be used in the condition like datetime > LAST
. Learn more about the LAST
keyword here.
Next Steps
Follow the links below to explore MindsDB.