Files
mindsdb--mindsdb/docs/mindsdb_sql/sql/create/ml-engine.mdx
2026-04-10 20:09:21 +03:00

132 lines
8.4 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: Configure an ML Engine
sidebarTitle: Configure an ML Engine
---
MindsDB integrates with numerous AI and ML frameworks that are made available via the AI/ML engines. The AI/ML engines are used to create models based on the particular AI/ML framework.
## Description
The `CREATE ML_ENGINE` command creates an ML engine that uses one of the available AI/ML handlers.
## Syntax
Before creating an AI/ML engine, make sure that the AI/ML handler of your interest is available by querying for the ML handlers.
```sql
SELECT *
FROM information_schema.handlers;
-- or
SHOW HANDLERS;
```
<Info>
If you cant find the AI/ML handler of your interest, you can contribute by [building a new AI/ML handler](/contribute/ml-handlers).
Please note that in the process of contributing new AI.ML engines, ML engines and/or their tests will only run correctly if all dependencies listed in the `requirements.txt` file are installed beforehand.
</Info>
If you find the AI/ML handler of your interest, then you can create an AI/ML engine using this command:
```sql
CREATE ML_ENGINE [IF NOT EXISTS] ml_engine_name
FROM handler_name
[USING argument_key = argument_value];
```
Please replace `ml_engine_name`, `handler_name`, and optionally, `argument_key` and `argument_value` with the real values.
<Note>
Please do not use the same `ml_engine_name` as the `handler_name` to avoid issue while dropping the ML engine.
</Note>
To verify that your AI/ML engine was successfully created, run the command below:
```sql
SELECT *
FROM information_schema.ml_engines;
-- or
SHOW ML_ENGINES;
```
If you want to drop an ML engine, run the command below:
```sql
DROP ML_ENGINE ml_engine_name;
```
## Example
Let's check what AI/ML handlers are currently available:
```sql
SHOW HANDLERS;
```
On execution, we get:
```sql
+-------------------+--------------------+-------------------------------------------------------+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------+----------------+-----------------------------------------------------------------------------+
| NAME | TITLE | DESCRIPTION | VERSION | CONNECTION_ARGS | IMPORT_SUCCESS | IMPORT_ERROR |
+-------------------+--------------------+-------------------------------------------------------+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------+----------------+-----------------------------------------------------------------------------+
| "ray_serve" | "RayServe" | "MindsDB handler for Ray Serve" | "0.0.1" | "[NULL]" | "true" | "[NULL]" |
| "autosklearn" | "Auto-Sklearn" | "MindsDB handler for Auto-Sklearn" | "0.0.2" | "[NULL]" | "false" | "No module named 'autosklearn'" |
| "mlflow" | "MLFlow" | "MindsDB handler for MLflow" | "0.0.2" | "[NULL]" | "false" | "No module named 'mlflow'" |
| "openai" | "OpenAI" | "MindsDB handler for OpenAI" | "0.0.1" | "[NULL]" | "true" | "[NULL]" |
| "merlion" | "Merlion" | "MindsDB handler for Merlion" | "0.0.1" | "[NULL]" | "false" | "object.__init__() takes exactly one argument (the instance to initialize)" |
| "byom" | "BYOM" | "MindsDB handler for BYOM" | "0.0.1" | "{'code': {'type': 'path', 'description': 'The path to model code'}, 'modules': {'type': 'path', 'description': 'The path to model requirements'}}" | "true" | "[NULL]" |
| "huggingface_api" | "Hugging Face API" | "MindsDB handler for Auto-Sklearn" | "0.0.2" | "[NULL]" | "false" | "No module named 'hugging_py_face'" |
| "huggingface" | "Hugging Face" | "MindsDB handler for Higging Face" | "0.0.1" | "[NULL]" | "true" | "[NULL]" |
| "TPOT" | "Tpot" | "MindsDB handler for TPOT " | "0.0.2" | "[NULL]" | "false" | "No module named 'tpot'" |
| "langchain" | "LangChain" | "MindsDB handler for LangChain" | "0.0.1" | "[NULL]" | "true" | "[NULL]" |
| "autokeras" | "Autokeras" | "MindsDB handler for Autokeras AutoML" | "0.0.1" | "[NULL]" | "false" | "No module named 'autokeras'" |
+-------------------+--------------------+-------------------------------------------------------+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------+----------------+-----------------------------------------------------------------------------+
```
Here we create an AI/ML engine using the OpenAI handler and providing an OpenAI API key in the `USING` clause.
```sql
CREATE ML_ENGINE my_openai_engine
FROM openai
USING
openai_api_key = '<your opanai api key>';
```
On execution, we get:
```sql
Query successfully completed
```
Now let's verify that our ML engine exists.
```sql
SHOW ML_ENGINES;
```
On execution, we get:
```sql
+-------------------+------------+------------------------------------------------------+
|NAME |HANDLER |CONNECTION_DATA |
+-------------------+------------+------------------------------------------------------+
|huggingface |huggingface |{"key":["password"],"value":[""]} |
|openai |openai |{"key":["password"],"value":[""]} |
|my_openai_engine |openai |{"key":["openai_api_key","password"],"value":["",""]} |
+-------------------+------------+------------------------------------------------------+
```
Please note that the `USING` clause is optional, as it depends on the AI/ML handler whether it requires some arguments or not. Here, we created an OpenAI engine and provided own API key.
After creating your ML engine, you can create a model like this:
```sql
CREATE MODEL my_model
PREDICT answer
USING
engine = 'my_openai_engine',
prompt_template = 'ask a question to a model'
```
The `USING` clause specifies the ML engine to be used for creating a new model.