Within MindsDB, you can create projects to store your AI models, views, or jobs.

Working with PROJECTS

Creating PROJECTS

You can create projects to store your models, making the structure like this:

project_alpha
├─ models
├─ models_versions
├─ model_a
├─ model_b
project_beta
├─ models
├─ models_versions
├─ model_c

Here is how you create a project:

CREATE PROJECT project_alpha;

Use lower-case letters for a project name.

Viewing PROJECTS

There are two ways you can list all your projects:

  1. Use the SHOW DATABASES command:

    SHOW DATABASES WHERE type = 'project';
    

    On execution, we get:

    +----------------------+
    | Database             |
    +----------------------+
    | mindsdb              |
    | project_alpha        |
    | project_beta         |
    +----------------------+
    

    Please note that mindsdb is the default project.

  2. Use the SHOW FULL DATABASES command to get more details:

    SHOW FULL DATABASES WHERE type = 'project';
    

    On execution, we get:

    +----------------------+----------+-----------+
    | Database             | TYPE     | ENGINE    |
    +----------------------+----------+-----------+
    | mindsdb              | project  | [NULL]    |
    | project_alpha        | project  | [NULL]    |
    | project_beta         | project  | [NULL]    |
    +----------------------+----------+-----------+
    

    To view all connected data sources, specify type = 'data' in the WHERE clause.

Dropping PROJECTS

Here is how you can remove a project:

DROP PROJECT project_alpha;

On execution, we get:

Query OK, 0 rows affected (x.xxx sec)

Cannot Drop a Project

Please note that if your project stores at least one object, it cannot be removed. In this case, you should first drop all the jobs and tables, such as models and views, belonging to this project, and then, you can remove the project. Please see the Example section for details.

Working with MODELS

Creating MODELS

Here is how you create a model within the project:

CREATE MODEL project_alpha.model_a
FROM integration_name
    (SELECT * FROM table_name)
PREDICT target;

On execution, we get:

Query OK, 0 rows affected (x.xxx sec)

Viewing MODELS

To see all the models from all projects, run the command below.

SHOW MODELS;

On execution, we get:

+---------+--------------+--------+--------+---------+-------------+---------------+------+------------------------+--------------------+
|NAME     |PROJECT       |STATUS  |ACCURACY|PREDICT  |UPDATE_STATUS|MINDSDB_VERSION|ERROR |SELECT_DATA_QUERY       |TRAINING_OPTIONS    |
+---------+--------------+--------+--------+---------+-------------+---------------+------+------------------------+--------------------+
|model_a  |project_alpha |complete|0.999   |target   |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
|model_b  |project_alpha |complete|0.999   |target   |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
|model_c  |project_beta  |complete|0.999   |target   |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
+---------+--------------+--------+--------+---------+-------------+---------------+------+------------------------+--------------------+

And if you want to list all the models from a defined project, run either of the commands below.

SHOW MODELS 
FROM project_alpha;
-- or
SELECT * 
FROM project_alpha.models;

On execution, we get:

+---------+--------------+--------+--------+---------+-------------+---------------+------+------------------------+--------------------+
|NAME     |PROJECT       |STATUS  |ACCURACY|PREDICT  |UPDATE_STATUS|MINDSDB_VERSION|ERROR |SELECT_DATA_QUERY       |TRAINING_OPTIONS    |
+---------+--------------+--------+--------+---------+-------------+---------------+------+------------------------+--------------------+
|model_a  |project_alpha |complete|0.999   |target   |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
|model_b  |project_alpha |complete|0.999   |target   |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
+---------+--------------+--------+--------+---------+-------------+---------------+------+------------------------+--------------------+

Here is how to run a detailed search:

SHOW MODELS 
FROM project_alpha 
LIKE 'model_a' 
WHERE status='complete';

On execution, we get:

+---------+--------------+--------+--------+---------+-------------+---------------+------+------------------------+--------------------+
|NAME     |PROJECT       |STATUS  |ACCURACY|PREDICT  |UPDATE_STATUS|MINDSDB_VERSION|ERROR |SELECT_DATA_QUERY       |TRAINING_OPTIONS    |
+---------+--------------+--------+--------+---------+-------------+---------------+------+------------------------+--------------------+
|model_a  |project_alpha |complete|0.999   |target   |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
+---------+--------------+--------+--------+---------+-------------+---------------+------+------------------------+--------------------+

Dropping MODELS

To drop a model, run this command:

DROP MODEL project_alpha.model_a;

On execution, we get:

Query OK, 0 rows affected (x.xxx sec)

Working with MODELS_VERSION

There is a models_versions table for each project that stores all the versions of your models.

Here is how to query for all model versions from all the projects:

SELECT * 
FROM information_schema.models_versions;

On execution, we get:

+-------+-------------+------+-------+--------+--------+-------+-------------+---------------+------+------------------------+--------------------+
|NAME   |PROJECT      |ACTIVE|VERSION|STATUS  |ACCURACY|PREDICT|UPDATE_STATUS|MINDSDB_VERSION|ERROR |SELECT_DATA_QUERY       |TRAINING_OPTIONS    |
+-------+-------------+------+-------+--------+--------+-------+-------------+---------------+------+------------------------+--------------------+
|model_a|project_alpha|true  |1      |complete|0.999   |target |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
|model_b|project_alpha|true  |1      |complete|0.999   |target |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
|model_c|project_beta |true  |1      |complete|0.999   |target |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
+-------+-------------+------+-------+--------+--------+-------+-------------+---------------+------+------------------------+--------------------+

Example

If there is more training data available, you don’t need to recreate your model. Instead, use the RETRAIN command.

RETRAIN project_alpha.model_b;

After the retraining process completes, here is what you get:

SELECT * 
FROM information_schema.models_versions;

On execution, we get:

+-------+-------------+------+-------+--------+--------+-------+-------------+---------------+------+------------------------+--------------------+
|NAME   |PROJECT      |ACTIVE|VERSION|STATUS  |ACCURACY|PREDICT|UPDATE_STATUS|MINDSDB_VERSION|ERROR |SELECT_DATA_QUERY       |TRAINING_OPTIONS    |
+-------+-------------+------+-------+--------+--------+-------+-------------+---------------+------+------------------------+--------------------+
|model_a|project_alpha|true  |1      |complete|0.999   |target |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
|model_b|project_alpha|false |1      |complete|0.999   |target |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
|model_b|project_alpha|true  |2      |complete|0.999   |target |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
|model_c|project_beta |true  |1      |complete|0.999   |target |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
+-------+-------------+------+-------+--------+--------+-------+-------------+---------------+------+------------------------+--------------------+

Now, the model_b model has two records storing its two versions, out of which one is active.

You can also query for model versions of a project using this SELECT statement:

SELECT * FROM project_alpha.models_versions;

On execution, we get:

+-------+-------------+------+-------+--------+--------+-------+-------------+---------------+------+------------------------+--------------------+
|NAME   |PROJECT      |ACTIVE|VERSION|STATUS  |ACCURACY|PREDICT|UPDATE_STATUS|MINDSDB_VERSION|ERROR |SELECT_DATA_QUERY       |TRAINING_OPTIONS    |
+-------+-------------+------+-------+--------+--------+-------+-------------+---------------+------+------------------------+--------------------+
|model_a|project_alpha|true  |1      |complete|0.999   |target |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
|model_b|project_alpha|false |1      |complete|0.999   |target |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
|model_b|project_alpha|true  |2      |complete|0.999   |target |up_to_date   |22.10.2.1      |[NULL]|SELECT * FROM table_name|{'target': 'target'}|
+-------+-------------+------+-------+--------+--------+-------+-------------+---------------+------+------------------------+--------------------+

Working with TABLES

The models that you create with the CREATE MODEL command are simple tables within a project. Therefore, you can use the SHOW [FULL] TABLES commands to query for them.

Here is how to query for tables from all databases/projects/schemas:

SELECT table_schema, table_name, table_type
FROM information_schema.tables 
WHERE table_type IN ('BASE TABLE', 'MODEL');

On execution, we get:

+--------------+----------------+------------+
|table_schema  |table_name      |table_type
+--------------+----------------+------------+
|mindsdb       |models          |BASE TABLE  |
|mindsdb       |models_versions |BASE TABLE  |
|project_alpha |models          |BASE TABLE  |
|project_alpha |models_versions |BASE TABLE  |
|project_beta  |models          |BASE TABLE  |
|project_beta  |models_versions |BASE TABLE  |
|project_alpha |model_a         |MODEL       |
|project_alpha |model_b         |MODEL       |
|project_beta  |model_c         |MODEL       |
+--------------+----------------+------------+

Default Tables

Please note that each project contains four tables by default. These are the models, models_versions , jobs and jobs_history table.

There are also shortcut commands to query for the tables:

  1. Querying for tables from the default project:

    SHOW TABLES;
    

    On execution, we get:

    +---------------------+
    |Tables_in_mindsdb    |
    +---------------------+
    |models               |
    |models_versions      |
    +---------------------+
    

    Or, to get more details:

    SHOW FULL TABLES;
    

    On execution, we get:

    +---------------------+-----------+
    |Tables_in_mindsdb    |Table_type |
    +---------------------+-----------+
    |models               |BASE TABLE |
    |models_versions      |BASE TABLE |
    +---------------------+-----------+
    

    How to Set a Default Project

    The default project is set to mindsdb. If you want to change it, run the USE project_name; command.

  2. Querying for tables from a defined project:

    SHOW TABLES FROM project_alpha;
    

    On execution, we get:

    +-------------------------+
    |Tables_in_project_alpha  |
    +-------------------------+
    |models                   |
    |models_versions          |
    |model_a                  |
    |model_b                  |
    +-------------------------+
    

    Or, to get more details:

    SHOW FULL TABLES FROM project_alpha;
    

    On execution, we get:

    +-------------------------+-----------+
    |Tables_in_project_alpha  |Table_type |
    +-------------------------+-----------+
    |models                   |BASE TABLE |
    |models_versions          |BASE TABLE |
    |model_a                  |MODEL      |
    |model_b                  |MODEL      |
    +-------------------------+-----------+
    

Example

Let’s create a project.

CREATE PROJECT my_project;

To verify that the project was created successfully, let’s run the command below to select all databases, including connected data sources and projects.

SHOW FULL DATABASES;

On execution, we get:

+------------------+-------+------+
|Database          |TYPE   |ENGINE|
+------------------+-------+------+
|information_schema|system |[NULL]|
|mindsdb           |project|[NULL]|
|my_project        |project|[NULL]|
|files             |data   |files |
+------------------+-------+------+

Please note that information_schema is the system database, mindsdb is the default project, and files is the database to store all uploaded files. For more information, please visit our docs on MindsDB default structure.

Now we create a model within the project.

CREATE MODEL my_project.my_model
FROM example_db
    (SELECT * FROM demo_data.home_rentals)
PREDICT rental_price;

Also, let’s create a view.

CREATE VIEW my_project.my_view (
    SELECT * 
    FROM example_db.demo_data.home_rentals
);

Here is what we have in the my_project project.

SHOW TABLES FROM my_project;

On execution, we get:

+--------------------+
|Tables_in_my_project|
+--------------------+
|models              |
|models_versions     |
|my_model            |
|my_view             |
+--------------------+

Let’s try to delete our project.

DROP PROJECT my_project;

On execution, we get:

Project 'my_project' can not be deleted, because it contains tables: my_model, my_view

Users should remove all project content before dropping a project.

DROP MODEL my_project.my_model;
DROP VIEW my_project.my_view;

Now we can proceed to drop a project.

DROP PROJECT my_project;