# Table of Contents - [Build an Application Handler - MindsDB](#build-an-application-handler-mindsdb) - [Join our Community - MindsDB](#join-our-community-mindsdb) - [How to Contribute to MindsDB - MindsDB](#how-to-contribute-to-mindsdb-mindsdb) - [Build a Database Handler - MindsDB](#build-a-database-handler-mindsdb) - [How to Write MindsDB Documentation - MindsDB](#how-to-write-mindsdb-documentation-mindsdb) - [MindsDB Installation for Development - MindsDB](#mindsdb-installation-for-development-mindsdb) - [How to Write Handlers README - MindsDB](#how-to-write-handlers-readme-mindsdb) - [Python Coding Standards - MindsDB](#python-coding-standards-mindsdb) - [Data Catalog for Integrations - MindsDB](#data-catalog-for-integrations-mindsdb) - [Querying Data Catalog for Integrations - MindsDB](#querying-data-catalog-for-integrations-mindsdb) - [Data Catalog - MindsDB](#data-catalog-mindsdb) - [Benefits of MindsDB - MindsDB](#benefits-of-mindsdb-mindsdb) - [Disposable Email Domains and OpenAI - MindsDB](#disposable-email-domains-and-openai-mindsdb) - [How to Interact with MindsDB from PHP - MindsDB](#how-to-interact-with-mindsdb-from-php-mindsdb) - [Missing required CPU features - MindsDB](#missing-required-cpu-features-mindsdb) - [How to Persist Predictions - MindsDB](#how-to-persist-predictions-mindsdb) - [Bring Your Own Model - MindsDB](#bring-your-own-model-mindsdb) - [MindsDB and MLflow - MindsDB](#mindsdb-and-mlflow-mindsdb) - [Binance - MindsDB](#binance-mindsdb) - [Confluence - MindsDB](#confluence-mindsdb) - [Page Not Found](#page-not-found) - [Page Not Found](#page-not-found) - [Page Not Found](#page-not-found) - [MindsDB at AWS Marketplace - MindsDB](#mindsdb-at-aws-marketplace-mindsdb) - [Data Insights - MindsDB](#data-insights-mindsdb) - [Forecast Quarterly House Sales with MindsDB - MindsDB](#forecast-quarterly-house-sales-with-mindsdb-mindsdb) - [Setup for Source Code via pip - MindsDB](#setup-for-source-code-via-pip-mindsdb) - [Chatbot - MindsDB](#chatbot-mindsdb) - [Build a Chatbot with a Text2SQL Skill - MindsDB](#build-a-chatbot-with-a-text2sql-skill-mindsdb) - [MongoDB - MindsDB](#mongodb-mindsdb) - [Configure an ML Engine - MindsDB](#configure-an-ml-engine-mindsdb) - [Building a Twitter Chatbot with MindsDB and OpenAI - MindsDB](#building-a-twitter-chatbot-with-mindsdb-and-openai-mindsdb) - [Build an AI Agent with MindsDB - MindsDB](#build-an-ai-agent-with-mindsdb-mindsdb) - [Get a Single Prediction - MindsDB](#get-a-single-prediction-mindsdb) - [Setup for Linux via pip - MindsDB](#setup-for-linux-via-pip-mindsdb) - [Get Batch Predictions - MindsDB](#get-batch-predictions-mindsdb) - [Setup for MacOS via pip - MindsDB](#setup-for-macos-via-pip-mindsdb) - [Text Summarization with MindsDB and OpenAI using SQL - MindsDB](#text-summarization-with-mindsdb-and-openai-using-sql-mindsdb) - [Create, Train, and Deploy a Model - MindsDB](#create-train-and-deploy-a-model-mindsdb) - [AI Integrations - MindsDB](#ai-integrations-mindsdb) - [Setup for Windows via pip - MindsDB](#setup-for-windows-via-pip-mindsdb) - [Page Not Found](#page-not-found) - [Page Not Found](#page-not-found) - [Predict Home Rental Prices with MindsDB - MindsDB](#predict-home-rental-prices-with-mindsdb-mindsdb) - [Create an Agent - MindsDB](#create-an-agent-mindsdb) - [Page Not Found](#page-not-found) - [Page Not Found](#page-not-found) - [Page Not Found](#page-not-found) - [Generative AI Tables - MindsDB](#generative-ai-tables-mindsdb) - [Build an AI/ML Handler - MindsDB](#build-an-ai-ml-handler-mindsdb) - [OpenAI - MindsDB](#openai-mindsdb) - [LangChain - MindsDB](#langchain-mindsdb) - [Anthropic - MindsDB](#anthropic-mindsdb) - [Cohere - MindsDB](#cohere-mindsdb) - [Ollama - MindsDB](#ollama-mindsdb) - [Join Models with Tables - MindsDB](#join-models-with-tables-mindsdb) - [Model Management - MindsDB](#model-management-mindsdb) - [Google Gemini - MindsDB](#google-gemini-mindsdb) - [Vertex AI - MindsDB](#vertex-ai-mindsdb) - [Hugging Face Inference API - MindsDB](#hugging-face-inference-api-mindsdb) - [Hugging Face - MindsDB](#hugging-face-mindsdb) - [Predict Customer Churn with MindsDB - MindsDB](#predict-customer-churn-with-mindsdb-mindsdb) - [Finetune a Model - MindsDB](#finetune-a-model-mindsdb) - [Sentiment Analysis with MindsDB and OpenAI using SQL - MindsDB](#sentiment-analysis-with-mindsdb-and-openai-using-sql-mindsdb) - [Retrain a Model - MindsDB](#retrain-a-model-mindsdb) - [Usage Examples of Hugging Face Models Through Inference API - MindsDB](#usage-examples-of-hugging-face-models-through-inference-api-mindsdb) - [Page Not Found](#page-not-found) - [AI Workflow Automation - MindsDB](#ai-workflow-automation-mindsdb) - [SDKs - MindsDB](#sdks-mindsdb) - [Page Not Found](#page-not-found) - [Fine-Tune the OpenAI Model - MindsDB](#fine-tune-the-openai-model-mindsdb) - [Automated Fine-Tuning - MindsDB](#automated-fine-tuning-mindsdb) - [Create, Train, and Deploy a Model - MindsDB](#create-train-and-deploy-a-model-mindsdb) - [Create, Train, and Deploy a Model - MindsDB](#create-train-and-deploy-a-model-mindsdb) - [Create a Job - MindsDB](#create-a-job-mindsdb) - [Configure an ML Engine - MindsDB](#configure-an-ml-engine-mindsdb) - [Fine-Tune the Classification Model - MindsDB](#fine-tune-the-classification-model-mindsdb) - [Automate Real-Time Trading Data Forecasts - MindsDB](#automate-real-time-trading-data-forecasts-mindsdb) - [Fine-Tune the Regression Model - MindsDB](#fine-tune-the-regression-model-mindsdb) - [Get Batch Predictions - MindsDB](#get-batch-predictions-mindsdb) - [Build a Twilio Chatbot with MindsDB and OpenAI - MindsDB](#build-a-twilio-chatbot-with-mindsdb-and-openai-mindsdb) - [Automate notifications about incoming customer reviews - MindsDB](#automate-notifications-about-incoming-customer-reviews-mindsdb) - [Manage Model Versions - MindsDB](#manage-model-versions-mindsdb) - [Build a Slack Chatbot with MindsDB and OpenAI - MindsDB](#build-a-slack-chatbot-with-mindsdb-and-openai-mindsdb) - [Configure an ML Engine - MindsDB](#configure-an-ml-engine-mindsdb) - [Get Batch Predictions - MindsDB](#get-batch-predictions-mindsdb) - [Page Not Found](#page-not-found) --- # Build an Application Handler - MindsDB [Skip to main content](https://docs.mindsdb.com/contribute/app-handlers#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Contribute Build an Application Handler [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [What are API Handlers?](https://docs.mindsdb.com/contribute/app-handlers#what-are-api-handlers) * [Creating an Application Handler](https://docs.mindsdb.com/contribute/app-handlers#creating-an-application-handler) * [Core Methods](https://docs.mindsdb.com/contribute/app-handlers#core-methods) * [API Table](https://docs.mindsdb.com/contribute/app-handlers#api-table) * [Implementation](https://docs.mindsdb.com/contribute/app-handlers#implementation) * [Exporting the connection\_args Dictionary](https://docs.mindsdb.com/contribute/app-handlers#exporting-the-connection-args-dictionary) * [Exporting All Required Variables](https://docs.mindsdb.com/contribute/app-handlers#exporting-all-required-variables) * [Check out our Application Handlers!](https://docs.mindsdb.com/contribute/app-handlers#check-out-our-application-handlers) In this section, you’ll find how to add new application integrations to MindsDB. **Prerequisite**You should have the latest version of the MindsDB repository installed locally. Follow [this guide](https://docs.mindsdb.com/contribute/install) to learn how to install MindsDB for development. [​](https://docs.mindsdb.com/contribute/app-handlers#what-are-api-handlers) What are API Handlers? ----------------------------------------------------------------------------------------------------- Application handlers act as a bridge between MindsDB and any application that provides APIs. You use application handlers to create databases using the [`CREATE DATABASE`](https://docs.mindsdb.com/sql/create/databases) statement. So you can reach data from any application that has its handler implemented within MindsDB. **Database Handlers**To learn more about handlers and how to implement a database handler, visit our [doc page here](https://docs.mindsdb.com/contribute/data-handlers) . [​](https://docs.mindsdb.com/contribute/app-handlers#creating-an-application-handler) Creating an Application Handler ------------------------------------------------------------------------------------------------------------------------ You can create your own application handler within MindsDB by inheriting from the [`APIHandler`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/api_handler.py#L150) class. By providing the implementation for some or all of the methods contained in the [`APIHandler`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/api_handler.py#L150) class, you can interact with the application APIs. ### [​](https://docs.mindsdb.com/contribute/app-handlers#core-methods) Core Methods Apart from the `__init__()` method, there are five core methods that must be implemented. We recommend checking actual examples in the codebase to get an idea of what goes into each of these methods, as they can change a bit depending on the nature of the system being integrated. Let’s review the purpose of each method. | Method | Purpose | | --- | --- | | [`_register_table()`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/api_handler.py#L164) | It registers the data resource in memory. For example, if you are using Twitter API it registers the `tweets` resource from `/api/v2/tweets`. | | [`connect()`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/base.py#L23) | It performs the necessary steps to connect/authenticate to the underlying system. | | [`check_connection()`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/base.py#L39) | It evaluates if the connection is alive and healthy. | | [`native_query()`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/base.py#L47) | It parses any _native_ statement string and acts upon it (for example, raw syntax commands). | | `call_application_api()` | It calls the application API and maps the data to pandas DataFrame. This method handles the pagination and data mapping. | Authors can opt for adding private methods, new files and folders, or any combination of these to structure all the necessary work that will enable the core methods to work as intended. **Other Common Methods**Under the [`mindsdb.integrations.utilities`](https://docs.mindsdb.com/contribute/main/mindsdb/integrations/utilities) library, contributors can find various methods that may be useful while implementing new handlers. ### [​](https://docs.mindsdb.com/contribute/app-handlers#api-table) API Table Once the data returned from the API call is registered using the [`_register_table()`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/api_handler.py#L164) method, you can use it to map to the [`APITable`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/api_handler.py#L93) class. The [`APITable`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/api_handler.py#L93) class provides CRUD methods. | Method | Purpose | | | --- | --- | --- | | `select()` | It implements the mappings from the ast.Select and calls the actual API through the `call_application_api`. | | | `insert()` | It implements the mappings from the ast.Insert and calls the actual API through the `call_application_api`. | | | `update()` | It implements the mappings from the ast.Update and calls the actual API through the `call_application_api`. | | | `delete()` | It implements the mappings from the ast.Delete and calls the actual API through the `call_application_api`. | | | `add()` | Adds new rows to the data dictionary. | | | `list()` | List data based on certain conditions by providing FilterCondition, limits, sorting and target fields. | | | `get_columns()` | It maps the data columns returned by the API. | | ### [​](https://docs.mindsdb.com/contribute/app-handlers#implementation) Implementation Each application handler should inherit from the [`APIHandler`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/api_handler.py#L150) class. Here is a step-by-step guide: * Implementing the [`__init__()`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/api_handler.py#L155) method: This method initializes the handler. Copy Ask AI def __init__(self, name: str): super().__init__(name) """ constructor Args: name (str): the handler name """ self._tables = {} * Implementing the [`connect()`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/base.py#L23) method: The `connect()` method sets up the connection. Copy Ask AI def connect(self) -> HandlerStatusResponse: """ Set up any connections required by the handler Should return output of check_connection() method after attempting connection. Should switch self.is_connected. Returns: HandlerStatusResponse """ * Implementing the [`check_connection()`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/base.py#L39) method: The `check_connection()` method performs the health check for the connection. Copy Ask AI def check_connection(self) -> HandlerStatusResponse: """ Check connection to the handler Returns: HandlerStatusResponse """ * Implementing the [`native_query()`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/base.py#L47) method: The `native_query()` method runs commands of the native API syntax. Copy Ask AI def native_query(self, query: Any) -> HandlerResponse: """Receive raw query and act upon it somehow. Args: query (Any): query in native format (str for sql databases, api's json etc) Returns: HandlerResponse """ * Implementing the `call_application_api()` method: This method makes the API calls. It is **not mandatory** to implement this method, but it can help make the code more reliable and readable. Copy Ask AI def call_application_api(self, method_name:str = None, params:dict = None) -> DataFrame: """Receive query as AST (abstract syntax tree) and act upon it somehow. Args: query (ASTNode): sql query represented as AST. Can be any kind of query: SELECT, INSERT, DELETE, etc Returns: DataFrame """ ### [​](https://docs.mindsdb.com/contribute/app-handlers#exporting-the-connection-args-dictionary) Exporting the `connection_args` Dictionary The `connection_args` dictionary contains all of the arguments used to establish the connection along with their descriptions, types, labels, and whether they are required or not. The `connection_args` dictionary should be stored in the `connection_args.py` file inside the handler folder. The `connection_args` dictionary is stored in a separate file in order to be able to hide sensitive information such as passwords or API keys.By default, when querying for `connection_data` from the `information_schema.databases` table, all sensitive information is hidden. To unhide it, use this command: Copy Ask AI set show_secrets=true; Here is an example of the `connection_args.py` file from the [GitHub handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/github_handler) where the API key value is set to hidden with `"secret": True`. Copy Ask AI from collections import OrderedDict from mindsdb.integrations.libs.const import HANDLER_CONNECTION_ARG_TYPE as ARG_TYPE connection_args = OrderedDict( repository={ "type": ARG_TYPE.STR, "description": " GitHub repository name.", "required": True, "label": "Repository", }, api_key={ "type": ARG_TYPE.PWD, "description": "Optional GitHub API key to use for authentication.", "required": False, "label": "Api key", "secret": True }, github_url={ "type": ARG_TYPE.STR, "description": "Optional GitHub URL to connect to a GitHub Enterprise instance.", "required": False, "label": "Github url", }, ) connection_args_example = OrderedDict( repository="mindsdb/mindsdb", api_key="ghp_xxx", github_url="https://github.com/mindsdb/mindsdb" ) ### [​](https://docs.mindsdb.com/contribute/app-handlers#exporting-all-required-variables) Exporting All Required Variables The following should be exported in the `__init__.py` file of the handler: * The `Handler` class. * The `version` of the handler. * The `name` of the handler. * The `type` of the handler, either `DATA` handler or `ML` handler. * The `icon_path` to the file with the database icon. * The `title` of the handler or a short description. * The `description` of the handler. * The `connection_args` dictionary with the connection arguments. * The `connection_args_example` dictionary with an example of the connection arguments. * The `import_error` message that is used if the import of the `Handler` class fails. A few of these variables are defined in another file called `__about__.py`. This file is imported into the `__init__.py` file. Here is an example of the `__init__.py` file for the [GitHub handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/github_handler) . Copy Ask AI from mindsdb.integrations.libs.const import HANDLER_TYPE from .__about__ import __version__ as version, __description__ as description from .connection_args import connection_args, connection_args_example try: from .github_handler import ( GithubHandler as Handler, connection_args_example, connection_args, ) import_error = None except Exception as e: Handler = None import_error = e title = "GitHub" name = "github" type = HANDLER_TYPE.DATA icon_path = "icon.svg" __all__ = [\ "Handler", "version", "name", "type", "title", "description",\ "import_error", "icon_path", "connection_args_example", "connection_args",\ ] The `__about__.py` file for the same [GitHub handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/github_handler) contains the following variables: Copy Ask AI __title__ = "MindsDB GitHub handler" __package_name__ = "mindsdb_github_handler" __version__ = "0.0.1" __description__ = "MindsDB handler for GitHub" __author__ = "Artem Veremey" __github__ = "https://github.com/mindsdb/mindsdb" __pypi__ = "https://pypi.org/project/mindsdb/" __license__ = "MIT" __copyright__ = "Copyright 2023 - mindsdb" [​](https://docs.mindsdb.com/contribute/app-handlers#check-out-our-application-handlers) Check out our Application Handlers! ------------------------------------------------------------------------------------------------------------------------------- To see some integration handlers that are currently in use, we encourage you to check out the following handlers inside the MindsDB repository: * [GitHub handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/github_handler) * [TwitterHandler](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/handlers/twitter_handler) And here are [all the handlers available in the MindsDB repository](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers) . Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/contribute/app-handlers.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/contribute/app-handlers) [Build a Database Handler](https://docs.mindsdb.com/contribute/data-handlers) [Write Handlers README](https://docs.mindsdb.com/contribute/integrations-readme) ⌘I --- # Join our Community - MindsDB [Skip to main content](https://docs.mindsdb.com/contribute/community#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Contribute Join our Community [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [MindsDB Newsletter](https://docs.mindsdb.com/contribute/community#mindsdb-newsletter) * [Contact Us](https://docs.mindsdb.com/contribute/community#contact-us) If you have questions or you want to chat with the MindsDB core team or other community members, you can join our [Slack workspace](https://mindsdb.com/joincommunity) [​](https://docs.mindsdb.com/contribute/community#mindsdb-newsletter) MindsDB Newsletter ------------------------------------------------------------------------------------------- To get updates on MindsDB’s latest announcements, releases, and events, [sign up for our newsletter](https://mindsdb.com/newsletter/) . [​](https://docs.mindsdb.com/contribute/community#contact-us) Contact Us --------------------------------------------------------------------------- If you are interested in MindsDB for large-scale projects, contact us by submitting [this form](https://mindsdb.com/contact-us/) . Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/contribute/community.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/contribute/community) [Write Documentation](https://docs.mindsdb.com/contribute/docs) ⌘I --- # How to Contribute to MindsDB - MindsDB [Skip to main content](https://docs.mindsdb.com/contribute/contribute#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Contribute How to Contribute to MindsDB [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [MindsDB Release Process](https://docs.mindsdb.com/contribute/contribute#mindsdb-release-process) * [Contributor Testing Requirements](https://docs.mindsdb.com/contribute/contribute#contributor-testing-requirements) * [Feature Branch Testing](https://docs.mindsdb.com/contribute/contribute#feature-branch-testing) * [Post-Release Testing](https://docs.mindsdb.com/contribute/contribute#post-release-testing) Thank you for your interest in contributing to MindsDB. MindsDB is free, open-source software and all types of contributions are welcome, whether they’re documentation changes, bug reports, bug fixes, or new source code changes. In order to contribute to MindsDB: * fork the MindsDB GitHub repository, * [install MindsDB locally](https://docs.mindsdb.com/contribute/install) , * implement and test your changes, * **push your changes to the `develop` branch**. Step-by-Step Guide 1. Fork the MindsDB repository from [MindsDB GitHub](https://github.com/mindsdb/mindsdb) . 2. Clone the MindsDB repository locally from your fork and go inside the repository folder. Copy Ask AI cd /path/mindsdb-repo-folder-name 3. Fetch all other branches from the MindsDB repository with these commands: Copy Ask AI git remote add upstream https://github.com/mindsdb/mindsdb git fetch upstream 4. Switch to the `develop` branch. Copy Ask AI git checkout develop 5. Create a new branch for your changes from the `develop` branch. Copy Ask AI git checkout -b new-branch-name 6. Make your changes on this branch. 7. Commit and push your changes to GitHub. Copy Ask AI git add * git commit -m "commit message" git push --set-upstream origin new-branch-name 8. Go to GitHub and create a PR to the `develop` branch of the MindsDB repository. ![](https://mintcdn.com/mindsdb/D7vB6Tj7fdk1mEwb/assets/contribute.png?w=2500&fit=max&auto=format&n=D7vB6Tj7fdk1mEwb&q=85&s=e83a34c7419944dee31e7a20ac23005a) [​](https://docs.mindsdb.com/contribute/contribute#mindsdb-release-process) MindsDB Release Process ------------------------------------------------------------------------------------------------------ The `main` branch of the [MindsDB repository](https://github.com/mindsdb/mindsdb) contains the latest stable version of MindsDB and represents the GA (General Availability) release. Learn more about [MindsDB release types here](https://docs.mindsdb.com/releases) . MindsDB follows the [Gitflow branching model](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow) to manage development and releases as follows. 1 Development Phase All code changes are first committed to the `develop` branch. 2 Release Preparation When a release is approaching, a short-lived `release` branch is created from the `develop` branch. * This branch is used for final testing and validation. * Pre-GA artifacts are built at this stage, including both the Python package and the Docker image, and shared for broader testing and feedback. 3 Release Finalization After successful testing and validation: * The `release` branch is merged into the `main` branch, making it an official GA release. * The final GA versions of the Python package and Docker image are released, while the pre-GA version are removed. [​](https://docs.mindsdb.com/contribute/contribute#contributor-testing-requirements) Contributor Testing Requirements ------------------------------------------------------------------------------------------------------------------------ As a contributor, you are responsible for writing the code according to the [Python Coding Standards](https://docs.mindsdb.com/contribute/python-coding-standards) and thoroughly testing all features or fixes that you implement before they are merged into the `develop` branch. ### [​](https://docs.mindsdb.com/contribute/contribute#feature-branch-testing) Feature Branch Testing Before merging your changes, the following types of testing must be completed to validate your work in isolation: * Unit Tests Verify that individual components or functions behave as expected during development. * Integration Tests Ensure that your new code works correctly with existing functionality and doesn’t introduce regressions. ### [​](https://docs.mindsdb.com/contribute/contribute#post-release-testing) Post-Release Testing After a release that includes your features or fixes is published, contributors are encouraged to: * Test their changes in the released environment, and * Report any issues or unexpected behavior that may arise. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/contribute/contribute.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/contribute/contribute) [Installation for Development](https://docs.mindsdb.com/contribute/install) ⌘I --- # Build a Database Handler - MindsDB [Skip to main content](https://docs.mindsdb.com/contribute/data-handlers#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Contribute Build a Database Handler [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [What are Database Handlers?](https://docs.mindsdb.com/contribute/data-handlers#what-are-database-handlers) * [Creating a Database Handler](https://docs.mindsdb.com/contribute/data-handlers#creating-a-database-handler) * [Core Methods](https://docs.mindsdb.com/contribute/data-handlers#core-methods) * [Implementation](https://docs.mindsdb.com/contribute/data-handlers#implementation) * [Exporting the connection\_args Dictionary](https://docs.mindsdb.com/contribute/data-handlers#exporting-the-connection-args-dictionary) * [Exporting All Required Variables](https://docs.mindsdb.com/contribute/data-handlers#exporting-all-required-variables) * [Exporting Requirements](https://docs.mindsdb.com/contribute/data-handlers#exporting-requirements) * [Check out our Database Handlers!](https://docs.mindsdb.com/contribute/data-handlers#check-out-our-database-handlers) In this section, you’ll find how to add new integrations/databases to MindsDB. **Prerequisite**You should have the latest version of the MindsDB repository installed locally. Follow [this guide](https://docs.mindsdb.com/contribute/install) to learn how to install MindsDB for development. [​](https://docs.mindsdb.com/contribute/data-handlers#what-are-database-handlers) What are Database Handlers? ---------------------------------------------------------------------------------------------------------------- Database handlers act as a bridge to any database. You use database handlers to create databases using [the CREATE DATABASE command](https://docs.mindsdb.com/sql/create/databases) . So you can reach data from any database that has its handler implemented within MindsDB. [​](https://docs.mindsdb.com/contribute/data-handlers#creating-a-database-handler) Creating a Database Handler ----------------------------------------------------------------------------------------------------------------- You can create your own database handler within MindsDB by inheriting from the [`DatabaseHandler`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/base.py#L102) class. By providing the implementation for some or all of the methods contained in the `DatabaseHandler` class, you can connect with the database of your choice. ### [​](https://docs.mindsdb.com/contribute/data-handlers#core-methods) Core Methods Apart from the `__init__()` method, there are seven core methods that must be implemented. We recommend checking actual examples in the codebase to get an idea of what goes into each of these methods, as they can change a bit depending on the nature of the system being integrated. Let’s review the purpose of each method. | Method | Purpose | | --- | --- | | `connect()` | It performs the necessary steps to connect to the underlying system. | | `disconnect()` | It gracefully closes connections established in the `connect()` method. | | `check_connection()` | It evaluates if the connection is alive and healthy. This method is called frequently. | | `native_query()` | It parses any _native_ statement string and acts upon it (for example, raw SQL commands). | | `query()` | It takes a parsed SQL command in the form of an abstract syntax tree and executes it. | | `get_tables()` | It lists and returns all the available tables. Each handler decides what a _table_ means for the underlying system when interacting with it from the data layer. Typically, these are actual tables. | | `get_columns()` | It returns columns of a table registered in the handler with the respective data type. | Authors can opt for adding private methods, new files and folders, or any combination of these to structure all the necessary work that will enable the core methods to work as intended. **Other Common Methods**Under the `mindsdb.integrations.libs.utils` library, contributors can find various methods that may be useful while implementing new handlers.Also, there are wrapper classes for the `DatabaseHandler` instances called [HandlerResponse](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/response.py#L7) and [HandlerStatusResponse](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/response.py#L32) . You should use them to ensure proper output formatting. ### [​](https://docs.mindsdb.com/contribute/data-handlers#implementation) Implementation Each database handler should inherit from the [`DatabaseHandler`](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/base.py#L102) class. Here is a step-by-step guide: * Setting the `name` class property: MindsDB uses it internally as the name of the handler. For example, the `CREATE DATABASE` statement uses the handler’s name. Copy Ask AI CREATE DATABASE integration_name WITH ENGINE = 'postgres', --- here, the handler's name is `postgres` PARAMETERS = { 'host': '127.0.0.1', 'user': 'root', 'password': 'password' }; * Implementing the `__init__()` method: This method initializes the handler. The `connection_data` argument contains the `PARAMETERS` from the `CREATE DATABASE` statement, such as `user`, `password`, etc. Copy Ask AI def __init__(self, name: str, connection_data: Optional[dict]): """ constructor Args: name (str): the handler name """ * Implementing the `connect()` method: The `connect()` method sets up the connection. Copy Ask AI def connect(self) -> HandlerStatusResponse: """ Set up any connections required by the handler Should return the output of check_connection() method after attempting connection. Should switch self.is_connected. Returns: HandlerStatusResponse """ * Implementing the `disconnect()` method: The `disconnect()` method closes the existing connection. Copy Ask AI def disconnect(self): """ Close any existing connections Should switch self.is_connected. """ * Implementing the `check_connection()` method: The `check_connection()` method performs the health check for the connection. Copy Ask AI def check_connection(self) -> HandlerStatusResponse: """ Check connection to the handler Returns: HandlerStatusResponse """ * Implementing the `native_query()` method: The `native_query()` method runs commands of the native database language. Copy Ask AI def native_query(self, query: Any) -> HandlerResponse: """Receive raw query and act upon it somehow. Args: query (Any): query in native format (str for sql databases, etc) Returns: HandlerResponse """ * Implementing the `query()` method: The query method runs parsed SQL commands. Copy Ask AI def query(self, query: ASTNode) -> HandlerResponse: """Receive query as AST (abstract syntax tree) and act upon it somehow. Args: query (ASTNode): sql query represented as AST. May be any kind of query: SELECT, INSERT, DELETE, etc Returns: HandlerResponse """ * Implementing the `get_tables()` method: The `get_tables()` method lists all the available tables. Copy Ask AI def get_tables(self) -> HandlerResponse: """ Return list of entities Return a list of entities that will be accessible as tables. Returns: HandlerResponse: should have the same columns as information_schema.tables (https://dev.mysql.com/doc/refman/8.0/en/information-schema-tables-table.html) Column 'TABLE_NAME' is mandatory, other is optional. """ * Implementing the `get_columns()` method: The `get_columns()` method lists all columns of a specified table. Copy Ask AI def get_columns(self, table_name: str) -> HandlerResponse: """ Returns a list of entity columns Args: table_name (str): name of one of tables returned by self.get_tables() Returns: HandlerResponse: should have the same columns as information_schema.columns (https://dev.mysql.com/doc/refman/8.0/en/information-schema-columns-table.html) Column 'COLUMN_NAME' is mandatory, other is optional. Highly recommended to define also 'DATA_TYPE': it should be one of python data types (by default it is str). """ ### [​](https://docs.mindsdb.com/contribute/data-handlers#exporting-the-connection-args-dictionary) Exporting the `connection_args` Dictionary The `connection_args` dictionary contains all of the arguments used to establish the connection along with their descriptions, types, labels, and whether they are required or not. The `connection_args` dictionary should be stored in the `connection_args.py` file inside the handler folder. The `connection_args` dictionary is stored in a separate file in order to be able to hide sensitive information such as passwords or API keys.By default, when querying for `connection_data` from the `information_schema.databases` table, all sensitive information is hidden. To unhide it, use this command: Copy Ask AI set show_secrets=true; Here is an example of the `connection_args.py` file from the [MySQL handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/mysql_handler) where the password value is set to hidden with `'secret': True`. Copy Ask AI from collections import OrderedDict from mindsdb.integrations.libs.const import HANDLER_CONNECTION_ARG_TYPE as ARG_TYPE connection_args = OrderedDict( url={ 'type': ARG_TYPE.STR, 'description': 'The URI-Like connection string to the MySQL server. If provided, it will override the other connection arguments.', 'required': False, 'label': 'URL' }, user={ 'type': ARG_TYPE.STR, 'description': 'The user name used to authenticate with the MySQL server.', 'required': True, 'label': 'User' }, password={ 'type': ARG_TYPE.PWD, 'description': 'The password to authenticate the user with the MySQL server.', 'required': True, 'label': 'Password', 'secret': True }, database={ 'type': ARG_TYPE.STR, 'description': 'The database name to use when connecting with the MySQL server.', 'required': True, 'label': 'Database' }, host={ 'type': ARG_TYPE.STR, 'description': 'The host name or IP address of the MySQL server. NOTE: use \'127.0.0.1\' instead of \'localhost\' to connect to local server.', 'required': True, 'label': 'Host' }, port={ 'type': ARG_TYPE.INT, 'description': 'The TCP/IP port of the MySQL server. Must be an integer.', 'required': True, 'label': 'Port' }, ssl={ 'type': ARG_TYPE.BOOL, 'description': 'Set it to True to enable ssl.', 'required': False, 'label': 'ssl' }, ssl_ca={ 'type': ARG_TYPE.PATH, 'description': 'Path or URL of the Certificate Authority (CA) certificate file', 'required': False, 'label': 'ssl_ca' }, ssl_cert={ 'type': ARG_TYPE.PATH, 'description': 'Path name or URL of the server public key certificate file', 'required': False, 'label': 'ssl_cert' }, ssl_key={ 'type': ARG_TYPE.PATH, 'description': 'The path name or URL of the server private key file', 'required': False, 'label': 'ssl_key', } ) connection_args_example = OrderedDict( host='127.0.0.1', port=3306, user='root', password='password', database='database' ) ### [​](https://docs.mindsdb.com/contribute/data-handlers#exporting-all-required-variables) Exporting All Required Variables The following should be exported in the `__init__.py` file of the handler: * The `Handler` class. * The `version` of the handler. * The `name` of the handler. * The `type` of the handler, either `DATA` handler or `ML` handler. * The `icon_path` to the file with the database icon. * The `title` of the handler or a short description. * The `description` of the handler. * The `connection_args` dictionary with the connection arguments. * The `connection_args_example` dictionary with an example of the connection arguments. * The `import_error` message that is used if the import of the `Handler` class fails. A few of these variables are defined in another file called `__about__.py`. This file is imported into the `__init__.py` file. Here is an example of the `__init__.py` file for the [MySQL handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/mysql_handler) . Copy Ask AI from mindsdb.integrations.libs.const import HANDLER_TYPE from .__about__ import __version__ as version, __description__ as description from .connection_args import connection_args, connection_args_example try: from .mysql_handler import ( MySQLHandler as Handler, connection_args_example, connection_args ) import_error = None except Exception as e: Handler = None import_error = e title = 'MySQL' name = 'mysql' type = HANDLER_TYPE.DATA icon_path = 'icon.svg' __all__ = [\ 'Handler', 'version', 'name', 'type', 'title', 'description',\ 'connection_args', 'connection_args_example', 'import_error', 'icon_path'\ ] The `__about__.py` file for the same [MySQL handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/mysql_handler) contains the following variables: Copy Ask AI __title__ = 'MindsDB MySQL handler' __package_name__ = 'mindsdb_mysql_handler' __version__ = '0.0.1' __description__ = "MindsDB handler for MySQL" __author__ = 'MindsDB Inc' __github__ = 'https://github.com/mindsdb/mindsdb' __pypi__ = 'https://pypi.org/project/mindsdb/' __license__ = 'MIT' __copyright__ = 'Copyright 2022- mindsdb' ### [​](https://docs.mindsdb.com/contribute/data-handlers#exporting-requirements) Exporting Requirements In the case if the integration requires other packages to function correctly, list them in the `requirements.txt` file. Create a text file named `requirements.txt` that stores all packages required for using the integration. Here is an example: Copy Ask AI mysql-connector-python==9.1.0 ... [​](https://docs.mindsdb.com/contribute/data-handlers#check-out-our-database-handlers) Check out our Database Handlers! -------------------------------------------------------------------------------------------------------------------------- To see some integration handlers that are currently in use, we encourage you to check out the following handlers inside the MindsDB repository: * [MySQL](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/mysql_handler) * [Postgres](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/postgres_handler) And here are [all the handlers available in the MindsDB repository](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers) . Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/contribute/data-handlers.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/contribute/data-handlers) [Python Coding Standards](https://docs.mindsdb.com/contribute/python-coding-standards) [Build an Application Handler](https://docs.mindsdb.com/contribute/app-handlers) ⌘I --- # How to Write MindsDB Documentation - MindsDB [Skip to main content](https://docs.mindsdb.com/contribute/docs#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Contribute How to Write MindsDB Documentation [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Running the Docs Locally](https://docs.mindsdb.com/contribute/docs#running-the-docs-locally) * [MindsDB Repository Structure](https://docs.mindsdb.com/contribute/docs#mindsdb-repository-structure) This section gets you started on how to contribute to the MindsDB documentation. MindsDB’s documentation is run using Mintlify. If you want to contribute to our docs, please follow the steps below to set up the environment locally. [​](https://docs.mindsdb.com/contribute/docs#running-the-docs-locally) Running the Docs Locally -------------------------------------------------------------------------------------------------- **Prerequisite** You should have installed Git (version 2.30.1 or higher) and Node.js (version 18.10.0 or higher). Step 1. Clone the MindsDB Git repository: Copy Ask AI git clone https://github.com/mindsdb/mindsdb.git Step 2. Install Mintlify on your OS: Copy Ask AI npm i mintlify -g Step 3. Go to the `docs` folder inside the cloned MindsDB Git repository and start Mintlify there: Copy Ask AI mintlify dev The documentation website is now available at `http://localhost:3000`. **Getting an Error?** If you use the Windows operating system, you may get an error saying `no such file or directory: C:/Users/Username/.mintlify/mint/client`. Here are the steps to troubleshoot it: * Go to the `C:/Users/Username/.mintlify/` directory. * Remove the `mint` folder. * Open the Git Bash in this location and run `git clone https://github.com/mintlify/mint.git`. * Repeat step 3. [​](https://docs.mindsdb.com/contribute/docs#mindsdb-repository-structure) MindsDB Repository Structure ---------------------------------------------------------------------------------------------------------- Here is the structure of the MindsDB docs repository: Copy Ask AI docs # All documentation source files |__assets/ # Images and icons used throughout the docs │ ├─ ... │__folders_with_mdx_files/ # All remaining folders that store the .mdx files |__mdx_files # Some of the .mdx files are stored in the docs directory |__mintlify.json # This JSON file stores navigation and page setup Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/contribute/docs.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/contribute/docs) [Write Handlers README](https://docs.mindsdb.com/contribute/integrations-readme) [Join our Community](https://docs.mindsdb.com/contribute/community) ⌘I --- # MindsDB Installation for Development - MindsDB [Skip to main content](https://docs.mindsdb.com/contribute/install#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Contribute MindsDB Installation for Development [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Install MindsDB for Development](https://docs.mindsdb.com/contribute/install#install-mindsdb-for-development) * [Install dependencies](https://docs.mindsdb.com/contribute/install#install-dependencies) * [Install Features via Extras](https://docs.mindsdb.com/contribute/install#install-features-via-extras) * [What’s Next?](https://docs.mindsdb.com/contribute/install#what%E2%80%99s-next) If you want to contribute to the development of MindsDB, you need to install from source. If you do not want to contribute to the development of MindsDB but simply install and use it, then [install MindsDB via Docker](https://docs.mindsdb.com/setup/self-hosted/docker) . [​](https://docs.mindsdb.com/contribute/install#install-mindsdb-for-development) Install MindsDB for Development ------------------------------------------------------------------------------------------------------------------- Here are the steps to install MindsDB from source. You can either follow the steps below or visit the provided link. Before installing MindsDB from source, ensure that you use one of the following Python versions: `3.10.x`, `3.11.x`, `3.12.x`, `3.13.x`. 1. Fork the [MindsDB repository from GitHub](https://github.com/mindsdb/mindsdb) . 2. Clone the fork locally: Copy Ask AI git clone https://github.com//mindsdb.git 3. Create a virtual environment: Copy Ask AI python -m venv mindsdb-venv 4. Activate the virtual environment: Windows: Copy Ask AI .\mindsdb-venv\Scripts\activate macOS/Linux: Copy Ask AI source mindsdb-venv/bin/activate 5. Install MindsDB with its local development dependencies: Install dependencies: Copy Ask AI cd mindsdb pip install -e . 6. Start MindsDB: Copy Ask AI python -m mindsdb By default, MindsDB starts the `http` and `mysql` APIs. You can define which APIs to start using the `api` flag as below. Copy Ask AI python -m mindsdb --api http,mysql If you want to start MindsDB without the graphical user interface (GUI), use the `--no_studio` flag as below. Copy Ask AI python -m mindsdb --no_studio Alternatively, you can use a makefile to install dependencies and start MindsDB: Copy Ask AI make install_mindsdb make run_mindsdb Now you should see the following message in the console: Copy Ask AI ... mindsdb.api.http.initialize: - GUI available at http://127.0.0.1:47334/ mindsdb.api.mysql.mysql_proxy.mysql_proxy: Starting MindsDB Mysql proxy server on tcp://127.0.0.1:47335 mindsdb.api.mysql.mysql_proxy.mysql_proxy: Waiting for incoming connections... mindsdb: mysql API: started on 47335 mindsdb: http API: started on 47334 You can access the MindsDB Editor at `localhost:47334`. [​](https://docs.mindsdb.com/contribute/install#install-dependencies) Install dependencies --------------------------------------------------------------------------------------------- The core installation includes everything needed to run the Federated Query Engine and essential database capabilities. The dependencies for many of the data or ML integrations are not installed by default. If you need additional features — such as Agents, the Knowledge Base, MCP or A2A protocol — you can enable them through extras, rather than installing everything by default. ### [​](https://docs.mindsdb.com/contribute/install#install-features-via-extras) Install Features via Extras Optional integrations and features can be installed as needed using extras. | Feature | Install command | | --- | --- | | Agents / LLMs | `pip install ".[agents]"` | | Knowledge Base | `pip install ".[kb]"` | | Multiple features at once | `pip install ".[agents,knowledgebase]"` | | Integrations | `pip install .[integration_name]` | You can find all available [handlers here](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers) . [​](https://docs.mindsdb.com/contribute/install#what%E2%80%99s-next) What’s Next? ------------------------------------------------------------------------------------ Now that you installed and started MindsDB locally, go ahead and find out how to create and train a model using the [`CREATE MODEL`](https://docs.mindsdb.com/sql/create/model) statement. Check out the [Use Cases](https://docs.mindsdb.com/use-cases/overview) section to follow tutorials that cover Large Language Models, Chatbots, Time Series, Classification, and Regression models, Semantic Search, and more. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/contribute/install.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/contribute/install) [Contribute to MindsDB](https://docs.mindsdb.com/contribute/contribute) [Python Coding Standards](https://docs.mindsdb.com/contribute/python-coding-standards) ⌘I --- # How to Write Handlers README - MindsDB [Skip to main content](https://docs.mindsdb.com/contribute/integrations-readme#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Contribute How to Write Handlers README [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Sections to Include](https://docs.mindsdb.com/contribute/integrations-readme#sections-to-include) * [Table of Contents](https://docs.mindsdb.com/contribute/integrations-readme#table-of-contents) * [About](https://docs.mindsdb.com/contribute/integrations-readme#about) * [Handler Implementation](https://docs.mindsdb.com/contribute/integrations-readme#handler-implementation) * [Example Usage](https://docs.mindsdb.com/contribute/integrations-readme#example-usage) * [Supported Tables/Tasks](https://docs.mindsdb.com/contribute/integrations-readme#supported-tables%2Ftasks) * [Limitations](https://docs.mindsdb.com/contribute/integrations-readme#limitations) * [TODO](https://docs.mindsdb.com/contribute/integrations-readme#todo) The README file is a crucial document that guides users in understanding, using, and contributing to the MindsDb integration. It serves as the first point of contact for anyone interacting with the integration, hence the need for it to be comprehensive, clear, and user-friendly. [​](https://docs.mindsdb.com/contribute/integrations-readme#sections-to-include) Sections to Include ------------------------------------------------------------------------------------------------------- ### [​](https://docs.mindsdb.com/contribute/integrations-readme#table-of-contents) Table of Contents A well-organized table of contents is provided for easy navigation through the document, allowing users to quickly find the information they need. ### [​](https://docs.mindsdb.com/contribute/integrations-readme#about) About Explain what specific database, application, or framework the integration targets. Provide a concise overview of the integration’s purpose, highlighting its key features and benefits. ### [​](https://docs.mindsdb.com/contribute/integrations-readme#handler-implementation) Handler Implementation * Setup * Detail the installation and initial setup process, including any prerequisites. * Connection * Describe the steps to establish and manage connections, with clear instructions. * Include SQL examples for better clarity. * Required Parameters * List and describe all essential parameters necessary for the operation of the integration. * Optional Parameters * Detail additional, non-mandatory parameters that can enhance the integration’s functionality. ### [​](https://docs.mindsdb.com/contribute/integrations-readme#example-usage) Example Usage * Practical Examples: Offer detailed examples showing how to use the integration effectively. * Coverage: Ensure examples encompass a range of functionalities, from basic to advanced operations. * SQL Examples: Include SQL statements and their expected outputs to illustrate use cases. ### [​](https://docs.mindsdb.com/contribute/integrations-readme#supported-tables/tasks) Supported Tables/Tasks Clearly enumerate the tables, tasks, or operations that the integration supports, possibly in a list or table format. ### [​](https://docs.mindsdb.com/contribute/integrations-readme#limitations) Limitations Transparently outline any limitations or constraints known in the integration. ### [​](https://docs.mindsdb.com/contribute/integrations-readme#todo) TODO * Future Developments: Highlight areas for future enhancements or improvements. * GitHub Issues: Link to open GitHub issues tagged as enhancements, indicating ongoing or planned feature additions. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/contribute/integrations-readme.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/contribute/integrations-readme) [Build an Application Handler](https://docs.mindsdb.com/contribute/app-handlers) [Write Documentation](https://docs.mindsdb.com/contribute/docs) ⌘I --- # Python Coding Standards - MindsDB [Skip to main content](https://docs.mindsdb.com/contribute/python-coding-standards#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Contribute Python Coding Standards [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [PEP8](https://docs.mindsdb.com/contribute/python-coding-standards#pep8) * [Automated Checks](https://docs.mindsdb.com/contribute/python-coding-standards#automated-checks) * [Logging](https://docs.mindsdb.com/contribute/python-coding-standards#logging) * [Setting Logging](https://docs.mindsdb.com/contribute/python-coding-standards#setting-logging) * [Docstrings](https://docs.mindsdb.com/contribute/python-coding-standards#docstrings) * [Exception Handling](https://docs.mindsdb.com/contribute/python-coding-standards#exception-handling) [​](https://docs.mindsdb.com/contribute/python-coding-standards#pep8) PEP8 ============================================================================= Strict adherence to [PEP8](https://peps.python.org/pep-0008/) standards is mandatory for all code contributions to MindsDB. **Why PEP8?** [PEP8](https://peps.python.org/pep-0008/) provides an extensive set of guidelines for Python code styling, promoting readability and a uniform coding standard. By aligning with PEP8, we ensure our codebase remains clean, maintainable, and easily understandable for Python developers at any level. #### [​](https://docs.mindsdb.com/contribute/python-coding-standards#automated-checks) Automated Checks * Upon submission of a Pull Request (PR), an automated process checks the code for PEP8 compliance. * Non-compliance with PEP8 can result in the failure of the build process. Adherence to PEP8 is not just a best practice but a necessity to ensure smooth integration of new code into the codebase. * If a PR fails due to PEP8 violations, the contributor is required to review the automated feedback provided. * Pay special attention to common PEP8 compliance issues such as proper indentation, appropriate line length, correct use of whitespace, and following the recommended naming conventions. * Contributors are encouraged to iteratively improve their code based on the feedback until full compliance is achieved. [​](https://docs.mindsdb.com/contribute/python-coding-standards#logging) Logging =================================================================================== Always instantiate a logger using the MindsDB utilities module. This practice ensures a uniform approach to logging across different parts of the application. Example of Logger Creation: Copy Ask AI from mindsdb.utilities import log logger = log.getLogger(__name__) ### [​](https://docs.mindsdb.com/contribute/python-coding-standards#setting-logging) Setting Logging * Environment Variable: Use `MINDSDB_LOG_LEVEL` to set the desired logging level. This approach allows for dynamic adjustment of log verbosity without needing code modifications. * Log Levels: Available levels include: * `DEBUG`: Detailed information, typically of interest only when diagnosing problems. * `INFO:` Confirmation that things are working as expected. * `WARNING`: An indication that something unexpected happened, or indicative of some problem in the near future. * `ERROR`: Due to a more serious problem, the software has not been able to perform some function. * `CRITICAL`: A serious error, indicating that the program itself may be unable to continue running. * Avoid print() statements. They lack the flexibility and control offered by logging mechanisms, particularly in terms of output redirection and level-based filtering. * The logger name should be `__name__` to automatically reflect the module’s name. This convention is crucial for pinpointing the origin of log messages. [​](https://docs.mindsdb.com/contribute/python-coding-standards#docstrings) Docstrings ========================================================================================= Docstrings are essential for documenting Python code. They provide a clear explanation of the functionality of classes, functions, modules, etc., making the codebase easier to understand and maintain. A well-written docstring should include: * Function’s Purpose: Describe what the function/class/module does. * Parameters: List and explain the parameters it takes. * Return Value: Describe what the function returns. * Exceptions: Mention any exceptions that the function might raise. Copy Ask AI def example_function(param1, param2): """This is an example docstring. Args: param1 (type): Description of param1. param2 (type): Description of param2. Returns: type: Description of the return value. Raises: ExceptionType: Description of the exception. """ # function body... [​](https://docs.mindsdb.com/contribute/python-coding-standards#exception-handling) Exception Handling ========================================================================================================= Implementing robust error handling strategies is essential to maintain the stability and reliability of MindsDB. Proper exception management ensures that the application behaves predictably under error conditions, providing clear feedback and preventing unexpected crashes or behavior. * Utilizing MindsDB Exceptions: To ensure uniformity and clarity in error reporting, always use predefined exceptions from the MindsDB exceptions library. * Adding New Exceptions: If during development you encounter a scenario where none of the existing exceptions adequately represent the error, consider defining a new, specific exception. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/contribute/python-coding-standards.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/contribute/python-coding-standards) [Installation for Development](https://docs.mindsdb.com/contribute/install) [Build a Database Handler](https://docs.mindsdb.com/contribute/data-handlers) ⌘I --- # Data Catalog for Integrations - MindsDB [Skip to main content](https://docs.mindsdb.com/data_catalog/integrations/overview#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Data Catalog for Integrations Data Catalog for Integrations [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Enabling the Data Catalog](https://docs.mindsdb.com/data_catalog/integrations/overview#enabling-the-data-catalog) * [How It Works](https://docs.mindsdb.com/data_catalog/integrations/overview#how-it-works) As of now, the Data Catalog is available for the following integrations: * [Snowflake](https://docs.mindsdb.com/integrations/data-integrations/snowflake) * [Salesforce](https://docs.mindsdb.com/integrations/app-integrations/salesforce) * [BigQuery](https://docs.mindsdb.com/integrations/data-integrations/google-bigquery) * [MS SQL Server](https://docs.mindsdb.com/integrations/data-integrations/microsoft-sql-server) * [MySQL](https://docs.mindsdb.com/integrations/app-integrations/mysql) * [Oracle](https://docs.mindsdb.com/integrations/data-integrations/oracle) * [PostgreSQL](https://docs.mindsdb.com/integrations/data-integrations/postgresql) ### [​](https://docs.mindsdb.com/data_catalog/integrations/overview#enabling-the-data-catalog) Enabling the Data Catalog To enable the Data Catalog feature in MindsDB, update your `config.json` file by setting the `data_catalog` flag to `true`: Copy Ask AI { "data_catalog": { "enabled": true } } Follow this doc page to learn how to [start MindsDB with custom configuration](https://docs.mindsdb.com/setup/custom-config) . Note that the data catalog is generated for a data source only after this data source is connected to an agent.Here is an example: Copy Ask AI CREATE DATABASE snowflake_data WITH ENGINE = 'snowflake', PARAMETERS = { "account": "abc123-xyz987", "user": "username", "password": "password", "database": "database_name", "schema": "schema_name", "warehouse": "warehouse_name" }; CREATE AGENT my_agent USING include_tables= ['snowflake_data.table_name', ...]; Now you can [query the data catalog](https://docs.mindsdb.com/data_catalog/integrations/query) generated for the `snowflake_data` integration. ### [​](https://docs.mindsdb.com/data_catalog/integrations/overview#how-it-works) How It Works When you create an [agent](https://docs.mindsdb.com/mindsdb_sql/agents/agent) in MindsDB that connects to one of the supported integrations, the Data Catalog automatically: 1. Inspects the data source. 2. Extracts metadata for all accessible tables and columns. 3. Stores this information in a dedicated catalog schema (`DATA_CATALOG`). 4. Makes this metadata available to agents and users via both SQL queries and internal reasoning. **Current Limitations**This feature is still evolving and has some known limitations: * **One-Time Snapshot**: Metadata is generated only once—at the time the agent is created. If the data schema changes (e.g., new columns, renamed tables), the Data Catalog will not automatically update. A refresh mechanism is planned in a future release. * **No Manual Feedback**: If any metadata appears to be incorrect (e.g., wrong row counts or data types), there is currently no way for users to flag or correct it. A feedback system will be introduced soon. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/data_catalog/integrations/overview.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/data_catalog/integrations/overview) [Overview](https://docs.mindsdb.com/data_catalog/overview) [Querying Data Catalog](https://docs.mindsdb.com/data_catalog/integrations/query) ⌘I --- # Querying Data Catalog for Integrations - MindsDB [Skip to main content](https://docs.mindsdb.com/data_catalog/integrations/query#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Data Catalog for Integrations Querying Data Catalog for Integrations [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Available Data Catalog Tables](https://docs.mindsdb.com/data_catalog/integrations/query#available-data-catalog-tables) * [INFORMATION\_SCHEMA.META\_TABLES](https://docs.mindsdb.com/data_catalog/integrations/query#information-schema-meta-tables) * [INFORMATION\_SCHEMA.META\_COLUMNS](https://docs.mindsdb.com/data_catalog/integrations/query#information-schema-meta-columns) * [INFORMATION\_SCHEMA.META\_COLUMN\_STATISTICS](https://docs.mindsdb.com/data_catalog/integrations/query#information-schema-meta-column-statistics) * [INFORMATION\_SCHEMA.META\_KEY\_COLUMN\_USAGE](https://docs.mindsdb.com/data_catalog/integrations/query#information-schema-meta-key-column-usage) * [INFORMATION\_SCHEMA.META\_TABLE\_CONSTRAINTS](https://docs.mindsdb.com/data_catalog/integrations/query#information-schema-meta-table-constraints) * [INFORMATION\_SCHEMA.META\_HANDLER\_INFO](https://docs.mindsdb.com/data_catalog/integrations/query#information-schema-meta-handler-info) MindsDB exposes collected metadata from connected data sources via virtual tables in the `INFORMATION_SCHEMA` schema. These views allow users to inspect and query the Data Catalog using familiar SQL syntax. [​](https://docs.mindsdb.com/data_catalog/integrations/query#available-data-catalog-tables) Available Data Catalog Tables ---------------------------------------------------------------------------------------------------------------------------- To filter results for a specific data integration, use `WHERE TABLE_SCHEMA = ''`. ### [​](https://docs.mindsdb.com/data_catalog/integrations/query#information-schema-meta-tables) `INFORMATION_SCHEMA.META_TABLES` Provides high-level metadata about available tables in a given integration. Here are the available columns: * `TABLE_NAME` (string): Name of the table. * `TABLE_TYPE` (string, optional): Type of table (e.g., `BASE TABLE`, `VIEW`). * `TABLE_SCHEMA` (string, optional): Schema name or integration name. * `TABLE_DESCRIPTION` (string, optional): Description of the table. * `ROW_COUNT` (integer, optional): Estimated row count. Here is how to query it foe a specific data integration: Copy Ask AI SELECT * FROM INFORMATION_SCHEMA.META_TABLES WHERE TABLE_SCHEMA = 'integration_name'; ### [​](https://docs.mindsdb.com/data_catalog/integrations/query#information-schema-meta-columns) `INFORMATION_SCHEMA.META_COLUMNS` Returns detailed column-level metadata for all tables in the specified integration. Here are the available columns: * `TABLE_NAME` (string): Name of the table. * `COLUMN_NAME` (string): Column name. * `DATA_TYPE` (string): Data type of the column. * `COLUMN_DESCRIPTION` (string, optional): Description of the column. * `IS_NULLABLE` (boolean, optional): Whether nulls are allowed. * `COLUMN_DEFAULT` (string, optional): Default value, if any. Here is how to query it foe a specific data integration: Copy Ask AI SELECT * FROM INFORMATION_SCHEMA.META_COLUMNS WHERE TABLE_SCHEMA = 'integration_name'; ### [​](https://docs.mindsdb.com/data_catalog/integrations/query#information-schema-meta-column-statistics) `INFORMATION_SCHEMA.META_COLUMN_STATISTICS` Provides statistical insights about each column’s values and distribution. Here are the available columns: * `TABLE_NAME` (string): Name of the table. * `COLUMN_NAME` (string): Column name. * `MOST_COMMON_VALUES` (array of strings, optional) * `MOST_COMMON_FREQUENCIES` (array of integers, optional) * `NULL_PERCENTAGE` (float, optional) * `MINIMUM_VALUE` (string, optional) * `MAXIMUM_VALUE` (string, optional) * `DISTINCT_VALUES_COUNT` (integer, optional) Here is how to query it foe a specific data integration: Copy Ask AI SELECT * FROM INFORMATION_SCHEMA.META_COLUMN_STATISTICS WHERE TABLE_SCHEMA = 'integration_name'; ### [​](https://docs.mindsdb.com/data_catalog/integrations/query#information-schema-meta-key-column-usage) `INFORMATION_SCHEMA.META_KEY_COLUMN_USAGE` Describes the primary key columns for tables in the integration. Here are the available columns: * `TABLE_NAME` (string): Name of the table. * `COLUMN_NAME` (string): Column name. * `ORDINAL_POSITION` (integer, optional) * `CONSTRAINT_NAME` (string, optional) Here is how to query it foe a specific data integration: Copy Ask AI SELECT * FROM INFORMATION_SCHEMA.META_KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = 'integration_name'; ### [​](https://docs.mindsdb.com/data_catalog/integrations/query#information-schema-meta-table-constraints) `INFORMATION_SCHEMA.META_TABLE_CONSTRAINTS` Lists table-level constraints, including primary and foreign keys. Here are the available columns: * `TABLE_NAME` (string): Name of the table. * `CONSTRAINT_NAME` (string, optional) * `CONSTRAINT_TYPE` (string): e.g., PRIMARY KEY, FOREIGN KEY Here is how to query it foe a specific data integration: Copy Ask AI SELECT * FROM INFORMATION_SCHEMA.META_TABLE_CONSTRAINTS WHERE TABLE_SCHEMA = 'integration_name'; ### [​](https://docs.mindsdb.com/data_catalog/integrations/query#information-schema-meta-handler-info) `INFORMATION_SCHEMA.META_HANDLER_INFO` Returns a textual summary of the integration implementation, including supported SQL features and capabilities. Here are the available columns: * `HANDLER_INFO` (string): Description. Here is how to query it foe a specific data integration: Copy Ask AI SELECT * FROM INFORMATION_SCHEMA.META_HANDLER_INFO WHERE TABLE_SCHEMA = 'integration_name'; Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/data_catalog/integrations/query.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/data_catalog/integrations/query) [Overview](https://docs.mindsdb.com/data_catalog/integrations/overview) [BYOM](https://docs.mindsdb.com/integrations/ai-engines/byom) ⌘I --- # Data Catalog - MindsDB [Skip to main content](https://docs.mindsdb.com/data_catalog/overview#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Data Catalog Data Catalog [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Why It Matters](https://docs.mindsdb.com/data_catalog/overview#why-it-matters) The **Data Catalog** in MindsDB plays a key role in enhancing the context available to [agents](https://docs.mindsdb.com/mindsdb_sql/agents/agent) when querying data sources. By automatically indexing and storing metadata, such as table names, column types, constraints, and statistics, the catalog empowers agents to understand the structure and semantics of the data, leading to more accurate and efficient query generation. ### [​](https://docs.mindsdb.com/data_catalog/overview#why-it-matters) Why It Matters When agents interpret natural language questions or generate SQL queries, access to metadata improves their ability to: * Understand relationships between tables and fields. * Infer joins, filters, and aggregations more intelligently. * Avoid syntax errors due to missing or unknown schema information. This metadata layer provides agents with the necessary context to avoid making uninformed queries. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/data_catalog/overview.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/data_catalog/overview) [Use a Data Source](https://docs.mindsdb.com/mindsdb_sql/sql/api/use) [Overview](https://docs.mindsdb.com/data_catalog/integrations/overview) ⌘I --- # Benefits of MindsDB - MindsDB [Skip to main content](https://docs.mindsdb.com/faqs/benefits#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation FAQs Benefits of MindsDB [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) MindsDB facilitates development of AI-powered apps by bridging the gap between data and AI. Thanks to its numerous integrations with data sources (including databases, vector stores, and applications) and AI frameworks (including LLMs and AutoML), you can mix and match between the available integrations to create custom AI workflows with MindsDB. Here are some prominent benefits of using MindsDB: 1. **Unified AI Deployment and Management** MindsDB integrates directly with the database, warehouse, or stream. This eliminates the need to build and maintain custom, complex data pipelines or separate systems for AI/ML deployment. 2. **Automated AI Workflows** MindsDB automates the entire AI workflow to execute on time-based or event-based triggers. No need to build custom automation logic to get predictions, move data, or (re)train models. 3. **Turn every developer into an AI Engineer** MindsDB enables developers to leverage their existing SQL skills, accelerating the adoption of AI across teams and departments, turning every developer into an AI Engineer. 4. **Enhanced Scalability and Performance** Whether in your private cloud or using MindsDB’s managed service, MindsDB enables you to handle large-scale AI/ML workloads efficiently. MindsDB can scale to meet the demands of your use case, ensuring optimal performance and responsiveness. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/faqs/benefits.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/faqs/benefits) [Persisting Predictions](https://docs.mindsdb.com/faqs/persist-predictions) ⌘I --- # Disposable Email Domains and OpenAI - MindsDB [Skip to main content](https://docs.mindsdb.com/faqs/disposable-email-doman-and-openai#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation FAQs Disposable Email Domains and OpenAI [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) Disposable email domains can’t make use of OpenAI, therefore users will encounter errors with using MindsDB’s integration with OpenAI. To check if your email domain is disposable, you can verify it on [QuickEmailVerification](https://quickemailverification.com/tools/disposable-email-address-detector) or [VerifyEmail.IO](https://verifymail.io/domain/ipnuc.com) . Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/faqs/disposable-email-doman-and-openai.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/faqs/disposable-email-doman-and-openai) [MindsDB and PHP](https://docs.mindsdb.com/faqs/mindsdb-with-php) [Missing required CPU features](https://docs.mindsdb.com/faqs/missing-required-cpu-features) ⌘I --- # How to Interact with MindsDB from PHP - MindsDB [Skip to main content](https://docs.mindsdb.com/faqs/mindsdb-with-php#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation FAQs How to Interact with MindsDB from PHP [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) To get started with MindsDB, you need to install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . There are a few ways you can interact with MindsDB from the PHP code. 1. You can connect to MindsDB using the [PHP Data Objects](https://www.php.net/manual/en/book.pdo.php) and execute statements directly on MindsDB with the `PDO::query` method. 2. You can use the [REST API](https://docs.mindsdb.com/rest/overview) endpoints to interact with MindsDB directly from PHP. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/faqs/mindsdb-with-php.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/faqs/mindsdb-with-php) [Persisting Predictions](https://docs.mindsdb.com/faqs/persist-predictions) [Disposable Email Domains and OpenAI](https://docs.mindsdb.com/faqs/disposable-email-doman-and-openai) ⌘I --- # Missing required CPU features - MindsDB [Skip to main content](https://docs.mindsdb.com/faqs/missing-required-cpu-features#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation FAQs Missing required CPU features [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) Depending on the operating system and its setup, you may encounter this runtime warning when starting MindsDB: Copy Ask AI RuntimeWarning: Missing required CPU features. The following required CPU features were not detected: avx2, fma, bmi1, bmi2, lzcnt The solution is to install the `polars-lts-cpu` package in the environment where MindsDB runs. If you are on an Apple ARM machine (e.g. M1), this warning is likely due to running Python under Rosetta. To troubleshoot it, install a native version of Python that does not run under Rosetta x86-64 emulation. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/faqs/missing-required-cpu-features.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/faqs/missing-required-cpu-features) [Disposable Email Domains and OpenAI](https://docs.mindsdb.com/faqs/disposable-email-doman-and-openai) ⌘I --- # How to Persist Predictions - MindsDB [Skip to main content](https://docs.mindsdb.com/faqs/persist-predictions#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation FAQs How to Persist Predictions [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Creating a View](https://docs.mindsdb.com/faqs/persist-predictions#creating-a-view) * [Creating a Table](https://docs.mindsdb.com/faqs/persist-predictions#creating-a-table) * [Downloading a CSV File](https://docs.mindsdb.com/faqs/persist-predictions#downloading-a-csv-file) MindsDB provides a range of options for persisting predictions and forecasts. Let’s explore all possibilities to save the prediction results. **Reasons to Save Predictions**Every time you want to get predictions, you need to query the model, usually joined with an input data table, like this: Copy Ask AI SELECT input.product_name, input.review, output.sentiment FROM mysql_demo_db.amazon_reviews AS input JOIN sentiment_classifier AS output; However, querying the model returns the result set that is not persistent by default. For future use, it is recommended to persist the result set instead of querying the model again with the same data.MindsDB enables you to save predictions into a view or a table or download as a CSV file. [​](https://docs.mindsdb.com/faqs/persist-predictions#creating-a-view) Creating a View ----------------------------------------------------------------------------------------- After creating the model, you can save the prediction results into a view. Copy Ask AI CREATE VIEW review_sentiment ( -- querying for predictions SELECT input.product_name, input.review, output.sentiment FROM mysql_demo_db.amazon_reviews AS input JOIN sentiment_classifier AS output LIMIT 10 ); Now the `review_sentiment` view stores sentiment predictions made for all customer reviews. Here is a [comprehensive tutorial](https://docs.mindsdb.com/nlp/sentiment-analysis-inside-mysql-with-openai) on how to predict sentiment of customer reviews using OpenAI. [​](https://docs.mindsdb.com/faqs/persist-predictions#creating-a-table) Creating a Table ------------------------------------------------------------------------------------------- After creating the model, you can save predictions into a database table. Copy Ask AI CREATE TABLE local_postgres.question_answers ( -- querying for predictions SELECT input.article_title, input.question, output.answer FROM mysql_demo_db.questions AS input JOIN question_answering_model AS output LIMIT 10 ); Here, the `local_postgres` database is a PostgreSQL database connected to MindsDB with a user that has the write access. Now the `question_answers` table stores all prediction results. Here is a [comprehensive tutorial](https://docs.mindsdb.com/nlp/question-answering-inside-mysql-with-openai) on how to answer questions using OpenAI. [​](https://docs.mindsdb.com/faqs/persist-predictions#downloading-a-csv-file) Downloading a CSV File ------------------------------------------------------------------------------------------------------- After executing the `SELECT` statement, you can download the output as a CSV file. ![](https://mintcdn.com/mindsdb/U8_C23ppbMIBDBSs/assets/faqs_download.csv.png?w=2500&fit=max&auto=format&n=U8_C23ppbMIBDBSs&q=85&s=60864d456904c35ff7bd0a33eb36db4c) Click the `Export` button and choose the `CSV` option. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/faqs/persist-predictions.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/faqs/persist-predictions) [Benefits of MindsDB](https://docs.mindsdb.com/faqs/benefits) [MindsDB and PHP](https://docs.mindsdb.com/faqs/mindsdb-with-php) ⌘I --- # Bring Your Own Model - MindsDB [Skip to main content](https://docs.mindsdb.com/integrations/ai-engines/byom#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Bring Your Own Models Bring Your Own Model [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [How It Works](https://docs.mindsdb.com/integrations/ai-engines/byom#how-it-works) * [Configuration](https://docs.mindsdb.com/integrations/ai-engines/byom#configuration) * [Example](https://docs.mindsdb.com/integrations/ai-engines/byom#example) The Bring Your Own Model (BYOM) feature lets you upload your own models in the form of Python code and use them within MindsDB. [​](https://docs.mindsdb.com/integrations/ai-engines/byom#how-it-works) How It Works --------------------------------------------------------------------------------------- You can upload your custom model via the MindsDB editor by clicking `Add` and `Upload custom model`, like this: ![](https://mintcdn.com/mindsdb/PepdSPcGoBKUq1N5/assets/byom_upload_custom_model.png?w=2500&fit=max&auto=format&n=PepdSPcGoBKUq1N5&q=85&s=23e1b8e90328d93286405f9316432efa) Here is the form that needs to be filled out in order to bring your model to MindsDB: ![](https://mintcdn.com/mindsdb/PepdSPcGoBKUq1N5/assets/byom_empty_form.png?w=2500&fit=max&auto=format&n=PepdSPcGoBKUq1N5&q=85&s=d8b03e14a877fd1bf59998c2a2e95d56) Let’s briefly go over the files that need to be uploaded: * The Python file stores an implementation of your model. It should contain the class with the implementation for the `train` and `predict` methods. Here is the sample format: Copy Ask AI class CustomPredictor(): ​ def train(self, df, target_col, args=None): return '' def predict(self, df): return df Example Copy Ask AI import os import pandas as pd ​ from sklearn.cross_decomposition import PLSRegression from sklearn import preprocessing ​ class CustomPredictor(): ​ def train(self, df, target_col, args=None): print(args, '1111') ​ self.target_col = target_col y = df[self.target_col] x = df.drop(columns=self.target_col) x_cols = list(x.columns) ​ x_scaler = preprocessing.StandardScaler().fit(x) y_scaler = preprocessing.StandardScaler().fit(y.values.reshape(-1, 1)) ​ xs = x_scaler.transform(x) ys = y_scaler.transform(y.values.reshape(-1, 1)) ​ pls = PLSRegression(n_components=1) pls.fit(xs, ys) ​ T = pls.x_scores_ W = pls.x_weights_ P = pls.x_loadings_ R = pls.x_rotations_ ​ self.x_cols = x_cols self.x_scaler = x_scaler self.P = P ​ def calc_limit(df): res = None for column in df.columns: if column == self.target_col: continue tbl = df.groupby(self.target_col).agg({column: ['mean', 'min', 'max', 'std']}) tbl.columns = tbl.columns.get_level_values(1) tbl['name'] = column tbl['std'] = tbl['std'].fillna(0) tbl['lower'] = tbl['mean'] - 3 * tbl['std'] tbl['upper'] = tbl['mean'] + 3 * tbl['std'] tbl['lower'] = tbl[["lower", "min"]].max(axis=1) # lower >= min tbl['upper'] = tbl[["upper", "max"]].min(axis=1) # upper <= max tbl = tbl[['name', 'lower', 'mean', 'upper']] try: res = pd.concat([res, tbl]) except: res = tbl return res ​ trdf = pd.DataFrame() trdf[self.target_col] = y.values trdf['T1'] = T.squeeze() limit = calc_limit(trdf).reset_index() ​ self.limit = limit ​ return "Trained predictor ready to be stored" ​ def predict(self, df): ​ yt = df[self.target_col].values xt = df[self.x_cols] ​ xt = self.x_scaler.transform(xt) ​ excess_cols = list(set(df.columns) - set(self.x_cols)) ​ pred_df = df[excess_cols].copy() ​ pred_df[self.target_col] = yt pred_df['T1'] = (xt @ self.P).squeeze() ​ pred_df = pd.merge(pred_df, self.limit[[self.target_col, 'lower', 'upper']], how='left', on=self.target_col) ​ return pred_df * The optional requirements file, or `requirements.txt`, stores all dependencies along with their versions. Here is the sample format: Copy Ask AI dependency_package_1 == version dependency_package_2 >= version dependency_package_3 >= version, < version ... Example Copy Ask AI pandas scikit-learn Once you upload the above files, please provide an engine name. Please note that your custom model is uploaded to MindsDB as an engine. Then you can use this engine to create a model. ![](https://mintcdn.com/mindsdb/tkxKy44mj_2VlYcf/assets/byom_diagram.png?w=2500&fit=max&auto=format&n=tkxKy44mj_2VlYcf&q=85&s=298827ee20c9586efe34d680000ea902) [​](https://docs.mindsdb.com/integrations/ai-engines/byom#configuration) Configuration ----------------------------------------------------------------------------------------- The BYOM feature can be configured with the following environment variables: * `MINDSDB_BYOM_ENABLED` This environment variable defines whether the BYOM feature is enabled (`MINDSDB_BYOM_ENABLED=true`) or disabled (`MINDSDB_BYOM_ENABLED=false`). Note that when running MindsDB locally, it is enabled by default. * `MINDSDB_BYOM_DEFAULT_TYPE` This environment variable defines the modes of operation of the BYOM feature. * `MINDSDB_BYOM_DEFAULT_TYPE=venv` When using the `venv` mode, MindsDB creates a virtual environment and installs in it the packages listed in the `requirements.txt` file. This virtual environment is dedicated for the custom model. Note that when running MindsDB locally, it is the default mode. * `MINDSDB_BYOM_DEFAULT_TYPE=inhouse` When using the `inhouse` mode, there is no dedicated virtual environment for the custom model. It uses the environment of MindsDB, therefore, the `requirements.txt` file is not used with this mode. * `MINDSDB_BYOM_INHOUSE_ENABLED` This environment variable defines whether the `inhouse` mode is enabled (`MINDSDB_BYOM_INHOUSE_ENABLED=true`) or disabled (`MINDSDB_BYOM_INHOUSE_ENABLED=false`). Note that when running MindsDB locally, it is enabled by default. [​](https://docs.mindsdb.com/integrations/ai-engines/byom#example) Example ----------------------------------------------------------------------------- We upload the custom model, as below: ![](https://mintcdn.com/mindsdb/PepdSPcGoBKUq1N5/assets/byom_form.png?w=2500&fit=max&auto=format&n=PepdSPcGoBKUq1N5&q=85&s=64ae58cea5d9b28b1027bebbe138ae16) Here we upload the `model.py` file that stores an implementation of the model and the `requirements.txt` file that stores all the dependencies. Once the model is uploaded, it becomes an ML engine within MindsDB. Now we use this `custom_model_engine` to create a model as follows: Copy Ask AI CREATE MODEL custom_model FROM my_integration (SELECT * FROM my_table) PREDICT target USING ENGINE = 'custom_model_engine'; Let’s query for predictions by joining the custom model with the data table. Copy Ask AI SELECT input.feature_column, model_target_column FROM my_integration.my_table as input JOIN custom_model as model; Check out the [BYOM handler folder](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/byom_handler) to see the implementation details. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/integrations/ai-engines/byom.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/ai-engines/byom) [Querying Data Catalog](https://docs.mindsdb.com/data_catalog/integrations/query) [MLflow](https://docs.mindsdb.com/integrations/ai-engines/mlflow) ⌘I --- # MindsDB and MLflow - MindsDB [Skip to main content](https://docs.mindsdb.com/integrations/ai-engines/mlflow#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Bring Your Own Models MindsDB and MLflow [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [How to Use MLflow Models in MindsDB](https://docs.mindsdb.com/integrations/ai-engines/mlflow#how-to-use-mlflow-models-in-mindsdb) * [Example](https://docs.mindsdb.com/integrations/ai-engines/mlflow#example) MLflow allows you to create, train, and serve machine learning models, apart from other features, such as organizing experiments, tracking metrics, and more. [​](https://docs.mindsdb.com/integrations/ai-engines/mlflow#how-to-use-mlflow-models-in-mindsdb) How to Use MLflow Models in MindsDB --------------------------------------------------------------------------------------------------------------------------------------- Here are the prerequisites for using MLflow-served models in MindsDB: 1. Train a model via a wrapper class that inherits from the `mlflow.pyfunc.PythonModel` class. It should expose the `predict()` method that returns the predicted output for some input data when called. Please ensure that the Python version specified for Conda environment matches the one used to train the model. 2. Start the MLflow server: Copy Ask AI mlflow server -p 5001 --backend-store-uri sqlite:////path/to/mlflow.db --default-artifact-root ./artifacts --host 0.0.0.0 3. Serve the trained model: Copy Ask AI mlflow models serve --model-uri ./model_folder_name [​](https://docs.mindsdb.com/integrations/ai-engines/mlflow#example) Example ------------------------------------------------------------------------------- Let’s create a model that registers an MLflow-served model as an AI Table: Copy Ask AI CREATE MODEL mindsdb.mlflow_model PREDICT target USING engine = 'mlflow', model_name = 'model_folder_name', -- replace the model_folder_name variable with a real value mlflow_server_url = 'http://0.0.0.0:5001/', -- match the port number with the MLflow server (point 2 in the previous section) mlflow_server_path = 'sqlite:////path/to/mlflow.db', -- replace the path with a real value (here we use the sqlite database) predict_url = 'http://localhost:5000/invocations'; -- match the port number that serves the trained model (point 3 in the previous section) Here is how to check the models status: Copy Ask AI DESCRIBE mlflow_model; Once the status is `complete`, we can query for predictions. One way is to query for a single prediction using synthetic data in the `WHERE` clause. Copy Ask AI SELECT target FROM mindsdb.mlflow_model WHERE text = 'The tsunami is coming, seek high ground'; Another way is to query for batch predictions by joining the model with the data table. Copy Ask AI SELECT t.text, m.predict FROM mindsdb.mlflow_model AS m JOIN files.some_text as t; Here, the data table comes from the `files` integration. It is joined with the model and predictions are made for all the records at once. **Get More Insights**Check out the article on [How to bring your own machine learning model to databases](https://medium.com/mindsdb/how-to-bring-your-own-machine-learning-model-to-databases-47a188d6db00) by [Patricio Cerda Mardini](https://medium.com/@paxcema) to learn more. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/integrations/ai-engines/mlflow.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/ai-engines/mlflow) [BYOM](https://docs.mindsdb.com/integrations/ai-engines/byom) ⌘I --- # Binance - MindsDB [Skip to main content](https://docs.mindsdb.com/integrations/app-integrations/binance#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Applications Binance [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Connection](https://docs.mindsdb.com/integrations/app-integrations/binance#connection) * [Usage](https://docs.mindsdb.com/integrations/app-integrations/binance#usage) * [Select Data](https://docs.mindsdb.com/integrations/app-integrations/binance#select-data) * [Train a Model](https://docs.mindsdb.com/integrations/app-integrations/binance#train-a-model) * [Making Predictions](https://docs.mindsdb.com/integrations/app-integrations/binance#making-predictions) In this section, we present how to connect Binance to MindsDB. [Binance](https://www.binance.com/en) is one of the world’s largest cryptocurrency exchanges. It’s an online platform where you can buy, sell, and trade a wide variety of cryptocurrencies. Binance offers a range of services beyond just trading, including staking, lending, and various financial products related to cryptocurrencies. Binance provides real-time trade data that can be utilized within MindsDB to make real-time forecasts. [​](https://docs.mindsdb.com/integrations/app-integrations/binance#connection) Connection -------------------------------------------------------------------------------------------- This handler integrates with the [Binance API](https://binance-docs.github.io/apidocs/spot/en/#change-log) to make aggregate trade (kline) data available to use for model training and predictions. Since there are no parameters required to connect to Binance using MindsDB, you can use the below statement: Copy Ask AI CREATE DATABASE my_binance WITH ENGINE = 'binance'; [​](https://docs.mindsdb.com/integrations/app-integrations/binance#usage) Usage ---------------------------------------------------------------------------------- ### [​](https://docs.mindsdb.com/integrations/app-integrations/binance#select-data) Select Data By default, aggregate data (klines) from the latest 1000 trading intervals with a length of one minute (1m) each will be returned. Copy Ask AI SELECT * FROM my_binance.aggregated_trade_data WHERE symbol = 'BTCUSDT'; Response Here is the sample output data: Copy Ask AI | symbol | open_time | open_price | high_price | low_price | close_price | volume | close_time | quote_asset_volume | number_of_trades | taker_buy_base_asset_volume | taker_buy_quote_asset_volume | | ----------- | ----------- | ----------- | ----------- | ----------- | ----------- | ----------- | ----------- | ------------------ | ---------------- | --------------------------- | ---------------------------- | | BTCUSDT | 1678338600 | 21752.65000 | 21761.33000 | 21751.53000 | 21756.7000 | 103.8614100 | 1678338659.999| 2259656.20520700 | 3655 | 55.25763000 | 1202219.60971860 | where: * `symbol` - Trading pair (BTC to USDT in the above example) * `open_time` - Start time of interval in seconds since the Unix epoch (default interval is 1m) * `open_price` - Price of a base asset at the beginning of a trading interval * `high_price` - The highest price of a base asset during trading interval * `low_price` - Lowest price of a base asset during a trading interval * `close_price` - Price of a base asset at the end of a trading interval * `volume` - Total amount of base asset traded during an interval * `close_time` - End time of interval in seconds since the Unix epoch * `quote_asset_volume` - Total amount of quote asset (USDT in the above case) traded during an interval * `number_of_trades` - Total number of trades made during an interval * `taker_buy_base_asset_volume` - How much of the base asset volume is contributed by taker buy orders * `taker_buy_quote_asset_volume` - How much of the quote asset volume is contributed by taker buy orders To get a customized response we can pass open\_time, close\_time, and interval: Copy Ask AI SELECT * FROM my_binance.aggregated_trade_data WHERE symbol = 'BTCUSDT' AND open_time > '2023-01-01' AND close_time < '2023-01-03 08:00:00' AND interval = '1s' LIMIT 10000; Supported intervals are [listed here](https://binance-docs.github.io/apidocs/spot/en/#kline-candlestick-data) ### [​](https://docs.mindsdb.com/integrations/app-integrations/binance#train-a-model) Train a Model Here is how to create a time series model using 10000 trading intervals in the past with a duration of 1m. Copy Ask AI CREATE MODEL mindsdb.btc_forecast_model FROM my_binance ( SELECT * FROM aggregated_trade_data WHERE symbol = 'BTCUSDT' AND close_time < '2023-01-01' AND interval = '1m' LIMIT 10000; ) PREDICT open_price ORDER BY open_time WINDOW 100 HORIZON 10; For more accuracy, the limit can be set to a higher value (e.g. 100,000) ### [​](https://docs.mindsdb.com/integrations/app-integrations/binance#making-predictions) Making Predictions First, let’s create a view for the most recent BTCUSDT aggregate trade data: Copy Ask AI CREATE VIEW recent_btcusdt_data AS ( SELECT * FROM my_binance.aggregated_trade_data WHERE symbol = 'BTCUSDT' ) Now let’s predict the future price of BTC: Copy Ask AI SELECT m.* FROM recent_btcusdt_data AS t JOIN mindsdb.btc_forecast_model AS m WHERE m.open_time > LATEST This will give the predicted BTC price for the next 10 minutes (as the horizon is set to 10) in terms of USDT. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/integrations/app-integrations/binance.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/app-integrations/binance) [Sample Database](https://docs.mindsdb.com/integrations/sample-database) [Confluence](https://docs.mindsdb.com/integrations/app-integrations/confluence) ⌘I --- # Confluence - MindsDB [Skip to main content](https://docs.mindsdb.com/integrations/app-integrations/confluence#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Applications Confluence [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Prerequisites](https://docs.mindsdb.com/integrations/app-integrations/confluence#prerequisites) * [Connection](https://docs.mindsdb.com/integrations/app-integrations/confluence#connection) * [Usage](https://docs.mindsdb.com/integrations/app-integrations/confluence#usage) * [Supported Tables](https://docs.mindsdb.com/integrations/app-integrations/confluence#supported-tables) This documentation describes the integration of MindsDB with [Confluence](https://www.atlassian.com/software/confluence) , a popular collaboration and documentation tool developed by Atlassian. The integration allows MindsDB to access data from Confluence and enhance it with AI capabilities. [​](https://docs.mindsdb.com/integrations/app-integrations/confluence#prerequisites) Prerequisites ----------------------------------------------------------------------------------------------------- Before proceeding, ensure the following prerequisites are met: 1. Install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . [​](https://docs.mindsdb.com/integrations/app-integrations/confluence#connection) Connection ----------------------------------------------------------------------------------------------- Establish a connection to Confluence from MindsDB by executing the following SQL command and providing its [handler name](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/confluence_handler) as an engine. Copy Ask AI CREATE DATABASE confluence_datasource WITH ENGINE = 'confluence', PARAMETERS = { "api_base": "https://example.atlassian.net", "username": "[email protected]", "password": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6" }; Required connection parameters include the following: * `api_base`: The base URL for your Confluence instance/server. * `username`: The email address associated with your Confluence account. * `password`: The API token generated for your Confluence account. Refer this [guide](https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/) for instructions on how to create API tokens for your account. [​](https://docs.mindsdb.com/integrations/app-integrations/confluence#usage) Usage ------------------------------------------------------------------------------------- Retrieve data from a specified table by providing the integration and table names: Copy Ask AI SELECT * FROM confluence_datasource.table_name LIMIT 10; The above example utilize `confluence_datasource` as the datasource name, which is defined in the `CREATE DATABASE` command. [​](https://docs.mindsdb.com/integrations/app-integrations/confluence#supported-tables) Supported Tables ----------------------------------------------------------------------------------------------------------- * `spaces`: The table containing information about the spaces in Confluence. * `pages`: The table containing information about the pages in Confluence. * `blogposts`: The table containing information about the blog posts in Confluence. * `whiteboards`: The table containing information about the whiteboards in Confluence. * `databases`: The table containing information about the databases in Confluence. * `tasks`: The table containing information about the tasks in Confluence. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/integrations/app-integrations/confluence.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/app-integrations/confluence) [Binance](https://docs.mindsdb.com/integrations/app-integrations/binance) [Docker Hub](https://docs.mindsdb.com/integrations/app-integrations/dockerhub) ⌘I --- # Page Not Found [Skip to main content](https://docs.mindsdb.com/app-integrations/microsoft-teams#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Page Not Found [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) 404 Page Not Found ============== We couldn't find the page. Maybe you were looking for one of these pages below? [Microsoft Teams](https://docs.mindsdb.com/integrations/app-integrations/microsoft-teams#microsoft-teams) [Microsoft SQL Server](https://docs.mindsdb.com/integrations/data-integrations/microsoft-sql-server#microsoft-sql-server) [Microsoft One Drive](https://docs.mindsdb.com/integrations/app-integrations/microsoft-onedrive#microsoft-one-drive) ⌘I --- # Page Not Found [Skip to main content](https://docs.mindsdb.com/app-integrations/microsoft-onedrive#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Page Not Found [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) 404 Page Not Found ============== We couldn't find the page. Maybe you were looking for one of these pages below? [Microsoft One Drive](https://docs.mindsdb.com/integrations/app-integrations/microsoft-onedrive#microsoft-one-drive) [Microsoft Teams](https://docs.mindsdb.com/integrations/app-integrations/microsoft-teams#microsoft-teams) [Microsoft SQL Server](https://docs.mindsdb.com/integrations/data-integrations/microsoft-sql-server#microsoft-sql-server) ⌘I --- # Page Not Found [Skip to main content](https://docs.mindsdb.com/app-integrations/newsapi#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Page Not Found [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) 404 Page Not Found ============== We couldn't find the page. Maybe you were looking for one of these pages below? [News API](https://docs.mindsdb.com/integrations/app-integrations/newsapi#news-api) [Build an Application Handler](https://docs.mindsdb.com/contribute/app-handlers#build-an-application-handler) [Use a Data Source](https://docs.mindsdb.com/mindsdb_sql/sql/api/use#) ⌘I --- # MindsDB at AWS Marketplace - MindsDB [Skip to main content](https://docs.mindsdb.com/setup/cloud/aws-marketplace#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation MindsDB at AWS Marketplace [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) MindsDB offers a streamlined setup process in cloud environments using its AWS Marketplace image. Explore the MindsDB AWS Marketplace image [here](https://aws.amazon.com/marketplace/seller-profile?id=03a65520-86ca-4ab8-a394-c11eb54573a9) . Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/setup/cloud/aws-marketplace.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/setup/cloud/aws-marketplace) ⌘I --- # Data Insights - MindsDB [Skip to main content](https://docs.mindsdb.com/sql/data-insights#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Data Insights [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Features](https://docs.mindsdb.com/sql/data-insights#features) * [Distribution of Data per Column](https://docs.mindsdb.com/sql/data-insights#distribution-of-data-per-column) * [Potential Bias Flag](https://docs.mindsdb.com/sql/data-insights#potential-bias-flag) * [Missing Values Flag](https://docs.mindsdb.com/sql/data-insights#missing-values-flag) * [Hovering Over the Histogram](https://docs.mindsdb.com/sql/data-insights#hovering-over-the-histogram) * [Full Data Analysis](https://docs.mindsdb.com/sql/data-insights#full-data-analysis) * [What’s Next?](https://docs.mindsdb.com/sql/data-insights#what%E2%80%99s-next) Data Insights is a data visualization feature of the MindsDB editor. It lets you explore the queried data by initially displaying and analyzing a subset of the first ten rows. You can choose to analyze a full dataset by clicking the `Full Data Analysis` button. The analysis presents the distribution of your data aggregated by column. ![](https://mintcdn.com/mindsdb/PwWStDnrPJllqmj0/assets/sql/data-insights-1.png?w=2500&fit=max&auto=format&n=PwWStDnrPJllqmj0&q=85&s=09f258d9eb074c654c8b2bedf16f9ebf) The data used here comes from one of our tutorials. For details, click [here](https://docs.mindsdb.com/sql/tutorials/home-rentals) . Before you see the Data Insights pane, you must run a `SELECT` query on your dataset. Let’s have a look at the available features. [​](https://docs.mindsdb.com/sql/data-insights#features) Features -------------------------------------------------------------------- ### [​](https://docs.mindsdb.com/sql/data-insights#distribution-of-data-per-column) Distribution of Data per Column When opening the Data Insights pane, you see the distribution of data of each output dataset column. Initially, the visualization and analysis of the first ten rows is shown, as below. ![](https://mintcdn.com/mindsdb/PwWStDnrPJllqmj0/assets/sql/data-insights-2.png?w=2500&fit=max&auto=format&n=PwWStDnrPJllqmj0&q=85&s=c92b1be3346c0ecd938cfc77f8e2d428) There is one histogram per column that depicts the column name, data types of the distribution, and the distribution itself. ### [​](https://docs.mindsdb.com/sql/data-insights#potential-bias-flag) `Potential Bias` Flag To see the `Potential Bias` flag, enter a full-screen mode of the Data Insights pane. ![](https://mintcdn.com/mindsdb/PwWStDnrPJllqmj0/assets/sql/data-insights-3.png?w=2500&fit=max&auto=format&n=PwWStDnrPJllqmj0&q=85&s=f625bbd3218a30e3319d9d7662895b21) Here, the `location` column exhibits potential bias, as there are more `great` column values than `good` or `poor` column values. Such cases are typically flagged. However, it does not necessarily mean that there is a problem with the dataset. The `Potential Bias` flag is used when data does not distribute normally or uniformly, likely over-representing or under-representing some values. This may be normal, hence, bias is only potential. ### [​](https://docs.mindsdb.com/sql/data-insights#missing-values-flag) `Missing Values` Flag To see the `Missing Values` flag, enter a full-screen mode of the Data Insights pane. This flag indicates the proportion of missing values in a column. Columns with a high percentage of missing values are not useful for modeling purposes. Hence, it is recommended to pay attention to the `Missing Values` flag and try to mitigate it whenever possible, as it indicates the degrading quality of your data. ### [​](https://docs.mindsdb.com/sql/data-insights#hovering-over-the-histogram) Hovering Over the Histogram When hovering over the histogram, you get the information on a particular column value and how many of such values are present in a column. The format is `(column_value, count)`. ![](https://mintcdn.com/mindsdb/qZ0qlWEqCb1K2Drt/assets/sql/data-insights-6.png?w=2500&fit=max&auto=format&n=qZ0qlWEqCb1K2Drt&q=85&s=4dea60a5fe82aa0a0e70813a3754f27c) It is helpful to determine the exact data value counts from the histograms. [​](https://docs.mindsdb.com/sql/data-insights#full-data-analysis) Full Data Analysis ---------------------------------------------------------------------------------------- Let’s do a full data analysis step by step. First, we need to query data for analysis in the MindsDB editor. Please note that you need to query your dataset without using a `LIMIT` keyword to be able to perform a complete data analysis. Copy Ask AI SELECT * FROM example_db.demo_data.home_rentals; On execution, we get: Copy Ask AI +---------------+-------------------+----+--------+--------------+--------------+------------+ |number_of_rooms|number_of_bathrooms|sqft|location|days_on_market|neighborhood |rental_price| +---------------+-------------------+----+--------+--------------+--------------+------------+ |2 |1 |917 |great |13 |berkeley_hills|3901 | |0 |1 |194 |great |10 |berkeley_hills|2042 | |1 |1 |543 |poor |18 |westbrae |1871 | |2 |1 |503 |good |10 |downtown |3026 | |3 |2 |1066|good |13 |thowsand_oaks |4774 | +---------------+-------------------+----+--------+--------------+--------------+------------+ Now, open the Data Insights pane by clicking the `Data Insights` button to the right of the output table. Initially, it shows the analysis of the first ten rows of the output table. ![](https://mintcdn.com/mindsdb/PwWStDnrPJllqmj0/assets/sql/data-insights-4.png?w=2500&fit=max&auto=format&n=PwWStDnrPJllqmj0&q=85&s=f4a6a31982175a69e60dae19876ea9be) To perform a complete analysis of your data, you can either go to a full-screen mode or stay in a pane mode and click on the `Full Data Analysis` button. Below is the complete data analysis. ![](https://mintcdn.com/mindsdb/PwWStDnrPJllqmj0/assets/sql/data-insights-5.png?w=2500&fit=max&auto=format&n=PwWStDnrPJllqmj0&q=85&s=2cd47fbfec3ac664eafefc8d3b8529be) Also, whenever your dataset changes, you can click on the `Refresh Data Analysis` button to update the data visualization and analysis. [​](https://docs.mindsdb.com/sql/data-insights#what%E2%80%99s-next) What’s Next? ----------------------------------------------------------------------------------- Want to do more exploratory data analysis in MindsDB? We’re collecting feedback to develop even more data visualization features. Let us know what you’d like to see as part of Data Insights. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/sql/data-insights.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/sql/data-insights) ⌘I --- # Forecast Quarterly House Sales with MindsDB - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/predictive_analytics/house-sales-forecasting#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Forecast Quarterly House Sales with MindsDB [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Connect a data source](https://docs.mindsdb.com/use-cases/predictive_analytics/house-sales-forecasting#connect-a-data-source) * [Deploy and train an ML model](https://docs.mindsdb.com/use-cases/predictive_analytics/house-sales-forecasting#deploy-and-train-an-ml-model) * [Make predictions](https://docs.mindsdb.com/use-cases/predictive_analytics/house-sales-forecasting#make-predictions) * [Automate continuous improvement of the model](https://docs.mindsdb.com/use-cases/predictive_analytics/house-sales-forecasting#automate-continuous-improvement-of-the-model) In this tutorial, we’ll use a time-series model to forecast quarterly house sales. This tutorial uses the Lightwood integration that requires the `mindsdb/mindsdb:lightwood` Docker image. [Learn more here](https://docs.mindsdb.com/setup/self-hosted/docker#install-mindsdb) . [​](https://docs.mindsdb.com/use-cases/predictive_analytics/house-sales-forecasting#connect-a-data-source) Connect a data source ----------------------------------------------------------------------------------------------------------------------------------- We start by connecting a demo database to MindsDB using the `CREATE DATABASE` statement. Copy Ask AI CREATE DATABASE example_db WITH ENGINE = "postgres", PARAMETERS = { "user": "demo_user", "password": "demo_password", "host": "samples.mindsdb.com", "port": "5432", "database": "demo", "schema": "demo_data" }; Let’s preview the data that will be used to train the model. Copy Ask AI SELECT * FROM example_db.house_sales LIMIT 10; [​](https://docs.mindsdb.com/use-cases/predictive_analytics/house-sales-forecasting#deploy-and-train-an-ml-model) Deploy and train an ML model ------------------------------------------------------------------------------------------------------------------------------------------------- Now, lets specify that we want to forecast the `ma` column, which is a moving average of the historical median price for house sales. Looking at the data, you can see several entries for the same date, which depend on two factors: how many bedrooms the properties have, and whether properties are “houses” or “units”. This means that we can have up to ten different groupings here. Let’s look at the data for one of them. Copy Ask AI SELECT saledate, ma, type, bedrooms FROM example_db.house_sales WHERE type='house' AND bedrooms=3; We want to generate forecasts to predict the behavior of this and the other series for the next year. MindsDB makes it simple so that we don’t need to repeat the predictor creation process for every group there is. Instead, we can just group for both columns and the predictor will learn from all series and enable all forecasts. We are going to use the `CREATE MODEL` statement, where we specify what data to train `FROM` and what we want to `PREDICT`. Copy Ask AI CREATE MODEL mindsdb.house_sales_model FROM example_db (SELECT * FROM house_sales) PREDICT ma ORDER BY saledate GROUP BY bedrooms, type -- as the data is quarterly, we will look back two years to forecast the next one year WINDOW 8 HORIZON 4; You can check the status of the model as below: Copy Ask AI DESCRIBE house_sales_model; [​](https://docs.mindsdb.com/use-cases/predictive_analytics/house-sales-forecasting#make-predictions) Make predictions ------------------------------------------------------------------------------------------------------------------------- Once the model’s status is complete, you can query it as a table to get forecasts for a given period of time. Usually, you’ll want to know what happens right after the latest training data point that was fed, for which we have a special bit of syntax, the `LATEST` keyword. Copy Ask AI SELECT m.saledate as date, m.ma as forecast FROM mindsdb.house_sales_model as m JOIN example_db.house_sales as t WHERE t.saledate > LATEST AND t.type = 'house' AND t.bedrooms=2 LIMIT 4; Now, try changing the value of `type` and `bedrooms` columns and check how the forecast varies. This is because MindsDB recognizes each grouping as being its own different time series. [​](https://docs.mindsdb.com/use-cases/predictive_analytics/house-sales-forecasting#automate-continuous-improvement-of-the-model) Automate continuous improvement of the model --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Now, we can take this even further. MindsDB includes powerful automation features called Jobs which allow us to automate queries in MindsDB. This is very handy for production AI/ML systems which all require automation logic to help them to work. We use the `CREATE JOB` statement to create a Job. Now, let’s use a Job to retrain the model every two days, just like we might in production. You can retrain the model to improve predictions every time when either new data or new MindsDB version is available. And, if you want to retrain your model considering only new data, then go for finetuning it. Copy Ask AI CREATE JOB retrain_model_and_save_predictions ( RETRAIN mindsdb.house_sales_model FROM example_db (SELECT * FROM house_sales) ) EVERY 2 days IF (SELECT * FROM example_db.house_sales WHERE created_at > LAST); This job will execute every 2 days only if there is new data available in the `house_sales` table. Learn more about the [`LAST` keyword](https://docs.mindsdb.com/mindsdb_sql/sql/create/jobs#last) here. And there you have it! You created an end-to-end automated production ML system in a few short minutes. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/predictive_analytics/house-sales-forecasting.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/predictive_analytics/house-sales-forecasting) ⌘I --- # Setup for Source Code via pip - MindsDB [Skip to main content](https://docs.mindsdb.com/setup/self-hosted/pip/source#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Setup for Source Code via pip [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Installation](https://docs.mindsdb.com/setup/self-hosted/pip/source#installation) * [Dependencies](https://docs.mindsdb.com/setup/self-hosted/pip/source#dependencies) * [Troubleshooting](https://docs.mindsdb.com/setup/self-hosted/pip/source#troubleshooting) * [Pip and Python Versions](https://docs.mindsdb.com/setup/self-hosted/pip/source#pip-and-python-versions) * [How to Avoid Dependency Issues](https://docs.mindsdb.com/setup/self-hosted/pip/source#how-to-avoid-dependency-issues) * [How to Avoid Common Errors](https://docs.mindsdb.com/setup/self-hosted/pip/source#how-to-avoid-common-errors) * [Further Issues?](https://docs.mindsdb.com/setup/self-hosted/pip/source#further-issues) * [What’s Next](https://docs.mindsdb.com/setup/self-hosted/pip/source#what%E2%80%99s-next) This section describes how to deploy MindsDB from the source code. It is the preferred way to use MindsDB if you want to contribute to our code or debug MindsDB. To successfully install MindsDB, use **Python 64-bit version**. Also, make sure that **Python >= 3.10** and **pip >= 20.3**. [​](https://docs.mindsdb.com/setup/self-hosted/pip/source#installation) Installation --------------------------------------------------------------------------------------- Please note that this method of MindsDB installation requires a minimum of 6 GB free storage. 1. Clone the MindsDB repository: Copy Ask AI git clone https://github.com/mindsdb/mindsdb.git 2. Create a new virtual environment: Copy Ask AI python -m venv mindsdb-venv 3. Activate the virtual environment: Copy Ask AI source mindsdb-venv/bin/activate 4. Install dependencies: Copy Ask AI cd mindsdb pip install -e . pip install -r requirements/requirements-dev.txt 5. Start MindsDB: Copy Ask AI python -m mindsdb By default, MindsDB starts the `http` and `mysql` APIs. You can define which APIs to start using the `api` flag as below. Copy Ask AI python -m mindsdb --api http,mysql,postgres If you want to start MindsDB without the graphical user interface (GUI), use the `--no_studio` flag as below. Copy Ask AI python -m mindsdb --no_studio 6. Now, you can access the following: MindsDB Studio MindsDB using MySQL Copy Ask AI http://127.0.0.1:47334/ [​](https://docs.mindsdb.com/setup/self-hosted/pip/source#dependencies) Dependencies --------------------------------------------------------------------------------------- The dependencies for many of the data or ML integrations are not installed by default. If you want to use a data or ML integration whose dependencies are not available by default, install it by running this command: Copy Ask AI pip install mindsdb[handler_name] You can find all available [handlers here](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers) . [​](https://docs.mindsdb.com/setup/self-hosted/pip/source#troubleshooting) Troubleshooting --------------------------------------------------------------------------------------------- ### [​](https://docs.mindsdb.com/setup/self-hosted/pip/source#pip-and-python-versions) Pip and Python Versions Currently, MindsDB supports Python versions 3.10.x, 3.10.x, and 3.11.x. To successfully install MindsDB, use **Python 64-bit version**. Also, make sure that **Python >= 3.10** and **pip >= 20.3**. You can check the pip and python versions by running the `pip --version` and `python --version` commands. Please note that depending on your environment and installed pip and python packages, you might have to use **pip3** instead of **pip** or **python3.x** instead of **py**. For example, `pip3 install mindsdb` instead of `pip install mindsdb`. ### [​](https://docs.mindsdb.com/setup/self-hosted/pip/source#how-to-avoid-dependency-issues) How to Avoid Dependency Issues Install MindsDB in a virtual environment using **pip** to avoid dependency issues. ### [​](https://docs.mindsdb.com/setup/self-hosted/pip/source#how-to-avoid-common-errors) How to Avoid Common Errors MindsDB requires around 3 GB of free disk space to install all of its dependencies. Make sure to allocate min. 3 GB of disk space to avoid the `IOError: [Errno 28] No space left on device while installing MindsDB` error. Before anything, activate your virtual environment where your MindsDB is installed. It is to avoid the `No module named mindsdb` error. If you encounter the `This site can’t be reached. 127.0.0.1 refused to connect.` error, please check the MindsDB server console to see if the server is still in the `starting` phase. But if the server has started and you still get this error, please report it on our [GitHub repository](https://github.com/mindsdb/mindsdb/issues) . [​](https://docs.mindsdb.com/setup/self-hosted/pip/source#further-issues) Further Issues? -------------------------------------------------------------------------------------------- You can try to use [Docker setup](https://docs.mindsdb.com/setup/self-hosted/docker) in case you are experiencing issues using pip. Also, please create an issue with detailed description in the [MindsDB GitHub repository](https://github.com/mindsdb/mindsdb/issues) so we can help you. Usually, we review issues and respond within a few hours. [​](https://docs.mindsdb.com/setup/self-hosted/pip/source#what%E2%80%99s-next) What’s Next --------------------------------------------------------------------------------------------- Now that you installed and started MindsDB locally in your Docker container, go ahead and find out how to create and train a model using the [`CREATE MODEL`](https://docs.mindsdb.com/sql/create/model) statement. In the **MindsDB SQL** section, you’ll find a comprehensive overview of the SQL syntax offered by MindsDB. You can connect MindsDB to different clients, including [PostgreSQL CLI](https://docs.mindsdb.com/connect/postgres-client) and [MySQL CLI](https://docs.mindsdb.com/connect/mysql-client) . Check out the [Use Cases](https://docs.mindsdb.com/use-cases/overview) section to follow tutorials that cover Large Language Models, Natural Language Processing, Time Series, Classification, and Regression models. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/setup/self-hosted/pip/source.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/setup/self-hosted/pip/source) ⌘I --- # Chatbot - MindsDB [Skip to main content](https://docs.mindsdb.com/mindsdb_sql/agents/chatbot#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Chatbot [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [CREATE CHATBOT Syntax](https://docs.mindsdb.com/mindsdb_sql/agents/chatbot#create-chatbot-syntax) * [database](https://docs.mindsdb.com/mindsdb_sql/agents/chatbot#database) * [agent](https://docs.mindsdb.com/mindsdb_sql/agents/chatbot#agent) * [is\_running](https://docs.mindsdb.com/mindsdb_sql/agents/chatbot#is-running) * [DROP CHATBOT Syntax](https://docs.mindsdb.com/mindsdb_sql/agents/chatbot#drop-chatbot-syntax) * [Example](https://docs.mindsdb.com/mindsdb_sql/agents/chatbot#example) Within MindsDB, chatbots are [agents](https://docs.mindsdb.com/mindsdb_sql/agents/agent) connected to a chat interface. Creating a chatbot requires either an [AI agent](https://docs.mindsdb.com/mindsdb_sql/agents/agent) or an LLM, and a connection to a chat app, like [Slack](https://docs.mindsdb.com/integrations/app-integrations/slack) or [MS Teams](https://docs.mindsdb.com/integrations/app-integrations/microsoft-teams) . ![](https://mintcdn.com/mindsdb/tkxKy44mj_2VlYcf/assets/chatbot_diagram.png?w=2500&fit=max&auto=format&n=tkxKy44mj_2VlYcf&q=85&s=f6d526ee95c49ac0e8024816a30f63b0) [​](https://docs.mindsdb.com/mindsdb_sql/agents/chatbot#create-chatbot-syntax) `CREATE CHATBOT` Syntax --------------------------------------------------------------------------------------------------------- Here is how to create a chatbot that integrates an AI Agent and can be connected to a chat interface. Copy Ask AI CREATE CHATBOT my_chatbot USING database = 'my_slack', -- created with CREATE DATABASE my_slack agent = 'my_agent', -- created with CREATE AGENT my_agent is_running = true; -- default is true It creates a chatbot that users can interact with via the configured chat interface. View all chatbots with this command. Copy Ask AI SHOW CHATBOTS; ### [​](https://docs.mindsdb.com/mindsdb_sql/agents/chatbot#database) `database` In MindsDB, the [`CREATE DATABASE` command](https://docs.mindsdb.com/mindsdb_sql/sql/create/database) is used to connect data integrations including databases and applications such as chat interfaces. The `database` parameter stores the name of the chat interface connected to MindsDB with the [`CREATE DATABASE` command](https://docs.mindsdb.com/mindsdb_sql/sql/create/database) , such as [Slack](https://docs.mindsdb.com/integrations/app-integrations/slack) or [MS Teams](https://docs.mindsdb.com/integrations/app-integrations/microsoft-teams) . ### [​](https://docs.mindsdb.com/mindsdb_sql/agents/chatbot#agent) `agent` The `agent` parameter stores the name of the agent created in MindsDB with the [`CREATE AGENT` command](https://docs.mindsdb.com/mindsdb_sql/agents/agent) . Alternatively, user can use the `model` parameter, instead of `agent`, to connect an LLM created in MindsDB with the [`CREATE MODEL` command](https://docs.mindsdb.com/mindsdb_sql/sql/create/model) . ### [​](https://docs.mindsdb.com/mindsdb_sql/agents/chatbot#is-running) `is_running` The `is_running` parameter defines whether the chatbot is going to be available right after its creation (`true`) or not (`false`). If it is set to `false`, users can enable it with this command. Copy Ask AI UPDATE CHATBOT my_chatbot SET is_running = true; Here are some tips for using the Slack integration: 1. If you want to use Slack in the [`CREATE CHATBOT`](https://docs.mindsdb.com/agents/chatbot) syntax, use [this method of connecting Slack to MindsDB](https://docs.mindsdb.com/integrations/app-integrations/slack#method-1-chatbot-responds-in-direct-messages-to-a-slack-app) . 2. If you want to connect the chatbot to multiple Slack channels, open your Slack application and add the App/Bot to one or more channels: * Go to the channel where you want to use the bot. * Right-click on the channel and select _View Channel Details_. * Select _Integrations_. * Click on _Add an App_. [​](https://docs.mindsdb.com/mindsdb_sql/agents/chatbot#drop-chatbot-syntax) `DROP CHATBOT` Syntax ----------------------------------------------------------------------------------------------------- Here is how to delete a chatbot: Copy Ask AI DROP CHATBOT my_chatbot; [​](https://docs.mindsdb.com/mindsdb_sql/agents/chatbot#example) Example --------------------------------------------------------------------------- Following the example from [here](https://docs.mindsdb.com/agents/agent#example) , let’s create a chatbot utilizing the already created agent. Start by connecting a chat app to MindsDB: * Follow [this instruction](https://docs.mindsdb.com/integrations/app-integrations/slack) to connect Slack to MindsDB. * Follow [this instruction](https://docs.mindsdb.com/integrations/app-integrations/microsoft-teams) to connect MS Teams to MindsDB. Next, create a chatbot. Copy Ask AI CREATE CHATBOT text_to_sql_chatbot USING database = 'my_slack', -- this must be created with CREATE DATABASE agent = 'text_to_sql_agent', -- this must be created with CREATE AGENT is_running = true; Follow [this tutorial](https://docs.mindsdb.com/use-cases/ai_agents/build_ai_agents) to build your own chatbot. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/mindsdb_sql/agents/chatbot.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/mindsdb_sql/agents/chatbot) ⌘I --- # Build a Chatbot with a Text2SQL Skill - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/ai_agents/create-chatbot#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Build a Chatbot with a Text2SQL Skill [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Chatbot Components](https://docs.mindsdb.com/use-cases/ai_agents/create-chatbot#chatbot-components) * [Chat App](https://docs.mindsdb.com/use-cases/ai_agents/create-chatbot#chat-app) * [AI Agent](https://docs.mindsdb.com/use-cases/ai_agents/create-chatbot#ai-agent) * [Create Chatbot](https://docs.mindsdb.com/use-cases/ai_agents/create-chatbot#create-chatbot) MindsDB provides the `CREATE CHATBOT` statement that lets you customize your chatbot with an AI model and a data source of your choice. Follow this tutorial to learn build a chatbot with a Text2SQL skill. The `CREATE CHATBOT` statement requires the following components: 1. **Chat app**: A connection to a chat app, such as [Slack](https://docs.mindsdb.com/integrations/app-integrations/slack#method-1-chatbot-responds-in-direct-messages-to-a-slack-app) or [MS Teams](https://docs.mindsdb.com/integrations/app-integrations/microsoft-teams) . 2. **AI agent**: An AI agent that comes with an AI model trained with the provided training data. Learn more about [AI agents here](https://docs.mindsdb.com/agents/agent) . Learn more about [chatbots here](https://docs.mindsdb.com/agents/chatbot) . Let’s go over getting all the components ready. [​](https://docs.mindsdb.com/use-cases/ai_agents/create-chatbot#chatbot-components) Chatbot Components --------------------------------------------------------------------------------------------------------- ### [​](https://docs.mindsdb.com/use-cases/ai_agents/create-chatbot#chat-app) Chat App Use the `CREATE DATABASE` statement to connect the chat app to MindsDB. If you want to use Slack, follow [this link](https://docs.mindsdb.com/integrations/app-integrations/slack#method-1-chatbot-responds-in-direct-messages-to-a-slack-app) to setup a Slack app, generate required tokens, and connect it to MindsDB.If you want to use MS Teams, follow [this link](https://docs.mindsdb.com/integrations/app-integrations/microsoft-teams) to generate required tokens and connect it to MindsDB. ### [​](https://docs.mindsdb.com/use-cases/ai_agents/create-chatbot#ai-agent) AI Agent Start by creating and deploying the model. If you haven’t created a LangChain engine, use the `CREATE ML_ENGINE` statement, as explained [here](https://docs.mindsdb.com/integrations/ai-engines/langchain#ai-engine) . Copy Ask AI CREATE MODEL my_model PREDICT answer USING engine = 'langchain', input_column = 'question', openai_api_key = 'your-model-api-key', -- choose one of OpenAI (openai_api_key) or Anthropic (anthropic_api_key) model_name='gpt-4', -- optional model name from OpenAI or Anthropic mode = 'conversational', user_column = 'question' , assistant_column = 'answer', max_tokens=100, temperature=0, verbose=True, prompt_template='Answer the user input in a helpful way'; Here is the command to check its status: Copy Ask AI DESCRIBE my_model; The status should read `complete` before proceeding. Next step is to create one or more skills for an AI agent. Here we create a Text2SQL skill. Copy Ask AI CREATE SKILL text_to_sql_skill USING type = 'text2sql', database = 'example_db', -- this is a data source that must be connected to MindsDB with CREATE DATABASE statement tables = ['sales_data'], -- this table comes from the connected example_db data source description = "Sales data that includes stores, sold products, and other sale details"; This skill enables a model to answer questions about data from the `sales_data` table. Now let’s create an AI agent using the above model and skill. Copy Ask AI CREATE AGENT support_agent USING model = 'my_model', -- this was created with CREATE MODEL skills = ['text_to_sql_skill']; -- this was created with CREATE SKILL [​](https://docs.mindsdb.com/use-cases/ai_agents/create-chatbot#create-chatbot) Create Chatbot ------------------------------------------------------------------------------------------------- Once all the components are ready, let’s proceed to creating the chatbot. Copy Ask AI CREATE CHATBOT my_chatbot USING database = 'chat_app', -- this parameters stores a connection to a chat app, like Slack or MS Teams agent = 'support_agent', -- this parameter stores an agent name, which was create with CREATE AGENT is_running = true; -- this parameter is optional and set to true by default, meaning that the chatbot is running The `database` parameter stores connection to a chat app. And the `agent` parameter stores an AI agent created by passing a model and training data. You can query all chatbot using this query: Copy Ask AI SELECT * FROM chatbots; Now you can go to Slack or MS Teams and chat with the chatbot created with MindsDB. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/ai_agents/create-chatbot.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/ai_agents/create-chatbot) ⌘I --- # MongoDB - MindsDB [Skip to main content](https://docs.mindsdb.com/integrations/data-integrations/mongodb#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation MongoDB [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Prerequisites](https://docs.mindsdb.com/integrations/data-integrations/mongodb#prerequisites) * [Connection](https://docs.mindsdb.com/integrations/data-integrations/mongodb#connection) * [Usage](https://docs.mindsdb.com/integrations/data-integrations/mongodb#usage) * [Troubleshooting Guide](https://docs.mindsdb.com/integrations/data-integrations/mongodb#troubleshooting-guide) This documentation describes the integration of MindsDB with [MongoDB](https://www.mongodb.com/company/what-is-mongodb) , a document database with the scalability and flexibility that you want with the querying and indexing that you need. [​](https://docs.mindsdb.com/integrations/data-integrations/mongodb#prerequisites) Prerequisites --------------------------------------------------------------------------------------------------- Before proceeding, ensure the following prerequisites are met: 1. Install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . [​](https://docs.mindsdb.com/integrations/data-integrations/mongodb#connection) Connection --------------------------------------------------------------------------------------------- Establish a connection to MongoDB from MindsDB by executing the following SQL command: Copy Ask AI CREATE DATABASE mongodb_datasource WITH ENGINE = 'mongodb', PARAMETERS = { "host": "mongodb+srv://admin:[email protected]/public" }; Use the following parameters to establish the connection: * `host`: The connection string of the MongoDB server that includes user (`admin`), password (`admin_pass`), host and port (`demo.mongodb.net`), and database (`public`). * `database`: If the connection string does not include the `/database` path, provide it in this parameter. Alternatively, the following set of connection parameters can be used: * `username`: The username associated with the database. * `password`: The password to authenticate your access. * `host`: The host of the MongoDB server. * `port`: The port through which TCP/IP connection is to be made. * `database`: The database name to be connected. [​](https://docs.mindsdb.com/integrations/data-integrations/mongodb#usage) Usage ----------------------------------------------------------------------------------- Retrieve data from a specified collection by providing the integration name and collection name: Copy Ask AI SELECT * FROM mongodb_datasource.my_collection LIMIT 10; The above examples utilize `mongodb_datasource` as the datasource name, which is defined in the `CREATE DATABASE` command. At the moment, this integration only supports `SELECT` and `UPDATE` queries. [​](https://docs.mindsdb.com/integrations/data-integrations/mongodb#troubleshooting-guide) Troubleshooting Guide ------------------------------------------------------------------------------------------------------------------- `Database Connection Error` * **Symptoms**: Failure to connect MindsDB with the MongoDB server. * **Checklist**: 1. Make sure the MongoDB server is active. 2. Confirm that host and credentials provided are correct. Try a direct MongoDB connection using a client like MongoDB Compass. 3. Ensure a stable network between MindsDB and MongoDB. For example, if you are using MongoDB Atlas, ensure that the IP address of the machine running MindsDB is whitelisted. `Unknown statement` * **Symptoms**: Errors related to the issuing of unsupported queries to MongoDB via the integration. * **Checklist**: 1. Ensure the query is a `SELECT` or `UPDATE` query. `SQL statement cannot be parsed by mindsdb_sql` * **Symptoms**: SQL queries failing or not recognizing collection names containing special characters. * **Checklist**: 1. Ensure table names with special characters are enclosed in backticks. 2. Examples: * Incorrect: SELECT \* FROM integration.travel-data * Incorrect: SELECT \* FROM integration.‘travel-data’ * Correct: SELECT \* FROM integration.\`travel-data\` Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/integrations/data-integrations/mongodb.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/data-integrations/mongodb) ⌘I --- # Configure an ML Engine - MindsDB [Skip to main content](https://docs.mindsdb.com/mindsdb_sql/sql/create/ml-engine#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Configure an ML Engine [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Description](https://docs.mindsdb.com/mindsdb_sql/sql/create/ml-engine#description) * [Syntax](https://docs.mindsdb.com/mindsdb_sql/sql/create/ml-engine#syntax) * [Example](https://docs.mindsdb.com/mindsdb_sql/sql/create/ml-engine#example) 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. [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/ml-engine#description) Description ----------------------------------------------------------------------------------------- The `CREATE ML_ENGINE` command creates an ML engine that uses one of the available AI/ML handlers. [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/ml-engine#syntax) 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. Copy Ask AI SELECT * FROM information_schema.handlers; -- or SHOW HANDLERS; If you can’t find the AI/ML handler of your interest, you can contribute by [building a new AI/ML handler](https://docs.mindsdb.com/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. If you find the AI/ML handler of your interest, then you can create an AI/ML engine using this command: Copy Ask AI 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. Please do not use the same `ml_engine_name` as the `handler_name` to avoid issue while dropping the ML engine. To verify that your AI/ML engine was successfully created, run the command below: Copy Ask AI SELECT * FROM information_schema.ml_engines; -- or SHOW ML_ENGINES; If you want to drop an ML engine, run the command below: Copy Ask AI DROP ML_ENGINE ml_engine_name; [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/ml-engine#example) Example --------------------------------------------------------------------------------- Let’s check what AI/ML handlers are currently available: Copy Ask AI SHOW HANDLERS; On execution, we get: Copy Ask AI +-------------------+--------------------+-------------------------------------------------------+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------+----------------+-----------------------------------------------------------------------------+ | NAME | TITLE | DESCRIPTION | VERSION | CONNECTION_ARGS | IMPORT_SUCCESS | IMPORT_ERROR | +-------------------+--------------------+-------------------------------------------------------+---------+-----------------------------------------------------------------------------------------------------------------------------------------------------+----------------+-----------------------------------------------------------------------------+ | "ray_serve" | "RayServe" | "MindsDB handler for Ray Serve" | "0.0.1" | "[NULL]" | "true" | "[NULL]" | | "neuralforecast" | "NeuralForecast" | "MindsDB handler for Nixtla's NeuralForecast package" | "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]" | | "ludwig" | "Ludwig" | "MindsDB handler for Ludwig AutoML" | "0.0.2" | "[NULL]" | "false" | "No module named 'dask'" | | "lightwood" | "Lightwood" | "[NULL]" | "1.0.0" | "[NULL]" | "true" | "[NULL]" | | "huggingface_api" | "Hugging Face API" | "MindsDB handler for Auto-Sklearn" | "0.0.2" | "[NULL]" | "false" | "No module named 'hugging_py_face'" | | "statsforecast" | "StatsForecast" | "MindsDB handler for Nixtla's StatsForecast package" | "0.0.0" | "[NULL]" | "true" | "[NULL]" | | "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. Copy Ask AI CREATE ML_ENGINE my_openai_engine FROM openai USING openai_api_key = ''; On execution, we get: Copy Ask AI Query successfully completed Now let’s verify that our ML engine exists. Copy Ask AI SHOW ML_ENGINES; On execution, we get: Copy Ask AI +-------------------+------------+------------------------------------------------------+ |NAME |HANDLER |CONNECTION_DATA | +-------------------+------------+------------------------------------------------------+ |lightwood |lightwood |{"key":["password"],"value":[""]} | |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: Copy Ask AI 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. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/mindsdb_sql/sql/create/ml-engine.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/mindsdb_sql/sql/create/ml-engine) ⌘I --- # Building a Twitter Chatbot with MindsDB and OpenAI - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/ai_workflow_automation/twitter-chatbot#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Building a Twitter Chatbot with MindsDB and OpenAI [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Deploy a GPT-4 model](https://docs.mindsdb.com/use-cases/ai_workflow_automation/twitter-chatbot#deploy-a-gpt-4-model) * [Connect Twitter to MindsDB](https://docs.mindsdb.com/use-cases/ai_workflow_automation/twitter-chatbot#connect-twitter-to-mindsdb) * [Automate replies to tweets](https://docs.mindsdb.com/use-cases/ai_workflow_automation/twitter-chatbot#automate-replies-to-tweets) In this tutorial, we’ll build a custom Twitter chatbot that replies to tweets with the help of the OpenAI GPT-4 model. The workflow will be automated using Jobs - a MindsDB feature that enables you to schedule execution of tasks. [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/twitter-chatbot#deploy-a-gpt-4-model) Deploy a GPT-4 model --------------------------------------------------------------------------------------------------------------------------- Please note that using OpenAI models require OpenAI API key. Therefore, before creating a model, you need to configure an engine by providing your OpenAI API key as below. See [docs](https://docs.mindsdb.com/integrations/ai-engines/openai) . Copy Ask AI CREATE ML_ENGINE openai_engine FROM openai USING openai_api_key = 'your-openai-api-key'; Let’s create a basic model to respond to tweets. Copy Ask AI CREATE MODEL gpt_model PREDICT response USING engine = 'openai_engine', model_name = 'gpt-4', prompt_template ='respond to {{text}} by {{author_username}}'; We can test the model by providing input data in the `WHERE` clause as below: Copy Ask AI SELECT response FROM gpt_model WHERE author_username = "mindsdb" AND text = "why is gravity so different on the sun?"; Now let’s add personality to our chatbot by modifying the `prompt_template` message: Copy Ask AI CREATE MODEL snoopstein_model PREDICT response USING engine = 'openai_engine', max_tokens = 300, temperature = 0.75, model_name = 'gpt-4', prompt_template = ' You are a twitter bot, your name is Snoop Stein (@snoop_stein), and you are helping people with their questions, you are smart and hilarious at the same time. From input message: {{text}} by from_user: {{author_username}} In less than 200 characters, write a Twitter response to {{author_username}} in the following format:\ Dear @, '2023-04-04 11:50:00'; And here is how to write tweets, providing a tweet id to reply to: Copy Ask AI INSERT INTO my_twitter.tweets (in_reply_to_tweet_id, text) VALUES (, 'Congratulations on the new release!'); [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/twitter-chatbot#automate-replies-to-tweets) Automate replies to tweets --------------------------------------------------------------------------------------------------------------------------------------- Now we put together all job components and automate the process. Copy Ask AI CREATE JOB twitter_chatbot ( INSERT INTO my_twitter.tweets ( SELECT d.id AS in_reply_to_tweet_id, m.response AS text FROM my_twitter.tweets AS d JOIN snoopstein_model AS m WHERE d.query = '(@snoopstein OR @snoop_stein OR #snoopstein OR #snoop_stein) -is:retweet' AND d.id > LAST ) ) EVERY minute; This job is executed every minute. It fetches all recently added tweets with the help of the [`LAST` keyword](https://docs.mindsdb.com/mindsdb_sql/sql/create/jobs#last) . Then, it prepares and posts the replies. Here are some useful commands to monitor the job: Copy Ask AI SHOW JOBS WHERE name = 'twitter_chatbot'; SELECT * FROM jobs WHERE name = 'twitter_chatbot'; SELECT * FROM log.jobs_history WHERE project = 'mindsdb' AND name = 'twitter_chatbot'; Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/ai_workflow_automation/twitter-chatbot.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/ai_workflow_automation/twitter-chatbot) ⌘I --- # Build an AI Agent with MindsDB - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/ai_agents/build_ai_agents#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Build an AI Agent with MindsDB [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Step-by-Step Tutorial](https://docs.mindsdb.com/use-cases/ai_agents/build_ai_agents#step-by-step-tutorial) * [Step 1. Create a conversational model](https://docs.mindsdb.com/use-cases/ai_agents/build_ai_agents#step-1-create-a-conversational-model) * [Step 2. Create skills](https://docs.mindsdb.com/use-cases/ai_agents/build_ai_agents#step-2-create-skills) * [Step 3. Create an AI agent](https://docs.mindsdb.com/use-cases/ai_agents/build_ai_agents#step-3-create-an-ai-agent) * [Step 4. Create a chatbot](https://docs.mindsdb.com/use-cases/ai_agents/build_ai_agents#step-4-create-a-chatbot) MindsDB provides a custom syntax to build AI agents that comprises an AI model augmented with users’ data access. AI agents can be connected to a chat interface, like Slack or MS Teams, to create chatbots. See details following [this link for Agents](https://docs.mindsdb.com/mindsdb_sql/agents/agent) and [this link for Chatbots](https://docs.mindsdb.com/mindsdb_sql/agents/chatbot) . [​](https://docs.mindsdb.com/use-cases/ai_agents/build_ai_agents#step-by-step-tutorial) Step-by-Step Tutorial ---------------------------------------------------------------------------------------------------------------- This tutorial demonstrates how to build AI agents with MindsDB using MindsDB SQL editor. This can be also accomplished with [APIs](https://docs.mindsdb.com/rest/agents/create-agent) and [Python SDK](https://docs.mindsdb.com/sdks/python/agents) . Let’s list all the steps required to build an AI agent. 1 Create a conversational model Create a conversational model using the [LangChain integration](https://docs.mindsdb.com/integrations/ai-engines/langchain) . 2 Create skills Create one or more skills to be assigned to an agent. _Note that skills store data to be passed to an agent, so it is required to connect users’ data to MindsDB before creating skills._ 3 Create an AI agent Create an AI agent providing the conversational model and the set of skills. 4 Create a chatbot Optionally, connect an agent to a chat interface to create a chatbot. The following sections walk you through the process of building an AI agent. [​](https://docs.mindsdb.com/use-cases/ai_agents/build_ai_agents#step-1-create-a-conversational-model) Step 1. Create a conversational model ----------------------------------------------------------------------------------------------------------------------------------------------- Use the `CREATE MODEL` statement below to create a conversational model. If required, adjust the parameters and prompts to fit your use case. Copy Ask AI CREATE MODEL conversational_model PREDICT answer USING engine = 'langchain', openai_api_key = 'YOUR_OPENAI_API_KEY_HERE', model_name = 'gpt-4', mode = 'conversational', user_column = 'question' , assistant_column = 'answer', max_tokens = 100, temperature = 0, verbose = True, prompt_template = 'Answer the user input in a helpful way'; Ensure that the model status reads `complete` using this command: Copy Ask AI DESCRIBE conversational_model; Learn more about [models created with LangChain](https://docs.mindsdb.com/integrations/ai-engines/langchain) . [​](https://docs.mindsdb.com/use-cases/ai_agents/build_ai_agents#step-2-create-skills) Step 2. Create skills --------------------------------------------------------------------------------------------------------------- A skill is essentially users’ data fed to the model, so the model can answer questions over users’ data. First, connect your database to MindsDB. Here the sample database is used. Copy Ask AI CREATE DATABASE datasource WITH ENGINE = "postgres", PARAMETERS = { "user": "demo_user", "password": "demo_password", "host": "samples.mindsdb.com", "port": "5432", "database": "demo", "schema": "demo_data" }; Create a skill using the connected data. Copy Ask AI CREATE SKILL text2sql_skill USING type = 'text2sql', database = 'datasource', -- connect your database with CREATE DATABASE and pass its name here tables = ['car_sales'], -- list table(s) to be made accessible by an agent description = 'this is car sales data'; Note that there are two types of skills: text-to-SQL and knowledge bases. Learn more about [skills here](https://docs.mindsdb.com/mindsdb_sql/agents/agent#create-skills) . Verify that the skill has been created successully using this command: Copy Ask AI SHOW SKILLS; [​](https://docs.mindsdb.com/use-cases/ai_agents/build_ai_agents#step-3-create-an-ai-agent) Step 3. Create an AI agent ------------------------------------------------------------------------------------------------------------------------- Now that both the conversational model and the skill are ready, let’s create an AI agent. Copy Ask AI CREATE AGENT ai_agent USING model = 'conversational_model', skills = ['text2sql_skill']; Verify that the agent has been created successully using this command: Copy Ask AI SHOW AGENTS; At this point, you can query an agent to ask questions over the data. Copy Ask AI SELECT question, answer FROM ai_agent WHERE question = 'how many cars were sold in 2016?'; [​](https://docs.mindsdb.com/use-cases/ai_agents/build_ai_agents#step-4-create-a-chatbot) Step 4. Create a chatbot --------------------------------------------------------------------------------------------------------------------- Optionally, you can create a chatbot by connecitng an AI agent to a chat interface. First connect a chat interface to MindsDB. Here the Slack connection is made. Copy Ask AI CREATE DATABASE mindsdb_slack WITH ENGINE = 'slack', PARAMETERS = { "token": "xoxb-xxx", "app_token": "xapp-xxx" }; Follow the instructions on how to [connect Slack to MindsDB](https://docs.mindsdb.com/integrations/app-integrations/slack#method-1-chatbot-responds-in-direct-messages-to-a-slack-app) for this use case. Now create a chatbot providing the AI agent and the Slack connection. Copy Ask AI CREATE CHATBOT ai_chatbot USING database = 'mindsdb_slack', -- connect a chat interface with CREATE DATABASE agent = 'ai_agent'; -- create an agent with with CREATE AGENT Verify that the chatbot is running using this command: Copy Ask AI SHOW CHATBOTS; Now you can go ahead and chat with the AI agent via Slack. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/ai_agents/build_ai_agents.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/ai_agents/build_ai_agents) ⌘I --- # Get a Single Prediction - MindsDB [Skip to main content](https://docs.mindsdb.com/mindsdb_sql/sql/get-single-prediction#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Get a Single Prediction [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Description](https://docs.mindsdb.com/mindsdb_sql/sql/get-single-prediction#description) * [Syntax](https://docs.mindsdb.com/mindsdb_sql/sql/get-single-prediction#syntax) * [Example](https://docs.mindsdb.com/mindsdb_sql/sql/get-single-prediction#example) [​](https://docs.mindsdb.com/mindsdb_sql/sql/get-single-prediction#description) Description ---------------------------------------------------------------------------------------------- The `SELECT` statement fetches predictions from the model table. The data is returned on the fly and the result set is not persisted. But there are ways to save predictions data! You can save your predictions as a view using the [`CREATE VIEW`](https://docs.mindsdb.com/sql/create/view) statement. Please note that a view is a saved query and does not store data like a table. Another way is to create a table using the [`CREATE TABLE`](https://docs.mindsdb.com/sql/create/table) statement or insert your predictions into an existing table using the [`INSERT INTO`](https://docs.mindsdb.com/sql/api/insert) statement. [​](https://docs.mindsdb.com/mindsdb_sql/sql/get-single-prediction#syntax) Syntax ------------------------------------------------------------------------------------ Here is the syntax for fetching a single prediction from the model table: Copy Ask AI SELECT target_name, target_name_explain FROM mindsdb.predictor_name WHERE column_name = value AND column_name = value; **Grammar Matters**Here are some points to keep in mind while writing queries in MindsDB:    1. The `column_name = value` pairs may be joined by `AND` or `OR` keywords.    2. Do not use any quotations for numerical values.    3. Use single quotes for strings.    4. The tables and column names are case sensitive. On execution, we get: Copy Ask AI +-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | target_name | target_name_explain | +-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | predicted_value | {"predicted_value": 4394, "confidence": 0.99, "anomaly": null, "truth": null, "confidence_lower_bound": 4313, "confidence_upper_bound": 4475} | +-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ Where: | Name | Description | | --- | --- | | `target_name` | Name of the column to be predicted. | | `target_name_explain` | Object of the JSON type that contains the `predicted_value` and additional information such as `confidence`, `anomaly`, `truth`, `confidence_lower_bound`, `confidence_upper_bound`. | | `predictor_name` | Name of the model used to make the prediction. | | `WHERE column_name = value AND ...` | `WHERE` clause used to pass the data values for which the prediction is made. | [​](https://docs.mindsdb.com/mindsdb_sql/sql/get-single-prediction#example) Example -------------------------------------------------------------------------------------- Let’s predict the `rental_price` value using the `home_rentals_model` model for the property having `sqft=823`, `location='good'`, `neighborhood='downtown'`, and `days_on_market=10`. Copy Ask AI SELECT sqft, location, neighborhood, days_on_market, rental_price, rental_price_explain FROM mindsdb.home_rentals_model1 WHERE sqft=823 AND location='good' AND neighborhood='downtown' AND days_on_market=10; On execution, we get: Copy Ask AI +-------+----------+--------------+----------------+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | sqft | location | neighborhood | days_on_market | rental_price | rental_price_explain | +-------+----------+--------------+----------------+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | 823 | good | downtown | 10 | 4394 | {"predicted_value": 4394, "confidence": 0.99, "anomaly": null, "truth": null, "confidence_lower_bound": 4313, "confidence_upper_bound": 4475} | +-------+----------+--------------+----------------+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/mindsdb_sql/sql/get-single-prediction.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/mindsdb_sql/sql/get-single-prediction) ⌘I --- # Setup for Linux via pip - MindsDB [Skip to main content](https://docs.mindsdb.com/setup/self-hosted/pip/linux#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Setup for Linux via pip [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Installation using the Python venv Module](https://docs.mindsdb.com/setup/self-hosted/pip/linux#installation-using-the-python-venv-module) * [Installation using Anaconda](https://docs.mindsdb.com/setup/self-hosted/pip/linux#installation-using-anaconda) * [Dependencies](https://docs.mindsdb.com/setup/self-hosted/pip/linux#dependencies) * [Troubleshooting](https://docs.mindsdb.com/setup/self-hosted/pip/linux#troubleshooting) * [Pip and Python Versions](https://docs.mindsdb.com/setup/self-hosted/pip/linux#pip-and-python-versions) * [How to Avoid Dependency Issues](https://docs.mindsdb.com/setup/self-hosted/pip/linux#how-to-avoid-dependency-issues) * [How to Avoid Common Errors](https://docs.mindsdb.com/setup/self-hosted/pip/linux#how-to-avoid-common-errors) * [Further Issues?](https://docs.mindsdb.com/setup/self-hosted/pip/linux#further-issues) * [What’s Next](https://docs.mindsdb.com/setup/self-hosted/pip/linux#what%E2%80%99s-next) To successfully install MindsDB, use **Python 64-bit version**. Also, make sure that **Python >= 3.10** and **pip >= 20.3**. [​](https://docs.mindsdb.com/setup/self-hosted/pip/linux#installation-using-the-python-venv-module) Installation using the Python [`venv`](https://docs.python.org/3/library/venv.html) Module -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1. Create a new virtual environment called `mindsdb`: Copy Ask AI python -m venv mindsdb Now, activate it: Copy Ask AI source mindsdb/bin/activate 2. Once inside the virtual environment, run the command below to mitigate the dependency issues: Copy Ask AI pip install --upgrade pip setuptools wheel 3. Install MindsDB: Copy Ask AI pip install mindsdb 4. Start MindsDB: Copy Ask AI python -m mindsdb By default, MindsDB starts the `http` and `mysql` APIs. You can define which APIs to start using the `api` flag as below. Copy Ask AI python -m mindsdb --api http,mysql,postgres If you want to start MindsDB without the graphical user interface (GUI), use the `--no_studio` flag as below. Copy Ask AI python -m mindsdb --no_studio [​](https://docs.mindsdb.com/setup/self-hosted/pip/linux#installation-using-anaconda) Installation using Anaconda -------------------------------------------------------------------------------------------------------------------- Here, you need either [Anaconda](https://www.anaconda.com/products/individual) or [Conda](https://conda.io/projects/conda/en/latest/index.html) installed on your machine. 1. Open Anaconda prompt and create a new virtual environment: Copy Ask AI conda create -n mindsdb Now, activate it: Copy Ask AI conda activate mindsdb 2. Once inside the virtual environment, run the command below to mitigate the dependency issues: Copy Ask AI pip install --upgrade pip setuptools wheel 3. Install MindsDB: Copy Ask AI pip install mindsdb 4. Start MindsDB: Copy Ask AI python -m mindsdb By default, MindsDB starts the `http` and `mysql` APIs. You can define which APIs to start using the `api` flag as below. Copy Ask AI python -m mindsdb --api http,mysql,postgres If you want to start MindsDB without the graphical user interface (GUI), use the `--no_studio` flag as below. Copy Ask AI python -m mindsdb --no_studio [​](https://docs.mindsdb.com/setup/self-hosted/pip/linux#dependencies) Dependencies -------------------------------------------------------------------------------------- The dependencies for many of the data or ML integrations are not installed by default. If you want to use a data or ML integration whose dependencies are not available by default, install it by running this command: Copy Ask AI pip install mindsdb[handler_name] You can find all available [handlers here](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers) . [​](https://docs.mindsdb.com/setup/self-hosted/pip/linux#troubleshooting) Troubleshooting -------------------------------------------------------------------------------------------- ### [​](https://docs.mindsdb.com/setup/self-hosted/pip/linux#pip-and-python-versions) Pip and Python Versions Currently, MindsDB supports Python versions 3.10.x, and 3.11.x. To successfully install MindsDB, use **Python 64-bit version**. Also, make sure that **Python >= 3.10** and **pip >= 20.3**. You can check the pip and python versions by running the `pip --version` and `python --version` commands. Please note that depending on your environment and installed pip and python packages, you might have to use **pip3** instead of **pip** or **python3.x** instead of **py**. For example, `pip3 install mindsdb` instead of `pip install mindsdb`. ### [​](https://docs.mindsdb.com/setup/self-hosted/pip/linux#how-to-avoid-dependency-issues) How to Avoid Dependency Issues Install MindsDB in a virtual environment using **pip** to avoid dependency issues. Or you could try to install MindsDB with [Anaconda](https://www.anaconda.com/products/individual) and run the installation from the **Anaconda prompt**. ### [​](https://docs.mindsdb.com/setup/self-hosted/pip/linux#how-to-avoid-common-errors) How to Avoid Common Errors MindsDB requires around 3 GB of free disk space to install all of its dependencies. Make sure to allocate min. 3 GB of disk space to avoid the `IOError: [Errno 28] No space left on device while installing MindsDB` error. Before anything, activate your virtual environment where your MindsDB is installed. It is to avoid the `No module named mindsdb` error. [​](https://docs.mindsdb.com/setup/self-hosted/pip/linux#further-issues) Further Issues? ------------------------------------------------------------------------------------------- You can try to replicate your issue using the [Docker setup](https://docs.mindsdb.com/setup/self-hosted/docker) . Also, please create an issue with detailed description in the [MindsDB GitHub repository](https://github.com/mindsdb/mindsdb/issues) so we can help you. Usually, we review issues and respond within a few hours. [​](https://docs.mindsdb.com/setup/self-hosted/pip/linux#what%E2%80%99s-next) What’s Next -------------------------------------------------------------------------------------------- Now that you installed and started MindsDB locally in your Docker container, go ahead and find out how to create and train a model using the [`CREATE MODEL`](https://docs.mindsdb.com/sql/create/model) statement. In the **MindsDB SQL** section, you’ll find a comprehensive overview of the SQL syntax offered by MindsDB. You can connect MindsDB to different clients, including [PostgreSQL CLI](https://docs.mindsdb.com/connect/postgres-client) and [MySQL CLI](https://docs.mindsdb.com/connect/mysql-client) . Check out the [Use Cases](https://docs.mindsdb.com/use-cases/overview) section to follow tutorials that cover Large Language Models, Natural Language Processing, Time Series, Classification, and Regression models. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/setup/self-hosted/pip/linux.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/setup/self-hosted/pip/linux) ⌘I --- # Get Batch Predictions - MindsDB [Skip to main content](https://docs.mindsdb.com/mindsdb_sql/sql/get-batch-predictions#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Get Batch Predictions [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Description](https://docs.mindsdb.com/mindsdb_sql/sql/get-batch-predictions#description) * [Syntax](https://docs.mindsdb.com/mindsdb_sql/sql/get-batch-predictions#syntax) * [Example](https://docs.mindsdb.com/mindsdb_sql/sql/get-batch-predictions#example) [​](https://docs.mindsdb.com/mindsdb_sql/sql/get-batch-predictions#description) Description ---------------------------------------------------------------------------------------------- The `SELECT` statement fetches predictions from the model table. The data is returned on the fly and the result set is not persisted. But there are ways to save predictions data! You can save your predictions as a view using the [`CREATE VIEW`](https://docs.mindsdb.com/sql/create/view) statement. Please note that a view is a saved query and does not store data like a table. Another way is to create a table using the [`CREATE TABLE`](https://docs.mindsdb.com/sql/create/table) statement or insert your predictions into an existing table using the [`INSERT INTO`](https://docs.mindsdb.com/sql/api/insert) statement. [​](https://docs.mindsdb.com/mindsdb_sql/sql/get-batch-predictions#syntax) Syntax ------------------------------------------------------------------------------------ Here is the syntax for making batch predictions by joining one or more data source tables with one or more model tables: Copy Ask AI SELECT t1.column, t2.column, m1.target, m2.target FROM integration_name.table_name1 AS t1 JOIN integration_name.table_name2 AS t2 ON t1.column = t2.column JOIN ... JOIN mindsdb.model_name1 AS m1 JOIN mindsdb.model_name2 AS m2 JOIN ... [ON t1.input_data = m1.expected_argument] WHERE m1.parameter = 'value' AND m2.parameter = 'value'; Where: * There are the data tables that provide input to the models: `integration_name.table_name1`, `integration_name.table_name2`. * These are the AI tables: `mindsdb.model_name1`, `mindsdb.model_name2`. Note that you can provide input to the models from the data tables and also in the `WHERE` clause. When querying for predictions, you can specify the `partition_size` parameter to split data into partitions and run prediction on different workers. Note that the [ML task queue](https://docs.mindsdb.com/setup/custom-config#overview-of-config-parameters) needs to be enabled to use this parameter.To use the `partition_size` parameter, provide it in the `USING` clause, specifying the partition size, like this: Copy Ask AI ... USING partition_size=100 Follow [this doc page](https://docs.mindsdb.com/generative-ai-tables) to learn more about AI Tables. [​](https://docs.mindsdb.com/mindsdb_sql/sql/get-batch-predictions#example) Example -------------------------------------------------------------------------------------- Let’s make bulk predictions to predict the `rental_price` value using the `home_rentals_model` model joined with the data source table. Copy Ask AI SELECT t.sqft, t.location, t.neighborhood, t.days_on_market, t.rental_price AS real_price, m.rental_price AS predicted_rental_price FROM example_db.demo_data.home_rentals AS t JOIN mindsdb.home_rentals_model AS m LIMIT 5; On execution, we get: Copy Ask AI +-------+----------+-----------------+----------------+--------------+-----------------------------+ | sqft | location | neighborhood | days_on_market | real_price | predicted_rental_price | +-------+----------+-----------------+----------------+--------------+-----------------------------+ | 917 | great | berkeley_hills | 13 | 3901 | 3886 | | 194 | great | berkeley_hills | 10 | 2042 | 2007 | | 543 | poor | westbrae | 18 | 1871 | 1865 | | 503 | good | downtown | 10 | 3026 | 3020 | | 1066 | good | thowsand_oaks | 13 | 4774 | 4748 | +-------+----------+-----------------+----------------+--------------+-----------------------------+ Follow [this doc page](https://docs.mindsdb.com/generative-ai-tables#working-with-generative-ai-tables) to see examples of joining multiple data table with multiple models. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/mindsdb_sql/sql/get-batch-predictions.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/mindsdb_sql/sql/get-batch-predictions) ⌘I --- # Setup for MacOS via pip - MindsDB [Skip to main content](https://docs.mindsdb.com/setup/self-hosted/pip/macos#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Setup for MacOS via pip [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Installation using the Python venv Module](https://docs.mindsdb.com/setup/self-hosted/pip/macos#installation-using-the-python-venv-module) * [Installation using Anaconda](https://docs.mindsdb.com/setup/self-hosted/pip/macos#installation-using-anaconda) * [Dependencies](https://docs.mindsdb.com/setup/self-hosted/pip/macos#dependencies) * [Troubleshooting](https://docs.mindsdb.com/setup/self-hosted/pip/macos#troubleshooting) * [Pip and Python Versions](https://docs.mindsdb.com/setup/self-hosted/pip/macos#pip-and-python-versions) * [How to Avoid Dependency Issues](https://docs.mindsdb.com/setup/self-hosted/pip/macos#how-to-avoid-dependency-issues) * [How to Avoid Common Errors](https://docs.mindsdb.com/setup/self-hosted/pip/macos#how-to-avoid-common-errors) * [Further Issues?](https://docs.mindsdb.com/setup/self-hosted/pip/macos#further-issues) * [What’s Next](https://docs.mindsdb.com/setup/self-hosted/pip/macos#what%E2%80%99s-next) To successfully install MindsDB, use **Python 64-bit version**. Also, make sure that **Python >= 3.10** and **pip >= 20.3**. [​](https://docs.mindsdb.com/setup/self-hosted/pip/macos#installation-using-the-python-venv-module) Installation using the Python [`venv`](https://docs.python.org/3/library/venv.html) Module -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1. Create a new virtual environment called `mindsdb`: Copy Ask AI python -m venv mindsdb Now, activate it: Copy Ask AI source mindsdb/bin/activate 2. Once inside the virtual environment, run the command below to mitigate the dependency issues: Copy Ask AI pip install --upgrade pip setuptools wheel 3. Install MindsDB: Copy Ask AI pip install mindsdb 4. Start MindsDB: Copy Ask AI python -m mindsdb By default, MindsDB starts the `http` and `mysql` APIs. You can define which APIs to start using the `api` flag as below. Copy Ask AI python -m mindsdb --api http,mysql,postgres If you want to start MindsDB without the graphical user interface (GUI), use the `--no_studio` flag as below. Copy Ask AI python -m mindsdb --no_studio [​](https://docs.mindsdb.com/setup/self-hosted/pip/macos#installation-using-anaconda) Installation using Anaconda -------------------------------------------------------------------------------------------------------------------- Here, you need either [Anaconda](https://www.anaconda.com/products/individual) or [Conda](https://conda.io/projects/conda/en/latest/index.html) installed on your machine. 1. Open Anaconda prompt and create a new virtual environment: Copy Ask AI conda create -n mindsdb Now, activate it: Copy Ask AI conda activate mindsdb 2. Once inside the virtual environment, run the command below to mitigate the dependency issues: Copy Ask AI pip install --upgrade pip setuptools wheel 3. Install MindsDB: Copy Ask AI pip install mindsdb 4. Start MindsDB: Copy Ask AI python -m mindsdb By default, MindsDB starts the `http` and `mysql` APIs. You can define which APIs to start using the `api` flag as below. Copy Ask AI python -m mindsdb --api http,mysql,postgres If you want to start MindsDB without the graphical user interface (GUI), use the `--no_studio` flag as below. Copy Ask AI python -m mindsdb --no_studio [​](https://docs.mindsdb.com/setup/self-hosted/pip/macos#dependencies) Dependencies -------------------------------------------------------------------------------------- The dependencies for many of the data or ML integrations are not installed by default. If you want to use a data or ML integration whose dependencies are not available by default, install it by running this command: Copy Ask AI pip install mindsdb[handler_name] You can find all available [handlers here](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers) . [​](https://docs.mindsdb.com/setup/self-hosted/pip/macos#troubleshooting) Troubleshooting -------------------------------------------------------------------------------------------- ### [​](https://docs.mindsdb.com/setup/self-hosted/pip/macos#pip-and-python-versions) Pip and Python Versions Currently, MindsDB supports Python versions 3.10.x, 3.10.x, and 3.11.x. To successfully install MindsDB, use **Python 64-bit version**. Also, make sure that **Python >= 3.10** and **pip >= 20.3**. You can check the pip and python versions by running the `pip --version` and `python --version` commands. Please note that depending on your environment and installed pip and python packages, you might have to use **pip3** instead of **pip** or **python3.x** instead of **py**. For example, `pip3 install mindsdb` instead of `pip install mindsdb`. ### [​](https://docs.mindsdb.com/setup/self-hosted/pip/macos#how-to-avoid-dependency-issues) How to Avoid Dependency Issues Install MindsDB in a virtual environment using **pip** to avoid dependency issues. Or you could try to install MindsDB with [Anaconda](https://www.anaconda.com/products/individual) and run the installation from the **Anaconda prompt**. ### [​](https://docs.mindsdb.com/setup/self-hosted/pip/macos#how-to-avoid-common-errors) How to Avoid Common Errors MindsDB requires around 3 GB of free disk space to install all of its dependencies. Make sure to allocate min. 3 GB of disk space to avoid the `IOError: [Errno 28] No space left on device while installing MindsDB` error. Before anything, activate your virtual environment where your MindsDB is installed. It is to avoid the `No module named mindsdb` error. Some users can get `OSError: dlopen Library not loaded 'libomp.dylib'`. Please make sure you have installed `libomp` and run the export commands. Copy Ask AI brew install libomp export LDFLAGS="-L/usr/local/opt/libomp/lib" export CPPFLAGS="-I/usr/local/opt/libomp/include" [​](https://docs.mindsdb.com/setup/self-hosted/pip/macos#further-issues) Further Issues? ------------------------------------------------------------------------------------------- You can try to replicate your issue using the [Docker setup](https://docs.mindsdb.com/setup/self-hosted/docker) . Also, please create an issue with detailed description in the [MindsDB GitHub repository](https://github.com/mindsdb/mindsdb/issues) so we can help you. Usually, we review issues and respond within a few hours. [​](https://docs.mindsdb.com/setup/self-hosted/pip/macos#what%E2%80%99s-next) What’s Next -------------------------------------------------------------------------------------------- Now that you installed and started MindsDB locally in your Docker container, go ahead and find out how to create and train a model using the [`CREATE MODEL`](https://docs.mindsdb.com/sql/create/model) statement. In the **MindsDB SQL** section, you’ll find a comprehensive overview of the SQL syntax offered by MindsDB. You can connect MindsDB to different clients, including [PostgreSQL CLI](https://docs.mindsdb.com/connect/postgres-client) and [MySQL CLI](https://docs.mindsdb.com/connect/mysql-client) . Check out the [Use Cases](https://docs.mindsdb.com/use-cases/overview) section to follow tutorials that cover Large Language Models, Natural Language Processing, Time Series, Classification, and Regression models. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/setup/self-hosted/pip/macos.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/setup/self-hosted/pip/macos) ⌘I --- # Text Summarization with MindsDB and OpenAI using SQL - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/data_enrichment/text-summarization-inside-mysql-with-openai#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Text Summarization with MindsDB and OpenAI using SQL [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Introduction](https://docs.mindsdb.com/use-cases/data_enrichment/text-summarization-inside-mysql-with-openai#introduction) * [Prerequisites](https://docs.mindsdb.com/use-cases/data_enrichment/text-summarization-inside-mysql-with-openai#prerequisites) * [Tutorial](https://docs.mindsdb.com/use-cases/data_enrichment/text-summarization-inside-mysql-with-openai#tutorial) * [Leverage the NLP Capabilities with MindsDB](https://docs.mindsdb.com/use-cases/data_enrichment/text-summarization-inside-mysql-with-openai#leverage-the-nlp-capabilities-with-mindsdb) * [What’s Next?](https://docs.mindsdb.com/use-cases/data_enrichment/text-summarization-inside-mysql-with-openai#what%E2%80%99s-next) [​](https://docs.mindsdb.com/use-cases/data_enrichment/text-summarization-inside-mysql-with-openai#introduction) Introduction -------------------------------------------------------------------------------------------------------------------------------- In this blog post, we present how to create OpenAI models within MindsDB. In this example, we ask a model to provide a summary of a text. The input data is taken from our sample MySQL database. [​](https://docs.mindsdb.com/use-cases/data_enrichment/text-summarization-inside-mysql-with-openai#prerequisites) Prerequisites ---------------------------------------------------------------------------------------------------------------------------------- To follow along, install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . [​](https://docs.mindsdb.com/use-cases/data_enrichment/text-summarization-inside-mysql-with-openai#tutorial) Tutorial ------------------------------------------------------------------------------------------------------------------------ In this tutorial, we create a predictive model to summarize an article. We use a table from our MySQL public demo database, so let’s start by connecting MindsDB to it: Copy Ask AI CREATE DATABASE mysql_demo_db WITH ENGINE = 'mysql', PARAMETERS = { "user": "user", "password": "MindsDBUser123!", "host": "samples.mindsdb.com", "port": "3306", "database": "public" }; Now that we’ve connected our database to MindsDB, let’s query the data to be used in the example: Copy Ask AI SELECT * FROM mysql_demo_db.articles LIMIT 3; Here is the output: Copy Ask AI +----------------------------------------------------------------+--------------------------------------------------------------+ | article | highlights | +----------------------------------------------------------------+--------------------------------------------------------------+ | Video footage has emerged of a law enforcement officer… | The 53-second video features… | | A new restaurant is offering a five-course drink-paired menu… | The Curious Canine Kitchen is… | | Mother-of-two Anna Tilley survived after spending four days… | Experts have warned hospitals not using standard treatment… | +----------------------------------------------------------------+--------------------------------------------------------------+ Let’s create a model table to summarize all articles from the input dataset: Before creating an OpenAI model, please create an engine, providing your OpenAI API key: Copy Ask AI CREATE ML_ENGINE openai_engine FROM openai USING openai_api_key = 'your-openai-api-key'; Copy Ask AI CREATE MODEL text_summarization_model PREDICT highlights USING engine = 'openai_engine', prompt_template = 'provide an informative summary of the text text:{{article}} using full sentences'; In practice, the `CREATE MODEL` statement triggers MindsDB to generate an AI table called `text_summarization_model` that uses the OpenAI integration to predict a column named `highlights`. The model lives inside the default `mindsdb` project. In MindsDB, projects are a natural way to keep artifacts, such as models or views, separate according to what predictive task they solve. You can learn more about MindsDB projects [here](https://docs.mindsdb.com/sql/project) . The `USING` clause specifies the parameters that this handler requires. * The `engine` parameter defines that we use the `openai` engine. * The `prompt_template` parameter conveys the structure of a message that is to be completed with additional text generated by the model. Follow [this instruction](https://docs.mindsdb.com/integrations/ai-engines/openai#setup) to set up the OpenAI integration in MindsDB. Once the `CREATE MODEL` statement has started execution, we can check the status of the creation process with the following query: Copy Ask AI DESCRIBE text_summarization_model; It may take a while to register as complete depending on the internet connection. Once the creation is complete, the behavior is the same as with any other AI table – you can query it either by specifying synthetic data in the actual query: Copy Ask AI SELECT article, highlights FROM text_summarization_model WHERE article = "Apple's Watch hits stores this Friday when customers and employees alike will be able to pre-order the timepiece. And boss Tim Cook is rewarding his staff by offering them a 50 per cent discount on the device."; Here is the output data: Copy Ask AI +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------+ | article | highlights | +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------+ | Apple's Watch hits stores this Friday when customers and employees alike will be able to pre-order the timepiece. And boss Tim Cook is rewarding his staff by offering them a 50 per cent discount on the device. | Apple's Watch hits stores this Friday, and employees will be able to pre-order the | +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------+ Or by joining with another table for batch predictions: Copy Ask AI SELECT input.article, output.highlights FROM mysql_demo_db.articles AS input JOIN text_summarization_model AS output LIMIT 3; Here is the output data: Copy Ask AI +----------------------------------------------------------------+------------------------------------------------------------------------------------------------+ | article | highlights | +----------------------------------------------------------------+------------------------------------------------------------------------------------------------+ | Video footage has emerged of a law enforcement officer… | A video has emerged of a law enforcement officer grabbing a cell phone from a woman who was | | A new restaurant is offering a five-course drink-paired menu… | A new restaurant in London is offering a five-course drink-paired menu for dogs | | Mother-of-two Anna Tilley survived after spending four days… | Sepsis is a potentially life-threatening condition that occurs when the body's response to an | +----------------------------------------------------------------+------------------------------------------------------------------------------------------------+ The `articles` table is used to make batch predictions. Upon joining the `text_summarization_model` model with the `articles` table, the model uses all values from the `article` column. [​](https://docs.mindsdb.com/use-cases/data_enrichment/text-summarization-inside-mysql-with-openai#leverage-the-nlp-capabilities-with-mindsdb) Leverage the NLP Capabilities with MindsDB -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- By integrating databases and OpenAI using MindsDB, developers can easily extract insights from text data with just a few SQL commands. These powerful natural language processing (NLP) models are capable of answering questions with or without context and completing general prompts. Furthermore, these models are powered by large pre-trained language models from OpenAI, so there is no need for manual development work. Ultimately, this provides developers with an easy way to incorporate powerful NLP capabilities into their applications while saving time and resources compared to traditional ML development pipelines and methods. All in all, MindsDB makes it possible for developers to harness the power of OpenAI efficiently! MindsDB is now the fastest-growing open-source applied machine-learning platform in the world. Its community continues to contribute to more than 70 data-source and ML-framework integrations. Stay tuned for the upcoming features - including more control over the interface parameters and fine-tuning models directly from MindsDB! Experiment with OpenAI models within MindsDB and unlock the ML capability over your data in minutes. Finally, if MindsDB’s vision to democratize ML sounds exciting, head to our [community Slack](https://mindsdb.com/joincommunity) , where you can get help and find people to chat about using other available data sources, ML frameworks, or writing a handler to bring your own! Follow our introduction to MindsDB’s OpenAI integration [here](https://mindsdb.com/blog/extract-insights-from-text-inside-databases-using-openai-gpt3-and-mindsdb-integration) . Also, we’ve got a variety of tutorials that use MySQL and MongoDB: * [Sentiment Analysis in MySQL](https://docs.mindsdb.com/nlp/sentiment-analysis-inside-mysql-with-openai) * [Question Answering in MySQL](https://docs.mindsdb.com/nlp/question-answering-inside-mysql-with-openai) * [Sentiment Analysis in MongoDB](https://docs.mindsdb.com/nlp/sentiment-analysis-inside-mongodb-with-openai) * [Question Answering in MongoDB](https://docs.mindsdb.com/nlp/question-answering-inside-mongodb-with-openai) * [Text Summarization in MongoDB](https://docs.mindsdb.com/nlp/text-summarization-inside-mongodb-with-openai) [​](https://docs.mindsdb.com/use-cases/data_enrichment/text-summarization-inside-mysql-with-openai#what%E2%80%99s-next) What’s Next? --------------------------------------------------------------------------------------------------------------------------------------- Have fun while trying it out yourself! * Bookmark [MindsDB repository on GitHub](https://github.com/mindsdb/mindsdb) . * Engage with the MindsDB community on [Slack](https://mindsdb.com/joincommunity) or [GitHub](https://github.com/mindsdb/mindsdb/discussions) to ask questions and share your ideas and thoughts. If this tutorial was helpful, please give us a GitHub star [here](https://github.com/mindsdb/mindsdb) . Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/data_enrichment/text-summarization-inside-mysql-with-openai.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/data_enrichment/text-summarization-inside-mysql-with-openai) ⌘I --- # Create, Train, and Deploy a Model - MindsDB [Skip to main content](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Create, Train, and Deploy a Model [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Description](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#description) * [Syntax](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#syntax) * [Overview](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#overview) * [Regression Models](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#regression-models) * [Classification Models](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#classification-models) * [Time Series Models](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#time-series-models) * [NLP Models](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#nlp-models) * [Large Language Models (LLM)](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#large-language-models-llm) * [Example](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#example) * [Regression Models](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#regression-models-2) * [Classification Models](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#classification-models-2) * [Time Series Models](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#time-series-models-2) * [NLP Models](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#nlp-models-2) * [Large Language Models (LLM)](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#large-language-models-llm-2) [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#description) Description ------------------------------------------------------------------------------------- The `CREATE MODEL` statement creates and trains a machine learning (ML) model. Please note that the `CREATE MODEL` statement is equivalent to the `CREATE MODEL` statement. We are transitioning to the `CREATE MODEL` statement, but the `CREATE MODEL` statement still works. [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#syntax) Syntax --------------------------------------------------------------------------- ### [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#overview) Overview Here is the full syntax: Copy Ask AI CREATE [OR REPLACE] MODEL [IF NOT EXISTS] project_name.predictor_name [FROM [integration_name | project_name]\ (SELECT [sequential_column,] [partition_column,] column_name, ...\ FROM [integration_name. | project_name.]table_name\ [JOIN model_name])] PREDICT target_column [ORDER BY sequential_column] [GROUP BY partition_column] [WINDOW int] [HORIZON int] [USING engine = 'engine_name',\ tag = 'tag_name',\ ...]; Where: | Expressions | Description | | --- | --- | | `project_name` | Name of the project where the model is created. By default, the `mindsdb` project is used. | | `predictor_name` | Name of the model to be created. | | `integration_name` | Name of the integration created using the [`CREATE DATABASE`](https://docs.mindsdb.com/sql/create/database)
statement or [file upload](https://docs.mindsdb.com/sql/create/file)
. | | `(SELECT column_name, ... FROM table_name)` | Selecting data to be used for training and validation. | | `target_column` | Column to be predicted. | | `ORDER BY sequential_column` | Used in time series models. The column by which time series is ordered. It can be a date or anything that defines the sequence of events. | | `GROUP BY partition_column` | Used in time series models. It is optional. The column by which rows that make a partition are grouped. For example, if you want to forecast the inventory for all items in the store, you can partition the data by `product_id`, so each distinct `product_id` has its own time series. | | `WINDOW int` | Used in time series models. The number of rows to look back at when making a prediction. It comes after the rows are ordered by the column defined in `ORDER BY` and split into groups by the column(s) defined in `GROUP BY`. The `WINDOW 10` syntax could be interpreted as “Always use the previous 10 rows”. | | `HORIZON int` | Used in time series models. It is optional. It defines the number of future predictions (it is 1 by default). However, the `HORIZON` parameter, besides defining the number of predictions, has an impact on the training procedure when using the Lightwood ML backend. For example, different mixers are selected depending on whether the `HORIZON` value is one or greater than one. | | `engine_name` | You can optionally provide an ML engine, based on which the model is created. | | `tag_name` | You can optionally provide a tag that is visible in the `training_options` column of the `mindsdb.models` table. | ### [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#regression-models) Regression Models Here is the syntax for regression models: Copy Ask AI CREATE MODEL project_name.predictor_name FROM integration_name (SELECT column_name, ... FROM table_name) PREDICT target_column [USING engine = 'engine_name',\ tag = 'tag_name']; Please note that the `FROM` clause is mandatory here. The `target_column` that will be predicted is a numerical value. The prediction values are not limited to a defined set of values, but can be any number from the given range of numbers. ### [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#classification-models) Classification Models Here is the syntax for classification models: Copy Ask AI CREATE MODEL project_name.predictor_name FROM integration_name (SELECT column_name, ... FROM table_name) PREDICT target_column [USING engine = 'engine_name',\ tag = 'tag_name']; Please note that the `FROM` clause is mandatory here. The `target_column` that will be predicted is a string value. The prediction values are limited to a defined set of values, such as `Yes` and `No`. ### [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#time-series-models) Time Series Models Here is the syntax for time series models: Copy Ask AI CREATE MODEL project_name.predictor_name FROM integration_name (SELECT sequential_column, partition_column, other_column, target_column FROM table_name) PREDICT target_column ORDER BY sequential_column [GROUP BY partition_column] WINDOW int [HORIZON int] [USING engine = 'engine_name',\ tag = 'tag_name']; Please note that the `FROM` clause is mandatory here. Due to the nature of time series forecasting, you need to use the [`JOIN`](https://docs.mindsdb.com/sql/api/join) statement and join the data table with the model table to get predictions. ### [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#nlp-models) NLP Models Here is the syntax for using external models within MindsDB: Copy Ask AI CREATE MODEL project_name.model_name PREDICT PRED USING engine = 'engine_name', task = 'task_name', model_name = 'hub_model_name', input_column = 'input_column_name', labels = ['label1', 'label2']; Please note that you don’t need to define the `FROM` clause here. Instead, the `input_column` is defined in the `USING` clause. It allows you to bring an external model, for example, from the Hugging Face model hub, and use it within MindsDB. ### [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#large-language-models-llm) Large Language Models (LLM) MindsDB integrates with [numerous LLM providers listed here](https://docs.mindsdb.com/integrations/ai-overview#large-language-models) . Commonly, LLMs support the `prompt_template` parameter that stores the message/instruction to the model. Copy Ask AI CREATE MODEL project_name.model_name PREDICT answer USING engine = 'llm_engine_name', prompt_template = 'answer users questions in a helpful way: {{questions}}'; The `prompt_template` parameter instructs the model what output should be generated. It can include variables enclosed in double curly braces, which will be replaced with data values upon joining the model with the input data. [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#example) Example ----------------------------------------------------------------------------- ### [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#regression-models-2) Regression Models Here is an example for regression models that uses data from a database: Copy Ask AI CREATE MODEL mindsdb.home_rentals_model FROM example_db (SELECT * FROM demo_data.home_rentals) PREDICT rental_price USING engine = 'lightwood', tag = 'my home rentals model'; On execution, we get: Copy Ask AI Query OK, 0 rows affected (x.xxx sec) Visit our [tutorial on regression models](https://docs.mindsdb.com/sql/tutorials/home-rentals) to see the full example. ### [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#classification-models-2) Classification Models Here is an example for classification models that uses data from a file: Copy Ask AI CREATE MODEL mindsdb.customer_churn_predictor FROM files (SELECT * FROM churn) PREDICT Churn USING engine = 'lightwood', tag = 'my customers model'; On execution, we get: Copy Ask AI Query OK, 0 rows affected (x.xxx sec) Visit our [tutorial on classification models](https://docs.mindsdb.com/sql/tutorials/customer-churn) to see the full example. ### [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#time-series-models-2) Time Series Models Here is an example for time series models that uses data from a file: Copy Ask AI CREATE MODEL mindsdb.house_sales_predictor FROM files (SELECT * FROM house_sales) PREDICT MA ORDER BY saledate GROUP BY bedrooms -- the target column to be predicted stores one row per quarter WINDOW 8 -- using data from the last two years to make forecasts (last 8 rows) HORIZON 4; -- making forecasts for the next year (next 4 rows) On execution, we get: Copy Ask AI Query OK, 0 rows affected (x.xxx sec) Visit our [tutorial on time series models](https://docs.mindsdb.com/sql/tutorials/house-sales-forecasting) to see the full example. ### [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#nlp-models-2) NLP Models Here is an example for the Hugging Face model: Copy Ask AI CREATE MODEL mindsdb.spam_classifier PREDICT PRED USING engine = 'huggingface', task = 'text-classification', model_name = 'mrm8488/bert-tiny-finetuned-sms-spam-detection', input_column = 'text_spammy', labels = ['ham', 'spam']; On execution, we get: Copy Ask AI Query OK, 0 rows affected (x.xxx sec) ### [​](https://docs.mindsdb.com/mindsdb_sql/sql/create/model#large-language-models-llm-2) Large Language Models (LLM) Here is an example using the OpenAI engine: Copy Ask AI CREATE MODEL sentiment_classifier PREDICT sentiment USING engine = 'openai_engine', prompt_template = 'analyze customer reviews and assign sentiment as positive or negative or neutral: {{review}}'; Note that the `prompt_template` parameter stores instructions that the model will follow to generate output. Visit our [page no how to bring Hugging Face models into MindsDB](https://docs.mindsdb.com/custom-model/huggingface) for more details. **Checking Model Status**After you run the `CREATE MODEL` statement, you can check the status of the training process by querying the `mindsdb.models` table. Copy Ask AI DESCRIBE predictor_name; On execution, we get: Copy Ask AI +---------------+-----------------------------------+----------------------------------------+-----------------------+-------------+---------------+-----+-----------------+----------------+ |name |status |accuracy |predict |update_status|mindsdb_version|error|select_data_query|training_options| +---------------+-----------------------------------+----------------------------------------+-----------------------+-------------+---------------+-----+-----------------+----------------+ |predictor_name |generating or training or complete |number depending on the accuracy metric |column_to_be_predicted |up_to_date |22.7.5.0 | | | | +---------------+-----------------------------------+----------------------------------------+-----------------------+-------------+---------------+-----+-----------------+----------------+ Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/mindsdb_sql/sql/create/model.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/mindsdb_sql/sql/create/model) ⌘I --- # AI Integrations - MindsDB [Skip to main content](https://docs.mindsdb.com/integrations/ai-overview#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation AI Integrations [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Large Language Models](https://docs.mindsdb.com/integrations/ai-overview#large-language-models) * [Bring Your Own Models](https://docs.mindsdb.com/integrations/ai-overview#bring-your-own-models) MindsDB integrates with numerous AI frameworks, facilitating [deployment and management of AI models](https://docs.mindsdb.com/model-management) . ![](https://mintcdn.com/mindsdb/tkxKy44mj_2VlYcf/assets/ai-integrations.png?w=2500&fit=max&auto=format&n=tkxKy44mj_2VlYcf&q=85&s=5d0002a592bc3a572c7af2a0925034bd) MindsDB offers a wide range of **AI engines** used to create models and incorporate them in the data landscape as virtual [AI tables](https://docs.mindsdb.com/generative-ai-tables) . MindsDB abstracts AI models as virtual tables, or Generative AI Tables, that can generate data from the underlying model upon being queried. This section contains instructions on how to create and deploy models within MindsDB, utilizing different AI/ML frameworks. ### [​](https://docs.mindsdb.com/integrations/ai-overview#large-language-models) Large Language Models [Anthropic\ ---------](https://docs.mindsdb.com/integrations/ai-engines/anthropic) [Cohere\ ------](https://docs.mindsdb.com/integrations/ai-engines/cohere) [Google Gemini\ -------------](https://docs.mindsdb.com/integrations/ai-engines/google_gemini) [Hugging Face Inference API\ --------------------------](https://docs.mindsdb.com/integrations/ai-engines/huggingface_inference_api) [Ollama\ ------](https://docs.mindsdb.com/integrations/ai-engines/ollama) [OpenAI\ ------](https://docs.mindsdb.com/integrations/ai-engines/openai) [Vertex AI\ ---------](https://docs.mindsdb.com/integrations/ai-engines/vertex) ### [​](https://docs.mindsdb.com/integrations/ai-overview#bring-your-own-models) Bring Your Own Models [BYOM\ ----](https://docs.mindsdb.com/integrations/ai-engines/byom) [MLflow\ ------](https://docs.mindsdb.com/integrations/ai-engines/mlflow) **Metadata about AI handlers and AI engines****AI handlers** represent a raw implementation of the integration between MindsDB and an AI/ML framework. These are used to create AI engines.Here is how you can query for all the available AI handlers used to create AI engines. Copy Ask AI SELECT * FROM information_schema.handlers WHERE type = 'ml'; Or, alternatively: Copy Ask AI SHOW HANDLERS WHERE type = 'ml'; And here is how you can query for all the created AI engines: Copy Ask AI SELECT * FROM information_schema.ml_engines; Or, alternatively: Copy Ask AI SHOW ML_ENGINES; Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/integrations/ai-overview.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/ai-overview) ⌘I --- # Setup for Windows via pip - MindsDB [Skip to main content](https://docs.mindsdb.com/setup/self-hosted/pip/windows#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Setup for Windows via pip [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Installation using the Python venv Module](https://docs.mindsdb.com/setup/self-hosted/pip/windows#installation-using-the-python-venv-module) * [Installation using Anaconda](https://docs.mindsdb.com/setup/self-hosted/pip/windows#installation-using-anaconda) * [Dependencies](https://docs.mindsdb.com/setup/self-hosted/pip/windows#dependencies) * [Troubleshooting](https://docs.mindsdb.com/setup/self-hosted/pip/windows#troubleshooting) * [Pip and Python Versions](https://docs.mindsdb.com/setup/self-hosted/pip/windows#pip-and-python-versions) * [How to Avoid Dependency Issues](https://docs.mindsdb.com/setup/self-hosted/pip/windows#how-to-avoid-dependency-issues) * [Installing torch or torchvision](https://docs.mindsdb.com/setup/self-hosted/pip/windows#installing-torch-or-torchvision) * [Further Issues?](https://docs.mindsdb.com/setup/self-hosted/pip/windows#further-issues) * [What’s Next](https://docs.mindsdb.com/setup/self-hosted/pip/windows#what%E2%80%99s-next) To successfully install MindsDB, use **Python 64-bit version**. Also, make sure that **Python >= 3.10** and **pip >= 20.3**. [​](https://docs.mindsdb.com/setup/self-hosted/pip/windows#installation-using-the-python-venv-module) Installation using the Python [`venv`](https://docs.python.org/3/library/venv.html) Module ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1. Create a new virtual environment called `mindsdb`: Copy Ask AI py -m venv mindsdb Now, activate it: Copy Ask AI .\mindsdb\Scripts\activate.bat 2. Once inside the virtual environment, run the command below to mitigate the dependency issues: Copy Ask AI pip install --upgrade pip setuptools wheel 3. Install MindsDB: Copy Ask AI pip install mindsdb 4. Start MindsDB: Copy Ask AI python -m mindsdb By default, MindsDB starts the `http` and `mysql` APIs. You can define which APIs to start using the `api` flag as below. Copy Ask AI python -m mindsdb --api http,mysql,postgres If you want to start MindsDB without the graphical user interface (GUI), use the `--no_studio` flag as below. Copy Ask AI python -m mindsdb --no_studio [​](https://docs.mindsdb.com/setup/self-hosted/pip/windows#installation-using-anaconda) Installation using Anaconda ---------------------------------------------------------------------------------------------------------------------- Here, you need either [Anaconda](https://www.anaconda.com/products/individual) or [Conda](https://conda.io/projects/conda/en/latest/index.html) installed on your machine. 1. Open Anaconda prompt and create a new virtual environment: Copy Ask AI conda create -n mindsdb Now, activate it: Copy Ask AI conda activate mindsdb 2. Once inside the virtual environment, run the command below to mitigate the dependency issues: Copy Ask AI pip install --upgrade pip setuptools wheel 3. Install MindsDB: Copy Ask AI pip install mindsdb 4. Start MindsDB: Copy Ask AI python -m mindsdb By default, MindsDB starts the `http` and `mysql` APIs. You can define which APIs to start using the `api` flag as below. Copy Ask AI python -m mindsdb --api http,mysql,postgres If you want to start MindsDB without the graphical user interface (GUI), use the `--no_studio` flag as below. Copy Ask AI python -m mindsdb --no_studio [​](https://docs.mindsdb.com/setup/self-hosted/pip/windows#dependencies) Dependencies ---------------------------------------------------------------------------------------- The dependencies for many of the data or ML integrations are not installed by default. If you want to use a data or ML integration whose dependencies are not available by default, install it by running this command: Copy Ask AI pip install mindsdb[handler_name] You can find all available [handlers here](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers) . [​](https://docs.mindsdb.com/setup/self-hosted/pip/windows#troubleshooting) Troubleshooting ---------------------------------------------------------------------------------------------- ### [​](https://docs.mindsdb.com/setup/self-hosted/pip/windows#pip-and-python-versions) Pip and Python Versions Currently, MindsDB supports Python versions 3.10.x, and 3.11.x. To successfully install MindsDB, use **Python 64-bit version**. Also, make sure that **Python >= 3.10** and **pip >= 20.3**. You can check the pip and python versions by running the `pip --version` and `python --version` commands. Please note that depending on your environment and installed pip and python packages, you might have to use **pip3** instead of **pip** or **python3.x** instead of **py**. For example, `pip3 install mindsdb` instead of `pip install mindsdb`. ### [​](https://docs.mindsdb.com/setup/self-hosted/pip/windows#how-to-avoid-dependency-issues) How to Avoid Dependency Issues Install MindsDB in a virtual environment using **pip** to avoid dependency issues. Or you could try to install MindsDB with [Anaconda](https://www.anaconda.com/products/individual) and run the installation from the **Anaconda prompt**. In addition, for Windows systems with default languages other than English, your system might not have UTF-8 as the default encoding standard, which will cause encoding errors when installing dependencies. To solve this issue, go to `Control Panel` > `Clock and Region` > `Region` > `Administrative tab` > `Change system locale button` and enable `Beta: Use Unicode UTF-8 for worldwide language support`. ### [​](https://docs.mindsdb.com/setup/self-hosted/pip/windows#installing-torch-or-torchvision) Installing torch or torchvision If the installation fails when installing **torch** or **torchvision**, try to install them manually by following the instructions on their [official website](https://pytorch.org/get-started/locally/) . [​](https://docs.mindsdb.com/setup/self-hosted/pip/windows#further-issues) Further Issues? --------------------------------------------------------------------------------------------- You can try to replicate your issue using the [Docker setup](https://docs.mindsdb.com/setup/self-hosted/docker) . Also, please create an issue with detailed description in the [MindsDB GitHub repository](https://github.com/mindsdb/mindsdb/issues) so we can help you. Usually, we review issues and respond within a few hours. [​](https://docs.mindsdb.com/setup/self-hosted/pip/windows#what%E2%80%99s-next) What’s Next ---------------------------------------------------------------------------------------------- Now that you installed and started MindsDB locally in your Docker container, go ahead and find out how to create and train a model using the [`CREATE MODEL`](https://docs.mindsdb.com/sql/create/model) statement. In the **MindsDB SQL** section, you’ll find a comprehensive overview of the SQL syntax offered by MindsDB. You can connect MindsDB to different clients, including [PostgreSQL CLI](https://docs.mindsdb.com/connect/postgres-client) and [MySQL CLI](https://docs.mindsdb.com/connect/mysql-client) . Check out the [Use Cases](https://docs.mindsdb.com/use-cases/overview) section to follow tutorials that cover Large Language Models, Natural Language Processing, Time Series, Classification, and Regression models. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/setup/self-hosted/pip/windows.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/setup/self-hosted/pip/windows) ⌘I --- # Page Not Found [Skip to main content](https://docs.mindsdb.com/tutorials#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Page Not Found [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) 404 Page Not Found ============== We couldn't find the page. Maybe you were looking for one of these pages below? [Tutorial to Get Started with MindsDB](https://docs.mindsdb.com/quickstart-tutorial#) [MindsDB Installation for Development](https://docs.mindsdb.com/contribute/install#whats-next) [MindsDB and DBeaver](https://docs.mindsdb.com/mindsdb_sql/connect/dbeaver#whats-next) ⌘I --- # Page Not Found [Skip to main content](https://docs.mindsdb.com/faqs/whitelist-ips#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Page Not Found [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) 404 Page Not Found ============== We couldn't find the page. Maybe you were looking for one of these pages below? [MariaDB SkySQL Setup Guide with MindsDB](https://docs.mindsdb.com/mindsdb_sql/connect/connect-mariadb-skysql#2-add-mindsdb-to-your-service-allowlist) [MindsDB and DBeaver](https://docs.mindsdb.com/mindsdb_sql/connect/dbeaver#lets-run-some-queries) [MindsDB and Grafana](https://docs.mindsdb.com/mindsdb_sql/connect/grafana#visual-query-builder) ⌘I --- # Predict Home Rental Prices with MindsDB - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/in-database_ml/home-rentals#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Predict Home Rental Prices with MindsDB [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Connect a data source](https://docs.mindsdb.com/use-cases/in-database_ml/home-rentals#connect-a-data-source) * [Deploy and train an ML model](https://docs.mindsdb.com/use-cases/in-database_ml/home-rentals#deploy-and-train-an-ml-model) * [Make predictions](https://docs.mindsdb.com/use-cases/in-database_ml/home-rentals#make-predictions) * [Automate continuous improvement of the model](https://docs.mindsdb.com/use-cases/in-database_ml/home-rentals#automate-continuous-improvement-of-the-model) In this tutorial, we’ll use a regression model to predict home rental prices. This tutorial uses the Lightwood integration that requires the `mindsdb/mindsdb:lightwood` Docker image. [Learn more here](https://docs.mindsdb.com/setup/self-hosted/docker#install-mindsdb) . [​](https://docs.mindsdb.com/use-cases/in-database_ml/home-rentals#connect-a-data-source) Connect a data source ------------------------------------------------------------------------------------------------------------------ We will start by connecting a demo database to MindsDB using the `CREATE DATABASE` statement. Copy Ask AI CREATE DATABASE example_db WITH ENGINE = "postgres", PARAMETERS = { "user": "demo_user", "password": "demo_password", "host": "samples.mindsdb.com", "port": "5432", "database": "demo", "schema": "demo_data" }; Let’s preview the data that will be used to train the model. Copy Ask AI SELECT * FROM example_db.home_rentals LIMIT 10; [​](https://docs.mindsdb.com/use-cases/in-database_ml/home-rentals#deploy-and-train-an-ml-model) Deploy and train an ML model -------------------------------------------------------------------------------------------------------------------------------- Let’s create and train a machine learning model. For that we are going to use the `CREATE MODEL` statement, where we specify what query to train `FROM` and what we want to `PREDICT`. Copy Ask AI CREATE MODEL mindsdb.home_rentals_model FROM example_db (SELECT * FROM home_rentals) PREDICT rental_price; It may take a couple of minutes for the training to complete. You can monitor the status of your model as below. Copy Ask AI DESCRIBE home_rentals_model; [​](https://docs.mindsdb.com/use-cases/in-database_ml/home-rentals#make-predictions) Make predictions -------------------------------------------------------------------------------------------------------- Once the model’s status is complete, you can make predictions by querying the model. Copy Ask AI SELECT rental_price, rental_price_explain FROM mindsdb.home_rentals_model WHERE sqft = 823 AND location='good' AND neighborhood='downtown' AND days_on_market=10; You can also make batch predictions by joining the data table with the model. Copy Ask AI SELECT t.rental_price as real_price, m.rental_price as predicted_price, t.number_of_rooms, t.number_of_bathrooms, t.sqft, t.location, t.days_on_market FROM example_db.home_rentals as t JOIN mindsdb.home_rentals_model as m LIMIT 100; [​](https://docs.mindsdb.com/use-cases/in-database_ml/home-rentals#automate-continuous-improvement-of-the-model) Automate continuous improvement of the model ---------------------------------------------------------------------------------------------------------------------------------------------------------------- Now, we can take this even further. MindsDB includes powerful automation features called Jobs which allow us to automate queries in MindsDB. This is very handy for production AI/ML systems which all require automation logic to help them to work. We use the `CREATE JOB` statement to create a Job. Now, let’s use a Job to retrain the model every two days, just like we might in production. You can retrain the model to improve predictions every time when either new data or new MindsDB version is available. And, if you want to retrain your model considering only new data, then go for finetuning it. Copy Ask AI CREATE JOB improve_model ( RETRAIN mindsdb.home_rentals_model FROM example_db (SELECT * FROM home_rentals) ) EVERY 2 days IF (SELECT * FROM example_db.home_rentals WHERE created_at > LAST); This job will execute every 2 days only if there is new data available in the `home_rentals` table. Learn more about the [`LAST` keyword](https://docs.mindsdb.com/mindsdb_sql/sql/create/jobs#last) here. And there you have it! You created an end-to-end automated production ML system in a few short minutes. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/in-database_ml/home-rentals.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/in-database_ml/home-rentals) ⌘I --- # Create an Agent - MindsDB [Skip to main content](https://docs.mindsdb.com/rest/agents/create-agent#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Create an Agent [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/rest/agents/create-agent.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/rest/agents/create-agent) ⌘I --- # Page Not Found [Skip to main content](https://docs.mindsdb.com/nlp/sentiment-analysis-inside-mongodb-with-openai#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Page Not Found [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) 404 Page Not Found ============== We couldn't find the page. Maybe you were looking for one of these pages below? [MindsDB's MCP Server with OpenAI's Remote MCP](https://docs.mindsdb.com/model-context-protocol/openai#mindsdbs-mcp-server-with-openais-remote-mcp) [MonetDB](https://docs.mindsdb.com/integrations/data-integrations/monetdb#monetdb) [Disposable Email Domains and OpenAI](https://docs.mindsdb.com/faqs/disposable-email-doman-and-openai#) ⌘I --- # Page Not Found [Skip to main content](https://docs.mindsdb.com/nlp/question-answering-inside-mongodb-with-openai#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Page Not Found [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) 404 Page Not Found ============== We couldn't find the page. Maybe you were looking for one of these pages below? [MindsDB's MCP Server with OpenAI's Remote MCP](https://docs.mindsdb.com/model-context-protocol/openai#mindsdbs-mcp-server-with-openais-remote-mcp) [MonetDB](https://docs.mindsdb.com/integrations/data-integrations/monetdb#monetdb) [Disposable Email Domains and OpenAI](https://docs.mindsdb.com/faqs/disposable-email-doman-and-openai#) ⌘I --- # Page Not Found [Skip to main content](https://docs.mindsdb.com/nlp/text-summarization-inside-mongodb-with-openai#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Page Not Found [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) 404 Page Not Found ============== We couldn't find the page. Maybe you were looking for one of these pages below? [MindsDB's MCP Server with OpenAI's Remote MCP](https://docs.mindsdb.com/model-context-protocol/openai#) [MonetDB](https://docs.mindsdb.com/integrations/data-integrations/monetdb#monetdb) [Disposable Email Domains and OpenAI](https://docs.mindsdb.com/faqs/disposable-email-doman-and-openai#) ⌘I --- # Generative AI Tables - MindsDB [Skip to main content](https://docs.mindsdb.com/generative-ai-tables#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Generative AI Tables [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [What are Generative AI Tables?](https://docs.mindsdb.com/generative-ai-tables#what-are-generative-ai-tables) * [How to Use Generative AI Tables](https://docs.mindsdb.com/generative-ai-tables#how-to-use-generative-ai-tables) * [Deploy AI Models as AI Tables](https://docs.mindsdb.com/generative-ai-tables#deploy-ai-models-as-ai-tables) * [Prepare Input Data](https://docs.mindsdb.com/generative-ai-tables#prepare-input-data) * [Make Predictions](https://docs.mindsdb.com/generative-ai-tables#make-predictions) * [Difference between AI Tables and Standard Tables](https://docs.mindsdb.com/generative-ai-tables#difference-between-ai-tables-and-standard-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. MindsDB integrates with numerous AI frameworks. [Learn more here](https://docs.mindsdb.com/integrations/ai-overview) . ![](https://docs.google.com/drawings/d/e/2PACX-1vQDXTuCWl8IxTEO-2ntjN17B5XtCtJDJ_d_PDCeX0ch0GBzSJfuJmefGuM_FEyGOwlgrxnNSzmLaYGO/pub?w=951&h=460) [​](https://docs.mindsdb.com/generative-ai-tables#what-are-generative-ai-tables) 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. [​](https://docs.mindsdb.com/generative-ai-tables#how-to-use-generative-ai-tables) How to Use Generative AI Tables --------------------------------------------------------------------------------------------------------------------- AI tables, introduced by MindsDB, abstract AI models as virtual tables so you can simply query AI models for predictions. With MindsDB, 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. ### [​](https://docs.mindsdb.com/generative-ai-tables#deploy-ai-models-as-ai-tables) Deploy 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. Copy Ask AI CREATE MODEL sentiment_classifier_model PREDICT sentiment USING engine = 'openai_engine', model_name = 'gpt-4', prompt_template = 'describe the sentiment of the reviews strictly as "positive", "neutral", or "negative". "I love the product":positive "It is a scam":negative "{{review}}.":'; 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. Copy Ask AI CREATE MODEL response_generator_model PREDICT response USING engine = 'openai_engine', model_name = 'gpt-4', prompt_template = 'briefly respond to the customer review: {{review}}, added by a customer after buying {{product_name}} in quantity {{quantity}}'; Follow [this doc page](https://docs.mindsdb.com/integrations/ai-engines/openai) 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. ### [​](https://docs.mindsdb.com/generative-ai-tables#prepare-input-data) Prepare Input Data The `amazon_reviews` table stores the following columns: Copy Ask AI +----------------------------+-----------------------------+------------------------+-------------+ | created_at | product_name | review | customer_id | +----------------------------+-----------------------------+------------------------+-------------+ | 2023-10-03 16:30:00.000000 | Power Adapter | It is a great product. | 1 | | 2023-10-03 16:31:00.000000 | Bluetooth and Wi-Fi Speaker | It is ok. | 2 | | 2023-10-03 16:32:00.000000 | Kindle eReader | It doesn’t work. | 3 | +----------------------------+-----------------------------+------------------------+-------------+ 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: Copy Ask AI +----------------------------+-----------------------------+-------------+----------+ | sale_date | product_name | customer_id | quantity | +----------------------------+-----------------------------+-------------+----------+ | 2023-10-03 16:30:00.000000 | Power Adapter | 1 | 20 | | 2023-10-03 16:31:00.000000 | Bluetooth and Wi-Fi Speaker | 2 | 5 | | 2023-10-03 16:32:00.000000 | Kindle eReader | 3 | 10 | +----------------------------+-----------------------------+-------------+----------+ The `response_generator_model` requires the two tables to be joined to provide it with sufficient input data. ### [​](https://docs.mindsdb.com/generative-ai-tables#make-predictions) Make 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: 1. If you query the AI table directly, you can provide input data in the `WHERE` clause, like this: Copy Ask AI SELECT review, sentiment FROM sentiment_classifier_model WHERE review = 'I like it'; 2. You can provide input data to AI tables from the joined data tables, like this: Copy Ask AI SELECT inp.product_name, inp.review, m1.sentiment, m2.response FROM data_integration_conn.amazon_reviews2 AS inp JOIN data_integration_conn.products_sold AS inp2 ON inp.customer_id = inp2.customer_id JOIN sentiment_classifier_model AS m1 JOIN response_generator_model AS m2; The `sentiment_classifier_model` requires a parameter named `review`, so the data table should contain a column named `review`, 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: Copy Ask AI SELECT inp.product_name, inp.review, m1.sentiment, m2.response FROM data_integration_conn.amazon_reviews2 AS inp JOIN sentiment_classifier_model AS m1 JOIN response_generator_model AS m2 WHERE m2.quantity = 5; 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: Copy Ask AI SELECT inp.product_name, inp.review, m1.sentiment, m2.response FROM data_integration_conn.amazon_reviews2 AS inp JOIN sentiment_classifier_model AS m1 JOIN response_generator_model AS m2 WHERE m2.quantity = (SELECT quantity FROM data_integration_conn.products_sold WHERE customer_id = 2); [​](https://docs.mindsdb.com/generative-ai-tables#difference-between-ai-tables-and-standard-tables) 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. Copy Ask AI SELECT income, debt FROM income_table; On execution, we get: Copy Ask AI +------+-----+ |income|debt | +------+-----+ |60000 |20000| |80000 |25100| |100000|30040| |120000|36010| +------+-----+ A simple visualization of the data present in the `income_table` table is as follows: ![Income vs Debt](https://mintcdn.com/mindsdb/qZ0qlWEqCb1K2Drt/assets/sql/income_vs_debt.png?w=2500&fit=max&auto=format&n=qZ0qlWEqCb1K2Drt&q=85&s=10b4f3b7ec4b9f77f41a82c091777081) Querying the income table to get the `debt` value for a particular `income` value results in the following: Copy Ask AI SELECT income, debt FROM income_table WHERE income = 80000; On execution, we get: Copy Ask AI +------+-----+ |income|debt | +------+-----+ |80000 |25100| +------+-----+ And here is what we get: ![Income vs Debt chart](https://mintcdn.com/mindsdb/qZ0qlWEqCb1K2Drt/assets/sql/income_vs_debt_known_value.png?w=2500&fit=max&auto=format&n=qZ0qlWEqCb1K2Drt&q=85&s=b9fe5ae22e93e980850318b54cad48a9) But what happens when querying the table for an `income` value that is not present there? Copy Ask AI SELECT income, debt FROM income_table WHERE income = 90000; On execution, we get: Copy Ask AI Empty set (0.00 sec) When the `WHERE` clause condition is not fulfilled for any of the rows, no value is returned. ![Income vs Debt query](https://mintcdn.com/mindsdb/qZ0qlWEqCb1K2Drt/assets/sql/income_vs_debt_unknown_value.png?w=2500&fit=max&auto=format&n=qZ0qlWEqCb1K2Drt&q=85&s=fd3e110cc61f63bdba0039787ce9e44b) 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. Copy Ask AI CREATE MODEL mindsdb.debt_model FROM income_table PREDICT debt; On execution, we get: Copy Ask AI Query OK, 0 rows affected (x.xxx sec) MindsDB provides the [`CREATE MODEL`](https://docs.mindsdb.com/sql/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: ![Income vs Debt model](https://mintcdn.com/mindsdb/qZ0qlWEqCb1K2Drt/assets/sql/income_vs_debt_predictor.png?w=2500&fit=max&auto=format&n=qZ0qlWEqCb1K2Drt&q=85&s=fd33c9f1cdf4be2c11708711944c99e2) 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. Copy Ask AI SELECT income, debt FROM mindsdb.debt_model WHERE income = 90000; On execution, we get: Copy Ask AI +------+-----+ |income|debt | +------+-----+ |90000 |27820| +------+-----+ And here is how it looks: ![Income vs Debt model](https://mintcdn.com/mindsdb/qZ0qlWEqCb1K2Drt/assets/sql/income_vs_debt_prediction.png?w=2500&fit=max&auto=format&n=qZ0qlWEqCb1K2Drt&q=85&s=32c9b58fa9a634e836f9f0d76aed74a7) Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/generative-ai-tables.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/generative-ai-tables) ⌘I --- # Build an AI/ML Handler - MindsDB [Skip to main content](https://docs.mindsdb.com/contribute/ml-handlers#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Build an AI/ML Handler [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [What are Machine Learning Handlers?](https://docs.mindsdb.com/contribute/ml-handlers#what-are-machine-learning-handlers) * [Creating a Machine Learning Handler](https://docs.mindsdb.com/contribute/ml-handlers#creating-a-machine-learning-handler) * [Core Methods](https://docs.mindsdb.com/contribute/ml-handlers#core-methods) * [Implementation](https://docs.mindsdb.com/contribute/ml-handlers#implementation) * [MindsDB ML Ecosystem](https://docs.mindsdb.com/contribute/ml-handlers#mindsdb-ml-ecosystem) * [Step-by-Step Instructions](https://docs.mindsdb.com/contribute/ml-handlers#step-by-step-instructions) * [Check out our Machine Learning Handlers!](https://docs.mindsdb.com/contribute/ml-handlers#check-out-our-machine-learning-handlers) In this section, you’ll find how to create new machine learning (ML) handlers within MindsDB. **Prerequisite**You should have the latest version of the MindsDB repository installed locally. Follow [this guide](https://docs.mindsdb.com/contribute/install) to learn how to install MindsDB for development. [​](https://docs.mindsdb.com/contribute/ml-handlers#what-are-machine-learning-handlers) What are Machine Learning Handlers? ------------------------------------------------------------------------------------------------------------------------------ ML handlers act as a bridge to any ML framework. You use ML handlers to create ML engines using [the CREATE ML\_ENGINE command](https://docs.mindsdb.com/sql/create/ml-engine) . So you can expose ML models from any supported ML engine as an AI table. **Database Handlers**To learn more about handlers and how to implement a database handler, visit our [doc page here](https://docs.mindsdb.com/contribute/data-handlers) . [​](https://docs.mindsdb.com/contribute/ml-handlers#creating-a-machine-learning-handler) Creating a Machine Learning Handler ------------------------------------------------------------------------------------------------------------------------------- You can create your own ML handler within MindsDB by inheriting from the [BaseMLEngine](https://github.com/mindsdb/mindsdb/blob/3d9090acb0b8b3b0e2a96e2c93dad436f5ebef90/mindsdb/integrations/libs/base.py#L123) class. By providing the implementation for some or all of the methods contained in the `BaseMLEngine` class, you can connect with the machine learning library or framework of your choice. ### [​](https://docs.mindsdb.com/contribute/ml-handlers#core-methods) Core Methods Apart from the `__init__()` method, there are five methods, of which two must be implemented. We recommend checking actual examples in the codebase to get an idea of what goes into each of these methods, as they can change a bit depending on the nature of the system being integrated. Let’s review the purpose of each method. | Method | Purpose | | --- | --- | | `create()` | It creates a model inside the engine registry. | | `predict()` | It calls a model and returns prediction data. | | `update()` | Optional. It updates an existing model without resetting its internal structure. | | `describe()` | Optional. It provides global model insights. | | `create_engine()` | Optional. It connects with external sources, such as REST API. | Authors can opt for adding private methods, new files and folders, or any combination of these to structure all the necessary work that will enable the core methods to work as intended. **Other Common Methods**Under the `mindsdb.integrations.libs.utils` library, contributors can find various methods that may be useful while implementing new handlers.Also, there is a wrapper class for the `BaseMLEngine` instances called [BaseMLEngineExec](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/libs/ml_exec_base.py#L157) . It is automatically deployed to take care of modifying the data responses into something that can be used alongside data handlers. ### [​](https://docs.mindsdb.com/contribute/ml-handlers#implementation) Implementation Here are the methods that must be implemented while inheriting from the [BaseMLEngine](https://github.com/mindsdb/mindsdb/blob/3d9090acb0b8b3b0e2a96e2c93dad436f5ebef90/mindsdb/integrations/libs/base.py#L123) class: * [The create() method](https://github.com/mindsdb/mindsdb/blob/3d9090acb0b8b3b0e2a96e2c93dad436f5ebef90/mindsdb/integrations/libs/base.py#L151) saves a model inside the engine registry for later usage. Copy Ask AI def create(self, target: str, df: Optional[pd.DataFrame] = None, args: Optional[Dict] = None) -> None: """ Saves a model inside the engine registry for later usage. Normally, an input dataframe is required to train the model. However, some integrations may merely require registering the model instead of training, in which case `df` can be omitted. Any other arguments required to register the model can be passed in an `args` dictionary. """ * [The predict() method](https://github.com/mindsdb/mindsdb/blob/3d9090acb0b8b3b0e2a96e2c93dad436f5ebef90/mindsdb/integrations/libs/base.py#L162) calls a model with an input dataframe and optionally, arguments to modify model’s behaviour. This method returns a dataframe with the predicted values. Copy Ask AI def predict(self, df: pd.DataFrame, args: Optional[Dict] = None) -> pd.DataFrame: """ Calls a model with some input dataframe `df`, and optionally some arguments `args` that may modify the model behavior. The expected output is a dataframe with the predicted values in the target-named column. Additional columns can be present, and will be considered row-wise explanations if their names finish with `_explain`. """ And here are the optional methods that you can implement alongside the mandatory ones if your ML framework allows it: * [The update() method](https://github.com/mindsdb/mindsdb/blob/3d9090acb0b8b3b0e2a96e2c93dad436f5ebef90/mindsdb/integrations/libs/base.py#L171) is used to update, fine-tune, or adjust an existing model without resetting its internal state. Copy Ask AI def finetune(self, df: Optional[pd.DataFrame] = None, args: Optional[Dict] = None) -> None: """ Optional. Used to update/fine-tune/adjust a pre-existing model without resetting its internal state (e.g. weights). Availability will depend on underlying integration support, as not all ML models can be partially updated. """ * [The describe() method](https://github.com/mindsdb/mindsdb/blob/3d9090acb0b8b3b0e2a96e2c93dad436f5ebef90/mindsdb/integrations/libs/base.py#L181) provides global model insights, such as framework-level parameters used in training. Copy Ask AI def describe(self, key: Optional[str] = None) -> pd.DataFrame: """ Optional. When called, this method provides global model insights, e.g. framework-level parameters used in training. """ * [The create\_engine() method](https://github.com/mindsdb/mindsdb/blob/3d9090acb0b8b3b0e2a96e2c93dad436f5ebef90/mindsdb/integrations/libs/base.py#L189) is used to connect with the external sources, such as REST API. Copy Ask AI def create_engine(self, connection_args: dict): """ Optional. Used to connect with external sources (e.g. a REST API) that the engine will require to use any other methods. """ [​](https://docs.mindsdb.com/contribute/ml-handlers#mindsdb-ml-ecosystem) MindsDB ML Ecosystem ------------------------------------------------------------------------------------------------- MindsDB has recently decoupled some modules out of its AutoML package in order to leverage them in integrations with other ML engines. The three modules are as follows: 1. The [type\_infer](https://github.com/mindsdb/type_infer) module that implements automated type inference for any dataset. Below is the description of the input and output of this module. **Input:** tabular dataset. **Output:** best guesses of what type of data each column contains. 2. The [dataprep\_ml](https://github.com/mindsdb/dataprep_ml) module that provides data preparation utilities, such as data cleaning, analysis, and splitting. Data cleaning procedures include column-wise cleaners, column-wise missing value imputers, and data splitters (train-val-test split, either simple or stratified). Below is the description of the input and output of this module. **Input:** tabular dataset. **Output:** cleaned dataset, plus insights useful for data analysis and model building. 3. The [mindsdb\_evaluator](https://github.com/mindsdb/mindsdb_evaluator) module that provides utilities for evaluating the accuracy and calibration of ML models. Below is the description of the input and output of this module. **Input:** model predictions and the input data used to generate these predictions, including corresponding ground truth values of the column to predict. **Output:** accuracy metrics that evaluate prediction accuracy and calibration metrics that check whether model-emitted probabilities are calibrated. We recommend that new contributors use [type\_infer](https://github.com/mindsdb/type_infer) and [dataprep\_ml](https://github.com/mindsdb/dataprep_ml) modules when writing ML handlers to avoid reimplementing thin AutoML layers over and over again; it is advised to focus on mapping input data and user parameters to the underlying framework’s API. For now, using the [mindsdb\_evaluator](https://github.com/mindsdb/mindsdb_evaluator) module is not required, but will be in the short to medium term, so it’s important to be aware of it while writing a new integration. **Example**Let’s say you want to write an integration for `TPOT`. Its high-level API exposes classes that are either for classification or regression. But as a handler designer, you need to ensure that arbitrary ML tasks are dispatched properly to each class (i.e., not using a regressor for a classification problem and vice versa). First, `type_infer` can help you by estimating the data type of the target variable (so you immediately know what class to use). Additionally, to quickly get a stratified train-test split, you can leverage `dataprep_ml` splitters and continue to focus on the actual usage of TPOT for the training and inference logic. We would appreciate your feedback regarding usage & feature roadmap for the above modules, as they are quite new. [​](https://docs.mindsdb.com/contribute/ml-handlers#step-by-step-instructions) Step-by-Step Instructions ----------------------------------------------------------------------------------------------------------- Step 1: Set up and run MindsDB locally 1. Set up MindsDB using the [self-hosted pip](https://docs.mindsdb.com/setup/self-hosted/pip/source) installation method. 2. Make sure you can run the [quickstart example](https://docs.mindsdb.com/quickstart) locally. If you run into errors, check your bash terminal output. 3. Create a new git branch to store your changes. Step 2: Write a (failing) test for your new handler 1. Check that you can run the existing handler tests with `python -m pytest tests/unit/ml_handlers/`. If you get the `ModuleNotFoundError` error, try adding the `__init__.py` file to any subdirectory that doesn’t have it. 2. Copy the simple tests from a relevant handler. For regular data, use the [Ludwig](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/ludwig_handler) handler. And for time series data, use the [StatsForecast](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/statsforecast_handler) handler. 3. Change the SQL query to reference your handler. Specifically, set `USING engine={HandlerName}`. 4. Run your new test. Please note that it should fail as you haven’t yet added your handler. The exception should be `Can't find integration_record for handler ...`. Step 3: Add your handler to the source code 1. Create a new directory in `mindsdb/integrations/handlers/`. You must name the new directory `{HandlerName}_handler/`. 2. Copy the `.py` files from the [OpenAI handler folder](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/openai_handler) , including: `__about__.py`, `__init__.py`, `openai_handler.py`, `creation_args.py`, and `model_using_args.py`. Note that the arguments used at model creation time (stored in `creation_args.py`) and the arguments used at prediction time (stored in `model_using_args.py`) should be stored in separate files in order to be able to hide sensitive information such as API keys.By default, when querying for `connection_data` from the `information_schema.ml_engines` table or `training_options` from the `information_schema.models` table, all sensitive information is hidden. To unhide it, use this command: Copy Ask AI set show_secrets=true; 3. Change the contents of `.py` files to match your new handler. Also, change the name of the `statsforecast_handler.py` file to match your handler. 4. Modify the `requirements.txt` file to install your handler’s dependencies. You may get conflicts with other packages like Lightwood, but you can ignore them for now. 5. Create a new blank class for your handler in the `{HandlerName}_handler.py` file. Like for other handlers, this should be a subclass of the `BaseMLEngine` class. 6. Add your new handler class to the testing DB. In the `tests/unit/executor_test_base.py` file starting at line 91, you can see how other handlers are added with `db.session.add(...)`. Copy that and modify it to add your handler. Please note to add your handler before Lightwood, otherwise the CI will break. 7. Run your new test. Please note that it should still fail but with a different exception message. Step 4: Modify the handler source code until your test passes 1. Define a `create()` method that deals with the model setup arguments. This will add your handler to the models table. Depending on the framework, you may also train the model here using the `df` argument. 2. Save relevant arguments/trained models at the end of your `create` method. This allows them to be accessed later. Use the `engine_storage` attributes; you can find examples in other handlers’ folders. 3. Define a `predict()` method that makes model predictions. This method must return a dataframe with format matching the input, except with a column containing your model’s predictions of the target. The input df is a subset of the original df with the rows determined by the conditions in the predict SQL query. 4. Don’t debug the `create()` and `predict()` methods with the `print()` statement because they’re inside a subthread. Instead, write relevant info to disk. 5. Once your first test passes, add new tests for any important cases. You can also add tests for any helper functions you write. Step 5: QA your handler locally 1. Launch the MindsDB server locally with `python -m mindsdb`. Again, any issues will appear in the terminal output. 2. Check that your handler has been added to the local server database. You can view the list of handlers with `SELECT * from information_schema.handlers`. 3. Run the relevant tutorial from the panel on the right side. For regular data, this is `Predict Home Rental Prices`. And for time series data, this is `Forecast Quarterly House Sales`. Specify `USING ENGINE={your_handler}` while creating a model. 4. Don’t debug the `create()` and `predict()` methods with the `print()` statement because they’re inside a subthread. Instead, write relevant info to disk. 5. You should get sensible results if your handler has been well-implemented. Make sure you try the predict step with a range of parameters. Step 6: Open a pull request 1. You need to fork the MindsDB repository. Follow [this guide](https://github.com/mindsdb/mindsdb/blob/main/CONTRIBUTING.md) to start a PR. 2. If relevant, add your tests and new dependencies to the CI config. This is at `.github/workflows/mindsdb.yml`. Please note that `pytest` is the recommended testing package. Use `pytest` to confirm your ML handler implementation is correct. **Templates for Unit Tests**If you implement a time-series ML handler, create your unit tests following the structure of the [StatsForecast unit tests](https://github.com/mindsdb/mindsdb/blob/main/tests/unit/ml_handlers/test_statsforecast.py) .If you implement an NLP ML handler, create your unit tests following the structure of the [Hugging Face unit tests](https://github.com/mindsdb/mindsdb/blob/main/tests/unit/ml_handlers/test_huggingface.py) . [​](https://docs.mindsdb.com/contribute/ml-handlers#check-out-our-machine-learning-handlers) Check out our Machine Learning Handlers! ---------------------------------------------------------------------------------------------------------------------------------------- To see some ML handlers that are currently in use, we encourage you to check out the following ML handlers inside the MindsDB repository: * [Lightwood](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/lightwood_handler) * [HuggingFace](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/huggingface_handler) * [Ludwig](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/ludwig_handler) * [OpenAI](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/handlers/openai_handler) And here are [all the handlers available in the MindsDB repository](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers) . Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/contribute/ml-handlers.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/contribute/ml-handlers) ⌘I --- # OpenAI - MindsDB [Skip to main content](https://docs.mindsdb.com/integrations/ai-engines/openai#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation OpenAI [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Prerequisites](https://docs.mindsdb.com/integrations/ai-engines/openai#prerequisites) * [Setup](https://docs.mindsdb.com/integrations/ai-engines/openai#setup) * [Usage with OpenAI-Compatible APIs](https://docs.mindsdb.com/integrations/ai-engines/openai#usage-with-openai-compatible-apis) * [Usage](https://docs.mindsdb.com/integrations/ai-engines/openai#usage) * [Troubleshooting Guide](https://docs.mindsdb.com/integrations/ai-engines/openai#troubleshooting-guide) This documentation describes the integration of MindsDB with [OpenAI](https://openai.com/) , an AI research organization known for developing AI models like GPT-3 and GPT-4. The integration allows for the deployment of OpenAI models within MindsDB, providing the models with access to data from various data sources. [​](https://docs.mindsdb.com/integrations/ai-engines/openai#prerequisites) Prerequisites ------------------------------------------------------------------------------------------- Before proceeding, ensure the following prerequisites are met: 1. Install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . 2. To use OpenAI within MindsDB, install the required dependencies following [this instruction](https://docs.mindsdb.com/setup/self-hosted/docker#install-dependencies) . 3. Obtain the OpenAI API key required to deploy and use OpenAI models within MindsDB. Follow the [instructions for obtaining the API key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key) . [​](https://docs.mindsdb.com/integrations/ai-engines/openai#setup) Setup --------------------------------------------------------------------------- Create an AI engine from the [OpenAI handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/openai_handler) . Copy Ask AI CREATE ML_ENGINE openai_engine FROM openai USING openai_api_key = 'api-key-value'; Create a model using `openai_engine` as an engine. Copy Ask AI CREATE MODEL openai_model PREDICT target_column USING engine = 'openai_engine', -- engine name as created via CREATE ML_ENGINE api_base = 'base-url', -- optional, replaces the default base URL mode = 'mode_name', -- optional, mode to run the model in model_name = 'openai_model_name', -- optional with default value of gpt-3.5-turbo question_column = 'question', -- optional, column name that stores user input context_column = 'context', -- optional, column that stores context of the user input prompt_template = 'input message to the model here', -- optional, user provides instructions to the model here user_column = 'user_input', -- optional, stores user input assistant_column = 'conversation_context', -- optional, stores conversation context prompt = 'instruction to the model', -- optional stores instruction to the model max_tokens = 100, -- optional, token limit for answer temperature = 0.3, -- temp json_struct = { 'key': 'value', ... }' If you want to update the `prompt_template` parameter, you do not have to recreate the model. Instead, you can override the `prompt_template` parameter at prediction time like this: Copy Ask AI SELECT question, answer FROM openai_model WHERE question = 'input question here' USING prompt_template = 'input new message to the model here'; The following parameters are available to use when creating an OpenAI model: engine This is the engine name as created with the [`CREATE ML_ENGINE`](https://docs.mindsdb.com/mindsdb_sql/sql/create/ml-engine) statement. api\_base This parameter is optional.It replaces the default OpenAI’s base URL with the defined value. mode This parameter is optional.The available modes include `default`, `conversational`, `conversational-full`, `image`, and `embedding`. * The `default` mode is used by default. The model replies to the `prompt_template` message. * The `conversational` mode enables the model to read and reply to multiple messages. * The `conversational-full` mode enables the model to read and reply to multiple messages, one reply per message. * The `image` mode is used to create an image instead of a text reply. * The `embedding` mode enables the model to return output in the form of embeddings. You can find [all models supported by each mode here](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/handlers/openai_handler/constants.py) . model\_name This parameter is optional. By default, the `gpt-3.5-turbo` model is used.You can find [all available models here](https://github.com/mindsdb/mindsdb/blob/main/mindsdb/integrations/handlers/openai_handler/constants.py) . question\_column This parameter is optional. It contains the column name that stores user input. context\_column This parameter is optional. It contains the column name that stores context for the user input. prompt\_template This parameter is optional if you use `question_column`. It stores the message or instructions to the model. _Please note that this parameter can be overridden at prediction time._ max\_tokens This parameter is optional. It defines the maximum token cost of the prediction. _Please note that this parameter can be overridden at prediction time._ temperature This parameter is optional. It defines how _risky_ the answers are. The value of `0` marks a well-defined answer, and the value of `0.9` marks a more creative answer. _Please note that this parameter can be overridden at prediction time._ json\_struct This parameter is optional. It is used to extract JSON data from a text column provided in the `prompt_template` parameter. [See examples here](https://docs.mindsdb.com/use-cases/data_enrichment/json-from-text#extract-json-from-text-data) . [​](https://docs.mindsdb.com/integrations/ai-engines/openai#usage-with-openai-compatible-apis) Usage with OpenAI-Compatible APIs ----------------------------------------------------------------------------------------------------------------------------------- The OpenAI handler can be used with any OpenAI-compatible APIs by providing the `api_base` parameter that stores the base URL of the OpenAI-compatible APIs. Here is an example of how to use the OpenAI handler with OpenRouter, the OpenAI-compatible interface for accessing LLMs. Copy Ask AI CREATE MODEL openrouter_model PREDICT answer USING engine = 'openai_engine', api_base = 'https://openrouter.ai/api/v1', openai_api_key = 'openrouter-api-key', model_name = 'mistralai/devstral-small-2505', prompt_template = 'answer a question: {{question}}'; DESCRIBE openrouter_model; SELECT * FROM openrouter_model WHERE question = 'how many planets are in the solar system?'; When using OpenAI-compatible APIs, it is required to provide the base URL in the `api_base` parameter and the API key in the `openai_api_key` parameter. [​](https://docs.mindsdb.com/integrations/ai-engines/openai#usage) Usage --------------------------------------------------------------------------- Here are the combination of parameters for creating a model: 1. Provide a `prompt_template` alone. 2. Provide a `question_column` and optionally a `context_column`. 3. Provide a `prompt`, `user_column`, and `assistant_column` to create a model in the conversational mode. The following usage examples utilize `openai_engine` to create a model with the `CREATE MODEL` statement. Answering questions without context Here is how to create a model that answers questions without context. Copy Ask AI CREATE MODEL openai_model PREDICT answer USING engine = 'openai_engine', question_column = 'question'; Query the model to get predictions. Copy Ask AI SELECT question, answer FROM openai_model WHERE question = 'Where is Stockholm located?'; Here is the output: Copy Ask AI +---------------------------+-------------------------------+ |question |answer | +---------------------------+-------------------------------+ |Where is Stockholm located?|Stockholm is located in Sweden.| +---------------------------+-------------------------------+ Answering questions with context Here is how to create a model that answers questions with context. Copy Ask AI CREATE MODEL openai_model PREDICT answer USING engine = 'openai_engine', question_column = 'question', context_column = 'context'; Query the model to get predictions. Copy Ask AI SELECT context, question, answer FROM openai_model WHERE context = 'Answer accurately' AND question = 'How many planets exist in the solar system?'; On execution, we get: Copy Ask AI +-------------------+-------------------------------------------+----------------------------------------------+ |context |question |answer | +-------------------+-------------------------------------------+----------------------------------------------+ |Answer accurately |How many planets exist in the solar system?| There are eight planets in the solar system. | +-------------------+-------------------------------------------+----------------------------------------------+ Prompt completion Here is how to create a model that offers the most flexible mode of operation. It answers any query provided in the `prompt_template` parameter. Good prompts are the key to getting great completions out of large language models like the ones that OpenAI offers. For best performance, we recommend you read their [prompting guide](https://beta.openai.com/docs/guides/completion/prompt-design) before trying your hand at prompt templating. Let’s look at an example that reuses the `openai_model` model created earlier and overrides parameters at prediction time. Copy Ask AI SELECT instruction, answer FROM openai_model WHERE instruction = 'Speculate extensively' USING prompt_template = '{{instruction}}. What does Tom Hanks like?', max_tokens = 100, temperature = 0.5; On execution, we get: Copy Ask AI +----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |instruction |answer | +----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |Speculate extensively |Some people speculate that Tom Hanks likes to play golf, while others believe that he enjoys acting and directing. It is also speculated that he likes to spend time with his family and friends, and that he enjoys traveling.| +----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Conversational mode Here is how to create a model in the conversational mode. Copy Ask AI CREATE MODEL openai_chat_model PREDICT response USING engine = 'openai_engine', mode = 'conversational', model_name = 'gpt-3.5-turbo', user_column = 'user_input', assistant_column = 'conversation_history', prompt = 'Answer the question in a helpful way.'; And here is how to query this model: Copy Ask AI SELECT response FROM openai_chat_model WHERE user_input = '' AND conversation_history = ''; **Next Steps**Follow [this tutorial on sentiment analysis](https://docs.mindsdb.com/use-cases/data_enrichment/sentiment-analysis-inside-mysql-with-openai) and [this tutorial on finetuning OpenAI models](https://docs.mindsdb.com/use-cases/automated_finetuning/openai) to see more use case examples. [​](https://docs.mindsdb.com/integrations/ai-engines/openai#troubleshooting-guide) Troubleshooting Guide ----------------------------------------------------------------------------------------------------------- `Authentication Error` * **Symptoms**: Failure to authenticate to the OpenAI API. * **Checklist**: 1. Make sure that your OpenAI account is active. 2. Confirm that your API key is correct. 3. Ensure that your API key has not been revoked. 4. Ensure that you have not exceeded the API usage or rate limit. `SQL statement cannot be parsed by mindsdb_sql` * **Symptoms**: SQL queries failing or not recognizing table and model names containing spaces or special characters. * **Checklist**: 1. Ensure table names with spaces or special characters are enclosed in backticks. Examples: * Incorrect: Copy Ask AI SELECT input.text, output.sentiment FROM integration.travel data AS input JOIN openai_engine AS output * Incorrect: Copy Ask AI SELECT input.text, output.sentiment FROM integration.'travel data' AS input JOIN openai_engine AS output * Correct: Copy Ask AI SELECT input.text, output.sentiment FROM integration.`travel data` AS input JOIN openai_engine AS output Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/integrations/ai-engines/openai.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/ai-engines/openai) ⌘I --- # LangChain - MindsDB [Skip to main content](https://docs.mindsdb.com/integrations/ai-engines/langchain#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation LangChain [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Prerequisites](https://docs.mindsdb.com/integrations/ai-engines/langchain#prerequisites) * [Setup](https://docs.mindsdb.com/integrations/ai-engines/langchain#setup) * [Usage](https://docs.mindsdb.com/integrations/ai-engines/langchain#usage) This documentation describes the integration of MindsDB with [LangChain](https://www.langchain.com/) , a framework for developing applications powered by language models. The integration allows for the deployment of LangChain models within MindsDB, providing the models with access to data from various data sources. [​](https://docs.mindsdb.com/integrations/ai-engines/langchain#prerequisites) Prerequisites ---------------------------------------------------------------------------------------------- Before proceeding, ensure the following prerequisites are met: 1. Install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . 2. To use LangChain within MindsDB, install the required dependencies following [this instruction](https://docs.mindsdb.com/setup/self-hosted/docker#install-dependencies) . 3. Obtain the API key for a selected model provider that you want to use through LangChain. Available models include the following: * OpenAI ([how to get the API key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key) ) * Anthropic ([how to get the API key](https://docs.anthropic.com/claude/docs/getting-access-to-claude) ) * Google ([how to get the API key](http://aistudio.google.com/) ) * Ollama ([how to download Ollama](https://ollama.com/download) ) * LiteLLM (use the API key of the model used via LiteLLM) * MindsDB (use any model created within MindsDB) [​](https://docs.mindsdb.com/integrations/ai-engines/langchain#setup) Setup ------------------------------------------------------------------------------ Create an AI engine from the [LangChain handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/langchain_handler) . Copy Ask AI CREATE ML_ENGINE langchain_engine FROM langchain USING serper_api_key = 'your-serper-api-key'; -- it is an optional parameter (if provided, the model will use serper.dev search to enhance the output) Create a model using `langchain_engine` as an engine and a selected model provider. Copy Ask AI CREATE MODEL langchain_model PREDICT target_column USING engine = 'langchain_engine', -- engine name as created via CREATE ML_ENGINE _api_key = 'api-key-value', -- replace with one of the available values (openai, anthropic, google, litellm) model_name = 'model-name', -- optional, model to be used (for example, 'gpt-4' if 'openai_api_key' provided) prompt_template = 'message to the model that may include some {{input}} columns as variables', max_tokens = 4096; -- defines the maximum number of tokens This handler supports [tracing features for LangChain via LangFuse](https://langfuse.com/docs/integrations/langchain/tracing) . To use it, provide the following parameters in the `USING` clause: * `langfuse_host`, * `langfuse_public_key`, * `langfuse_secret_key`. There are three different tools utilized by this agent: * **MindsDB** is the internal MindsDB executor. * **Metadata** fetches the metadata information for the available tables. * **Write** is able to write agent responses into a MindsDB data source. Each tool exposes the internal MindsDB executor in a different way to perform its tasks, effectively enabling the agent model to read from (and potentially write to) data sources or models available in the active MindsDB project. Create a conversational model using `langchain_engine` as an engine and a selected model provider. OpenAI Copy Ask AI CREATE MODEL langchain_openai_model PREDICT answer USING engine = 'langchain_engine', -- engine name as created via CREATE ML_ENGINE provider = 'openai', -- one of the available providers openai_api_key = 'api-key-value', model_name = 'gpt-3.5-turbo', -- choose one of the available OpenAI models mode = 'conversational', -- conversational mode user_column = 'question', -- column name that stores input from the user assistant_column = 'answer', -- column name that stores output of the model (see PREDICT column) base_url = 'base-url-value', -- optional, default is https://api.openai.com/v1/ verbose = True, prompt_template = 'Answer the users input in a helpful way: {{question}}', max_tokens = 4096; Anthropic Copy Ask AI CREATE MODEL langchain_anthropic_model PREDICT answer USING engine = 'langchain_engine', -- engine name as created via CREATE ML_ENGINE provider = 'anthropic', -- one of the available providers anthropic_api_key = 'api-key-value', model_name = 'claude-2.1', -- choose one of the available OpenAI models mode = 'conversational', -- conversational mode user_column = 'question', -- column name that stores input from the user assistant_column = 'answer', -- column name that stores output of the model (see PREDICT column) verbose = True, prompt_template = 'Answer the users input in a helpful way: {{question}}', max_tokens = 4096; Ollama Copy Ask AI CREATE MODEL langchain_ollama_model PREDICT answer USING engine = 'langchain_engine', -- engine name as created via CREATE ML_ENGINE provider = 'ollama', -- one of the available providers model_name = 'llama2', -- choose one of the models available from Ollama mode = 'conversational', -- conversational mode user_column = 'question', -- column name that stores input from the user assistant_column = 'answer', -- column name that stores output of the model (see PREDICT column) verbose = True, prompt_template = 'Answer the users input in a helpful way: {{question}}', max_tokens = 4096; Ensure to have Ollama set up locally by following this guide on [how to download Ollama](https://ollama.com/download) . LiteLLM Copy Ask AI CREATE MODEL langchain_litellm_model PREDICT answer USING engine = 'langchain_engine', -- engine name as created via CREATE ML_ENGINE provider = 'litellm', -- one of the available providers litellm_api_key = 'api-key-value', model_name = 'gpt-4', -- choose one of the models available from LiteLLM mode = 'conversational', -- conversational mode user_column = 'question', -- column name that stores input from the user assistant_column = 'answer', -- column name that stores output of the model (see PREDICT column) base_url = 'https://ai.dev.mindsdb.com', verbose = True, prompt_template = 'Answer the users input in a helpful way: {{question}}', max_tokens = 4096; Google Copy Ask AI CREATE MODEL langchain_google_model PREDICT answer USING engine = 'langchain_engine', -- engine name as created via CREATE ML_ENGINE provider = 'google', -- one of the available providers google_api_key = 'api-key-value', model_name = 'gemini-1.5-flash', -- choose one of the models available from Google mode = 'conversational', -- conversational mode user_column = 'question', -- column name that stores input from the user assistant_column = 'answer', -- column name that stores output of the model (see PREDICT column) verbose = True, prompt_template = 'Answer the users input in a helpful way: {{question}}', max_tokens = 4096; MindsDB Copy Ask AI CREATE MODEL langchain_mindsdb_model PREDICT answer USING engine = 'langchain_engine', -- engine name as created via CREATE ML_ENGINE provider = 'mindsdb', -- one of the available providers model_name = 'mindsdb_model', -- any model created within MindsDB mode = 'conversational', -- conversational mode user_column = 'question', -- column name that stores input from the user assistant_column = 'answer', -- column name that stores output of the model (see PREDICT column) verbose = True, prompt_template = 'Answer the users input in a helpful way: {{question}}', max_tokens = 4096; [​](https://docs.mindsdb.com/integrations/ai-engines/langchain#usage) Usage ------------------------------------------------------------------------------ The following usage examples utilize `langchain_engine` to create a model with the `CREATE MODEL` statement. Create a model that will be used to ask questions. Copy Ask AI CREATE ML_ENGINE langchain_engine_google FROM langchain; CREATE MODEL langchain_google_model PREDICT answer USING engine = 'langchain_engine_google', provider = 'google', google_api_key = 'api-key-value', model_name = 'gemini-1.5-flash', mode = 'conversational', user_column = 'question', assistant_column = 'answer', verbose = True, prompt_template = 'Answer the users input in a helpful way: {{question}}', max_tokens = 4096; Ask questions. Copy Ask AI SELECT question, answer FROM langchain_google_model WHERE question = 'How many planets are in the solar system?'; **Next Steps**Go to the [Use Cases](https://docs.mindsdb.com/use-cases/overview) section to see more examples. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/integrations/ai-engines/langchain.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/ai-engines/langchain) ⌘I --- # Anthropic - MindsDB [Skip to main content](https://docs.mindsdb.com/integrations/ai-engines/anthropic#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Anthropic [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Prerequisites](https://docs.mindsdb.com/integrations/ai-engines/anthropic#prerequisites) * [Setup](https://docs.mindsdb.com/integrations/ai-engines/anthropic#setup) * [Usage](https://docs.mindsdb.com/integrations/ai-engines/anthropic#usage) This documentation describes the integration of MindsDB with [Anthropic](https://www.anthropic.com/) , an AI research company. The integration allows for the deployment of Anthropic models within MindsDB, providing the models with access to data from various data sources. [​](https://docs.mindsdb.com/integrations/ai-engines/anthropic#prerequisites) Prerequisites ---------------------------------------------------------------------------------------------- Before proceeding, ensure the following prerequisites are met: 1. Install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . 2. To use Anthropic within MindsDB, install the required dependencies following [this instruction](https://docs.mindsdb.com/setup/self-hosted/docker#install-dependencies) . 3. Obtain the Anthropic API key required to deploy and use Anthropic models within MindsDB. Follow the [instructions for obtaining the API key](https://docs.anthropic.com/claude/docs/getting-access-to-claude) . [​](https://docs.mindsdb.com/integrations/ai-engines/anthropic#setup) Setup ------------------------------------------------------------------------------ Create an AI engine from the [Anthropic handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/anthropic_handler) . Copy Ask AI CREATE ML_ENGINE anthropic_engine FROM anthropic USING anthropic_api_key = 'your-anthropic-api-key'; Create a model using `anthropic_engine` as an engine. Copy Ask AI CREATE MODEL anthropic_model PREDICT target_column USING engine = 'anthropic_engine', -- engine name as created via CREATE ML_ENGINE column = 'column_name', -- column that stores input/question to the model max_tokens = , -- max number of tokens to be generated by the model (default is 100) model = 'model_name'; -- choose one of 'claude-instant-1.2', 'claude-2.1', 'claude-3-opus-20240229', 'claude-3-sonnet-20240229' (default is 'claude-2.1') The integrations between Anthropic and MindsDB was implemented using [Anthropic Python SDK](https://github.com/anthropics/anthropic-sdk-python) . [​](https://docs.mindsdb.com/integrations/ai-engines/anthropic#usage) Usage ------------------------------------------------------------------------------ The following usage examples utilize `anthropic_engine` to create a model with the `CREATE MODEL` statement. Create and deploy the Anthropic model within MindsDB to ask any question. Copy Ask AI CREATE MODEL anthropic_model PREDICT answer USING column = 'question', engine = 'anthropic_engine', max_tokens = 300, model = 'claude-2.1'; -- choose one of 'claude-instant-1.2', 'claude-2.1', 'claude-3-opus-20240229', 'claude-3-sonnet-20240229' Where: | Name | Description | | --- | --- | | `column` | It defines the prompt to the model. | | `engine` | It defines the Anthropic engine. | | `max_tokens` | It defines the maximum number of tokens to generate before stopping. | | `model` | It defines model that will complete your prompt. | **Default Model**When you create an Anthropic model in MindsDB, it uses the `claude-2.1` model by default. But you can use other available models by passing the model name to the `model` parameter in the `USING` clause of the `CREATE MODEL` statement. **Default Max Tokens**When you create an Anthropic model in MindsDB, it uses 100 tokens as the maximum by default. But you can adjust this value by passing it to the `max_tokens` parameter in the `USING` clause of the `CREATE MODEL` statement. Query the model to get predictions. Copy Ask AI SELECT question, answer FROM anthropic_model WHERE question = 'Where is Stockholm located?'; Here is the output: Copy Ask AI +-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+ | question | answer | +-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+ | Where is Stockholm located? | Stockholm is the capital and largest city of Sweden. It is located on Sweden's south-central east coast, where Lake Mälaren meets the Baltic Sea. | +-----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+ **Next Steps**Go to the [Use Cases](https://docs.mindsdb.com/use-cases/overview) section to see more examples. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/integrations/ai-engines/anthropic.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/ai-engines/anthropic) ⌘I --- # Cohere - MindsDB [Skip to main content](https://docs.mindsdb.com/integrations/ai-engines/cohere#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Cohere [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Prerequisites](https://docs.mindsdb.com/integrations/ai-engines/cohere#prerequisites) * [Setup](https://docs.mindsdb.com/integrations/ai-engines/cohere#setup) * [Usage](https://docs.mindsdb.com/integrations/ai-engines/cohere#usage) This documentation describes the integration of MindsDB with [Cohere](https://cohere.com/) , a technology company focused on artificial intelligence for the enterprise. The integration allows for the deployment of Cohere models within MindsDB, providing the models with access to data from various data sources. [​](https://docs.mindsdb.com/integrations/ai-engines/cohere#prerequisites) Prerequisites ------------------------------------------------------------------------------------------- Before proceeding, ensure the following prerequisites are met: 1. Install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . 2. To use Cohere within MindsDB, install the required dependencies following [this instruction](https://docs.mindsdb.com/setup/self-hosted/docker#install-dependencies) . 3. Obtain the Cohere API key required to deploy and use Cohere models within MindsDB. Sign up for a Cohere account and request an API key from the Cohere dashboard. Learn more [here](https://cohere.com/pricing) . [​](https://docs.mindsdb.com/integrations/ai-engines/cohere#setup) Setup --------------------------------------------------------------------------- Create an AI engine from the [Cohere handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/cohere_handler) . Copy Ask AI CREATE ML_ENGINE cohere_engine FROM cohere USING cohere_api_key = 'your-cohere-api-key'; Create a model using `cohere_engine` as an engine. Copy Ask AI CREATE MODEL cohere_model PREDICT target_column USING engine = 'cohere_engine', -- engine name as created via CREATE ML_ENGINE task = 'task_name', -- choose one of 'text-summarization', 'text-generation' column = 'column_name'; -- column that stores input/question to the model [​](https://docs.mindsdb.com/integrations/ai-engines/cohere#usage) Usage --------------------------------------------------------------------------- The following usage examples utilize `cohere_engine` to create a model with the `CREATE MODEL` statement. Create a model to predict the answer to a question using the `text-generation` task. Copy Ask AI CREATE MODEL cohere_model PREDICT answer USING engine = 'cohere_engine', task = 'text-generation', column = 'question'; Where: | Name | Description | | --- | --- | | `task` | It defines the task to be accomplished. | | `column` | It defines the column with the text to be acted upon. | | `engine` | It defines the Cohere engine. | Query the model to get predictions. Copy Ask AI SELECT answer FROM cohere_model WHERE question = 'What is the capital of France?'; Here is the output: | answer | | --- | | The capital of France is Paris. Paris is France’s largest city and a major global center for art, culture, fashion, and cuisine. It is renowned for its iconic landmarks such as the Eiffel Tower, Notre-Dame Cathedral, and the Louvre Museum. | **Next Steps**Go to the [Use Cases](https://docs.mindsdb.com/use-cases/overview) section to see more examples. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/integrations/ai-engines/cohere.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/ai-engines/cohere) ⌘I --- # Ollama - MindsDB [Skip to main content](https://docs.mindsdb.com/integrations/ai-engines/ollama#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Ollama [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Prerequisites](https://docs.mindsdb.com/integrations/ai-engines/ollama#prerequisites) * [Setup](https://docs.mindsdb.com/integrations/ai-engines/ollama#setup) * [Usage](https://docs.mindsdb.com/integrations/ai-engines/ollama#usage) This documentation describes the integration of MindsDB with [Ollama](https://ollama.com/) , a tool that enables local deployment of large language models. The integration allows for the deployment of Ollama models within MindsDB, providing the models with access to data from various data sources. [​](https://docs.mindsdb.com/integrations/ai-engines/ollama#prerequisites) Prerequisites ------------------------------------------------------------------------------------------- Before proceeding, ensure the following prerequisites are met: 1. Install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . 2. To use Ollama within MindsDB, install the required dependencies following [this instruction](https://docs.mindsdb.com/setup/self-hosted/docker#install-dependencies) . 3. Follow [this instruction](https://github.com/ollama/ollama?tab=readme-ov-file#ollama) to download Ollama and run models locally. Here are the recommended system specifications: * A working Ollama installation, as in point 3. * For 7B models, at least 8GB RAM is recommended. * For 13B models, at least 16GB RAM is recommended. * For 70B models, at least 64GB RAM is recommended. [​](https://docs.mindsdb.com/integrations/ai-engines/ollama#setup) Setup --------------------------------------------------------------------------- Create an AI engine from the [Ollama handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/ollama_handler) . Copy Ask AI CREATE ML_ENGINE ollama_engine FROM ollama; Create a model using `ollama_engine` as an engine. Copy Ask AI CREATE MODEL ollama_model PREDICT completion USING engine = 'ollama_engine', -- engine name as created via CREATE ML_ENGINE model_name = 'model-name', -- model run with 'ollama run model-name' ollama_serve_url = 'http://localhost:11434'; If you run Ollama and MindsDB in separate Docker containers, use the `localhost` value of the container. For example, `ollama_serve_url = 'http://host.docker.internal:11434'`. You can find [available models here](https://github.com/ollama/ollama?tab=readme-ov-file#model-library) . [​](https://docs.mindsdb.com/integrations/ai-engines/ollama#usage) Usage --------------------------------------------------------------------------- The following usage examples utilize `ollama_engine` to create a model with the `CREATE MODEL` statement. Deploy and use the `llama3` model. First, [download Ollama](https://github.com/ollama/ollama?tab=readme-ov-file#ollama) and run the model locally by executing `ollama pull llama3`. Now deploy this model within MindsDB. Copy Ask AI CREATE MODEL llama3_model PREDICT completion USING engine = 'ollama_engine', model_name = 'llama3'; Models can be run in either the ‘generate’ or ‘embedding’ modes. The ‘generate’ mode is used for text generation, while the ‘embedding’ mode is used to generate embeddings for text.However, these modes can only be used with models that support them. For example, the `moondream` model supports both modes.By default, if the mode is not specified, the model will run in ‘generate’ mode if multiple modes are supported. If only one mode is supported, the model will run in that mode.To specify the mode, use the `mode` parameter in the `CREATE MODEL` statement. For example, `mode = 'embedding'`. Query the model to get predictions. Copy Ask AI SELECT text, completion FROM llama3_model WHERE text = 'Hello'; Here is the output: Copy Ask AI +-------+--------------------------------------------------------------------------------------+ | text | completion | +-------+--------------------------------------------------------------------------------------+ | Hello | Hello back to you! Is there something I can help you with or would you like to chat? | +-------+--------------------------------------------------------------------------------------+ You can override the prompt message as below: Copy Ask AI SELECT text, completion FROM llama3_model WHERE text = 'Hello' USING prompt_template = 'Answer using exactly five words: {{text}}:'; Here is the output: Copy Ask AI +-------+------------------------------+ | text | completion | +-------+------------------------------+ | Hello | Warmly welcome to our space. | +-------+------------------------------+ **Next Steps**Go to the [Use Cases](https://docs.mindsdb.com/use-cases/overview) section to see more examples. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/integrations/ai-engines/ollama.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/ai-engines/ollama) ⌘I --- # Join Models with Tables - MindsDB [Skip to main content](https://docs.mindsdb.com/mindsdb_sql/sql/api/join#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Join Models with Tables [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Description](https://docs.mindsdb.com/mindsdb_sql/sql/api/join#description) * [Syntax](https://docs.mindsdb.com/mindsdb_sql/sql/api/join#syntax) * [Mapping input data to model arguments](https://docs.mindsdb.com/mindsdb_sql/sql/api/join#mapping-input-data-to-model-arguments) * [Example 1](https://docs.mindsdb.com/mindsdb_sql/sql/api/join#example-1) * [Example 2](https://docs.mindsdb.com/mindsdb_sql/sql/api/join#example-2) [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/join#description) Description --------------------------------------------------------------------------------- The `JOIN` clause combines rows from the database table and the model table on a column defined in its implementation. It is used to make batch predictions, as shown in the examples. [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/join#syntax) Syntax ----------------------------------------------------------------------- Here is the syntax that lets you join multiple data tables with multiple models to get all predictions at once. Copy Ask AI SELECT d1.column_name, d2.column_name, m1.column_name, m2.column_name, ... FROM integration_name.table_name_1 [AS] d1 [JOIN integration_name.table_name_2 [AS] d2 ON ...] [JOIN ...] JOIN project_name.model_name_1 [AS] m1 [JOIN project_name.model_name_2 [AS] m2] [JOIN ...] [ON d1.input_data = m1.expected_argument]; Where: | Name | Description | | --- | --- | | `integration_name.table_name_1` | Name of the data source table used as input for making predictions. | | `integration_name.table_name_2` | Optionally, you can join arbitrary number of data source tables. | | `project_name.model_name_1` | Name of the model table used to make predictions. | | `project_name.model_name_2` | Optionally, you can join arbitrary number of models. | ### [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/join#mapping-input-data-to-model-arguments) Mapping input data to model arguments If the input data contains a column named `question` and the model requires an argument named `input`, you can map these columns, as explained below. We have a model that expects to receive `input`: Copy Ask AI CREATE MODEL model_name PREDICT answer USING engine = 'openai', prompt_template = 'provide answers to an input from a user: {{input}}'; We have an input data table that has the following columns: Copy Ask AI +----+-------------------------------------------+ | id | question | +----+-------------------------------------------+ | 1 | How many planets are in the solar system? | | 2 | How many stars are in the solar system? | +----+-------------------------------------------+ Now if you want to get answers to these questions using the model, you need to join the input data table with the model and map the `question` column onto the `input` argument. Copy Ask AI SELECT * FROM input_table AS d JOIN model_name AS m ON d.question = m.input; [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/join#example-1) Example 1 ----------------------------------------------------------------------------- Let’s join the `home_rentals` table with the `home_rentals_model` model using this statement: Copy Ask AI SELECT t.rental_price AS real_price, m.rental_price AS predicted_price, t.number_of_rooms, t.number_of_bathrooms, t.sqft, t.location, t.days_on_market FROM example_db.demo_data.home_rentals AS t JOIN mindsdb.home_rentals_model AS m LIMIT 20; On execution, we get: Copy Ask AI +------------+-----------------+-----------------+---------------------+------+----------+----------------+ | real_price | predicted_price | number_of_rooms | number_of_bathrooms | sqft | location | days_on_market | +------------+-----------------+-----------------+---------------------+------+----------+----------------+ | 3901 | 3886 | 2 | 1 | 917 | great | 13 | | 2042 | 2007 | 0 | 1 | 194 | great | 10 | | 1871 | 1865 | 1 | 1 | 543 | poor | 18 | | 3026 | 3020 | 2 | 1 | 503 | good | 10 | | 4774 | 4748 | 3 | 2 | 1066 | good | 13 | | 4382 | 4388 | 3 | 2 | 816 | poor | 25 | | 2269 | 2272 | 0 | 1 | 461 | great | 6 | | 2284 | 2272 | 1 | 1 | 333 | great | 6 | | 5420 | 5437 | 3 | 2 | 1124 | great | 9 | | 5016 | 4998 | 3 | 2 | 1204 | good | 7 | | 1421 | 1427 | 0 | 1 | 538 | poor | 43 | | 3476 | 3466 | 2 | 1 | 890 | good | 6 | | 5271 | 5255 | 3 | 2 | 975 | great | 6 | | 3001 | 2993 | 2 | 1 | 564 | good | 13 | | 4682 | 4692 | 3 | 2 | 953 | good | 10 | | 1783 | 1738 | 1 | 1 | 493 | poor | 24 | | 1548 | 1543 | 1 | 1 | 601 | poor | 47 | | 1492 | 1491 | 0 | 1 | 191 | good | 12 | | 2431 | 2419 | 0 | 1 | 511 | great | 1 | | 4237 | 4257 | 3 | 2 | 916 | poor | 36 | +------------+-----------------+-----------------+---------------------+------+----------+----------------+ [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/join#example-2) Example 2 ----------------------------------------------------------------------------- Let’s query a time series model using this statement: Copy Ask AI SELECT m.saledate as date, m.ma AS forecast FROM mindsdb.house_sales_model AS m JOIN example_db.demo_data.house_sales AS t WHERE t.saledate > LATEST AND t.type = 'house' LIMIT 4; On execution, we get: Copy Ask AI +----------+------------------+ |date |forecast | +----------+------------------+ |2019-12-31|517506.31349071994| |2019-12-31|627822.6592658638 | |2019-12-31|953426.9545788583 | |2019-12-31|767252.4205039773 | +----------+------------------+ Follow [this doc page](https://docs.mindsdb.com/generative-ai-tables#working-with-generative-ai-tables) to see examples of joining multiple data table with multiple models. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/mindsdb_sql/sql/api/join.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/mindsdb_sql/sql/api/join) ⌘I --- # Model Management - MindsDB [Skip to main content](https://docs.mindsdb.com/features/model-management#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Model Management [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) MindsDB abstracts AI models, making them accessible from enterprise data environments. ![](https://mintcdn.com/mindsdb/iK5MN5UH2_93kMSg/assets/model-management.png?w=2500&fit=max&auto=format&n=iK5MN5UH2_93kMSg&q=85&s=c7927dbdeba11d8ea5e656fad09b2b8c) MindsDB enables you to manage every aspect of AI models. With MindsDB, you can [CREATE MODEL](https://docs.mindsdb.com/mindsdb_sql/sql/create/model) , [FINETUNE](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune) , [RETRAIN](https://docs.mindsdb.com/mindsdb_sql/sql/api/retrain) , and more. * [Deploy](https://docs.mindsdb.com/mindsdb_sql/sql/create/model) You can [create, train, and deploy AI models](https://docs.mindsdb.com/mindsdb_sql/sql/create/model) based on popular [AI/ML frameworks](https://docs.mindsdb.com/integrations/ai-overview) within MindsDB. * [Fine-tune](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune) You can [fine-tune models](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune) with data from various [data sources](https://docs.mindsdb.com/integrations/data-overview) connected to MindsDB. Check out [examples here](https://docs.mindsdb.com/use-cases/automated_finetuning/overview) . * [Automate](https://docs.mindsdb.com/mindsdb_sql/sql/create/jobs) You can automate tasks, including retraining or fine-tuning of AI models, to keep your AI system up-to-date. See [examples here](https://docs.mindsdb.com/use-cases/ai_workflow_automation/overview) . Go ahead and create an AI model!Use [SQL API](https://docs.mindsdb.com/mindsdb_sql/overview) , [REST API](https://docs.mindsdb.com/rest/overview) , or one of the [SDKs](https://docs.mindsdb.com/sdks/overview) to create and deploy AI models within MindsDB. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/features/model-management.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/features/model-management) ⌘I --- # Google Gemini - MindsDB [Skip to main content](https://docs.mindsdb.com/integrations/ai-engines/google_gemini#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Google Gemini [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Prerequisites](https://docs.mindsdb.com/integrations/ai-engines/google_gemini#prerequisites) * [Setup](https://docs.mindsdb.com/integrations/ai-engines/google_gemini#setup) * [Usage](https://docs.mindsdb.com/integrations/ai-engines/google_gemini#usage) This documentation describes the integration of MindsDB with [Google Gemini](https://docs.mindsdb.com/integrations/ai-engines/link) , a generative artificial intelligence model developed by Google. The integration allows for the deployment of Google Gemini models within MindsDB, providing the models with access to data from various data sources. [​](https://docs.mindsdb.com/integrations/ai-engines/google_gemini#prerequisites) Prerequisites -------------------------------------------------------------------------------------------------- Before proceeding, ensure the following prerequisites are met: 1. Install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . 2. To use Google Gemini within MindsDB, install the required dependencies following [this instruction](https://docs.mindsdb.com/setup/self-hosted/docker#install-dependencies) . 3. Obtain the Google Gemini API key required to deploy and use Google Gemini models within MindsDB. Follow the [instructions for obtaining the API key](https://ai.google.dev/gemini-api/docs/api-key) . [​](https://docs.mindsdb.com/integrations/ai-engines/google_gemini#setup) Setup ---------------------------------------------------------------------------------- Create an AI engine from the [Google Gemini handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/google_gemini_handler) . Copy Ask AI CREATE ML_ENGINE google_gemini_engine FROM google_gemini USING api_key = 'api-key-value'; Create a model using `google_gemini_engine` as an engine. Copy Ask AI CREATE MODEL google_gemini_model PREDICT target_column USING engine = 'google_gemini_engine', -- engine name as created via CREATE ML_ENGINE question_column = 'input_column', -- column name that stores user input model_name = 'gemini-2.0-flash'; -- model name to be used [​](https://docs.mindsdb.com/integrations/ai-engines/google_gemini#usage) Usage ---------------------------------------------------------------------------------- The following usage examples utilize `google_gemini_engine` to create a model with the `CREATE MODEL` statement. Create a model to generate text completions with the Gemini Pro model for your existing text data. Copy Ask AI CREATE MODEL google_gemini_model PREDICT answer USING engine = 'google_gemini_engine', question_column = 'question', model_name = 'gemini-2.0-flash'; Query the model to get predictions. Copy Ask AI SELECT question, answer FROM google_gemini_model WHERE question = 'How are you?'; Alternatively, you can query for batch predictions: Copy Ask AI SELECT t.question, m.answer FROM google_gemini_model AS m JOIN data_table AS t; **Next Steps**Go to the [Use Cases](https://docs.mindsdb.com/use-cases/overview) section to see more examples. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/integrations/ai-engines/google_gemini.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/ai-engines/google_gemini) ⌘I --- # Vertex AI - MindsDB [Skip to main content](https://docs.mindsdb.com/integrations/ai-engines/vertex#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Vertex AI [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Prerequisites](https://docs.mindsdb.com/integrations/ai-engines/vertex#prerequisites) * [Setup](https://docs.mindsdb.com/integrations/ai-engines/vertex#setup) * [Usage](https://docs.mindsdb.com/integrations/ai-engines/vertex#usage) This documentation describes the integration of MindsDB with [Vertex AI](https://cloud.google.com/vertex-ai) , a machine learning platform that lets you train and deploy ML models and AI applications, and customize large language models (LLMs) for use in AI-powered applications. The integration allows for the deployment of Vertex AI models within MindsDB, providing the models with access to data from various data sources. [​](https://docs.mindsdb.com/integrations/ai-engines/vertex#prerequisites) Prerequisites ------------------------------------------------------------------------------------------- Before proceeding, ensure the following prerequisites are met: 1. Install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . 2. To use Vertex AI within MindsDB, install the required dependencies following [this instruction](https://docs.mindsdb.com/setup/self-hosted/docker#install-dependencies) . [​](https://docs.mindsdb.com/integrations/ai-engines/vertex#setup) Setup --------------------------------------------------------------------------- Create an AI engine from the [Vertex AI handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/vertex_handler) . This command creates a config object that can be used in client creation step. Copy Ask AI CREATE ML_ENGINE vertex_engine FROM vertex USING project_id = "mindsdb-401709", location = "us-central1", staging_bucket = "gs://my_staging_bucket", experiment = "my-experiment", experiment_description = "my experiment description", service_account = { }; Create a model using `vertex_engine` as an engine. This command authenticates client to a Vertex account using config from previous step. If the endpoint for the model already exists, we create this model in MindsDB. Otherwise, we create and deploy the model to the endpoint before creating this model in MindsDB. Copy Ask AI CREATE MODEL vertex_model PREDICT target_column USING engine = 'vertex_engine', -- engine name as created via CREATE ML_ENGINE model_name = 'model_name', -- choose one of models from your project custom_model = value; -- indicate whether it is a custom model (True) or not (False) ; [​](https://docs.mindsdb.com/integrations/ai-engines/vertex#usage) Usage --------------------------------------------------------------------------- The following usage examples utilize `vertex_engine` to create a model with the `CREATE MODEL` statement. Detect anomaly using a custom model stored in Vertex AI. Copy Ask AI CREATE MODEL vertex_model PREDICT cut USING engine = 'vertex', model_name = 'diamonds_anomaly_detection', custom_model = True; Query the model to get predictions by joining it with the data table. Copy Ask AI SELECT d.cut, m.cut AS anomaly FROM data_table as d JOIN vertex_model as m; **Next Steps**Go to the [Use Cases](https://docs.mindsdb.com/use-cases/overview) section to see more examples.> Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/integrations/ai-engines/vertex.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/ai-engines/vertex) ⌘I --- # Hugging Face Inference API - MindsDB [Skip to main content](https://docs.mindsdb.com/integrations/ai-engines/huggingface_inference_api#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Hugging Face Inference API [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Prerequisites](https://docs.mindsdb.com/integrations/ai-engines/huggingface_inference_api#prerequisites) * [Setup](https://docs.mindsdb.com/integrations/ai-engines/huggingface_inference_api#setup) * [Usage](https://docs.mindsdb.com/integrations/ai-engines/huggingface_inference_api#usage) This documentation describes the integration of MindsDB with [Hugging Face Inference API](https://huggingface.co/inference-api/serverless) . The integration allows for the deployment of Hugging Face models through Inference API within MindsDB, providing the models with access to data from various data sources. [​](https://docs.mindsdb.com/integrations/ai-engines/huggingface_inference_api#prerequisites) Prerequisites -------------------------------------------------------------------------------------------------------------- Before proceeding, ensure the following prerequisites are met: 1. Install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . 2. To use Hugging Face Inference API within MindsDB, install the required dependencies following [this instruction](https://docs.mindsdb.com/setup/self-hosted/docker#install-dependencies) . 3. Obtain the API key for Hugging Face Inference API required to deploy and use Hugging Face models through Inference API within MindsDB. Generate tokens in the `Settings -> Access Tokens` tab of the Hugging Face account. [​](https://docs.mindsdb.com/integrations/ai-engines/huggingface_inference_api#setup) Setup ---------------------------------------------------------------------------------------------- Create an AI engine from the [Hugging Face Inference API handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/huggingface_api_handler) . Copy Ask AI CREATE ML_ENGINE huggingface_api_engine FROM huggingface_api USING huggingface_api_api_key = 'api-key-value'; Create a model using `huggingface_api_engine` as an engine. Copy Ask AI CREATE MODEL huggingface_api_model PREDICT target_column USING engine = 'huggingface_api_engine', -- engine name as created via CREATE ML_ENGINE task = 'task_name', -- choose one of 'text-classification', 'text-generation', 'question-answering', 'sentence-similarity', 'zero-shot-classification', 'summarization', 'fill-mask', 'image-classification', 'object-detection', 'automatic-speech-recognition', 'audio-classification' input_column = 'column_name', -- column that stores input/question to the model labels = ['label 1', 'label 2']; -- labels used to classify data (used for classification tasks) The following parameters are supported in the `USING` clause of the `CREATE MODEL` statement: | Parameter | Required | Description | | --- | --- | --- | | `engine` | Yes | It is the name of the ML engine created with the `CREATE ML_ENGINE` statement. | | `task` | Only if `model_name` is not provided | It describes a task to be performed. | | `model_name` | Only if `task` is not provided | It specifies a model to be used. | | `input_column` | Yes | It is the name of the column that stores input to the model. | | `endpoint` | No | It defines the endpoint to use for API calls. If not specified, the hosted Inference API from Hugging Face will be used. | | `options` | No | It is a JSON object containing additional options to pass to the API call. More information about the available options for each task can be found [here](https://huggingface.co/docs/api-inference/detailed_parameters)
. | | `parameters` | No | It is a JSON object containing additional parameters to pass to the API call. More information about the available parameters for each task can be found [here](https://huggingface.co/docs/api-inference/detailed_parameters)
. | | `context_column` | Only if `task` is `question-answering` | It is used for the `question-answering` task to provide context to the question. | | `input_column2` | Only if `task` is `sentence-similarity` | It is used for the `sentence-similarity` task to provide the second input sentence for comparison. | | `candidate_labels` | Only if `task` is `zero-shot-classification` | It is used for the `zero-shot-classification` task to classify input data according to provided labels. | [​](https://docs.mindsdb.com/integrations/ai-engines/huggingface_inference_api#usage) Usage ---------------------------------------------------------------------------------------------- The following usage examples utilize `huggingface_api_engine` to create a model with the `CREATE MODEL` statement. Create a model to classify input text as spam or ham. Copy Ask AI CREATE MODEL spam_classifier PREDICT is_spam USING engine = 'huggingface_api_engine', task = 'text-classification', column = 'text'; Query the model to get predictions. Copy Ask AI SELECT text, is_spam FROM spam_classifier WHERE text = 'Subscribe to this channel asap'; Here is the output: Copy Ask AI +--------------------------------+---------+ | text | is_spam | +--------------------------------+---------+ | Subscribe to this channel asap | spam | +--------------------------------+---------+ Find more quick examples below: Text Classification Copy Ask AI CREATE MODEL mindsdb.hf_text_classifier PREDICT sentiment USING task = 'text-classification', engine = 'hf_api_engine', input_column = 'text'; Fill Mask Copy Ask AI CREATE MODEL mindsdb.hf_fill_mask PREDICT sequence USING task = 'fill-mask', engine = 'hf_api_engine', input_column = 'text'; Summarization Copy Ask AI CREATE MODEL mindsdb.hf_summarizer PREDICT summary USING task = 'summarization', engine = 'hf_api_engine', input_column = 'text'; Text Generation Copy Ask AI CREATE MODEL mindsdb.hf_text_generator PREDICT generated_text USING task = 'text-generation', engine = 'hf_api_engine', input_column = 'text'; Question Answering Copy Ask AI CREATE MODEL mindsdb.hf_question_answerer PREDICT answer USING task = 'question-answering', engine = 'hf_api_engine', input_column = 'question', context_column = 'context'; Sentences Similarity Copy Ask AI CREATE MODEL mindsdb.hf_sentence_similarity PREDICT similarity USING task = 'sentence-similarity', engine = 'hf_api_engine', input_column = 'sentence1', input_column2 = 'sentence2'; Zero Shot Classification Copy Ask AI CREATE MODEL mindsdb.hf_zero_shot_classifier PREDICT label USING task = 'zero-shot-classification', engine = 'hf_api_engine', input_column = 'text', candidate_labels = ['label1', 'label2', 'label3']; Image Classification Copy Ask AI CREATE MODEL mindsdb.hf_image_classifier PREDICT label USING task = 'image-classification', engine = 'hf_api_engine', input_column = 'image_url'; Object Detection Copy Ask AI CREATE MODEL mindsdb.hf_object_detector PREDICT objects USING task = 'object-detection', engine = 'hf_api_engine', input_column = 'image_url'; Automatic Speech Recognition Copy Ask AI CREATE MODEL mindsdb.hf_speech_recognizer PREDICT transcription USING task = 'automatic-speech-recognition', engine = 'hf_api_engine', input_column = 'audio_url'; Audio Classification Copy Ask AI CREATE MODEL mindsdb.hf_audio_classifier PREDICT label USING task = 'audio-classification', engine = 'hf_api_engine', input_column = 'audio_url'; **Next Steps**Follow [this link](https://docs.mindsdb.com/sql/tutorials/hugging-face-inference-api-examples) to see more use case examples. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/integrations/ai-engines/huggingface_inference_api.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/ai-engines/huggingface_inference_api) ⌘I --- # Hugging Face - MindsDB [Skip to main content](https://docs.mindsdb.com/integrations/ai-engines/huggingface#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Hugging Face [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Prerequisites](https://docs.mindsdb.com/integrations/ai-engines/huggingface#prerequisites) * [Setup](https://docs.mindsdb.com/integrations/ai-engines/huggingface#setup) * [Usage](https://docs.mindsdb.com/integrations/ai-engines/huggingface#usage) This documentation describes the integration of MindsDB with [Hugging Face](https://huggingface.co/) , a company that develops computer tools for building applications using machine learning. The integration allows for the deployment of Hugging Face models within MindsDB, providing the models with access to data from various data sources. [​](https://docs.mindsdb.com/integrations/ai-engines/huggingface#prerequisites) Prerequisites ------------------------------------------------------------------------------------------------ Before proceeding, ensure the following prerequisites are met: 1. Install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . 2. To use Hugging Face within MindsDB, install the required dependencies following [this instruction](https://docs.mindsdb.com/setup/self-hosted/docker#install-dependencies) . [​](https://docs.mindsdb.com/integrations/ai-engines/huggingface#setup) Setup -------------------------------------------------------------------------------- Create an AI engine from the [Hugging Face handler](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/huggingface_handler) . Copy Ask AI CREATE ML_ENGINE huggingface_engine FROM huggingface USING huggingface_api_api_key = 'hf_xxx'; Create a model using `huggingface_engine` as an engine. Copy Ask AI CREATE MODEL huggingface_model PREDICT target_column USING engine = 'huggingface_engine', -- engine name as created via CREATE ML_ENGINE model_name = 'hf_hub_model_name', -- choose one of PyTorch models from the Hugging Face Hub task = 'task_name', -- choose one of 'text-classification', 'text-generation', 'zero-shot-classification', 'translation', 'summarization', 'text2text-generation', 'fill-mask' input_column = 'column_name', -- column that stores input/question to the model labels = ['label 1', 'label 2']; -- labels used to classify data (used for classification tasks) [​](https://docs.mindsdb.com/integrations/ai-engines/huggingface#usage) Usage -------------------------------------------------------------------------------- The following usage examples utilize `huggingface_engine` to create a model with the `CREATE MODEL` statement. Create a model to classify input text as spam or ham. Copy Ask AI CREATE MODEL spam_classifier PREDICT spam_or_ham USING engine = 'huggingface_engine', model_name = 'mrm8488/bert-tiny-finetuned-sms-spam-detection', task = 'text-classification', input_column = 'text', labels = ['ham', 'spam']; Query the model to get predictions. Copy Ask AI SELECT text, spam_or_ham FROM spam_classifier WHERE text = 'Subscribe to this channel asap'; Here is the output: Copy Ask AI +--------------------------------+-------------+ | text | spam_or_ham | +--------------------------------+-------------+ | Subscribe to this channel asap | spam | +--------------------------------+-------------+ **Next Steps**Follow [this link](https://docs.mindsdb.com/sql/tutorials/hugging-face-examples) to see more use case examples. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/integrations/ai-engines/huggingface.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/integrations/ai-engines/huggingface) ⌘I --- # Predict Customer Churn with MindsDB - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Predict Customer Churn with MindsDB [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Introduction](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#introduction) * [Data Setup](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#data-setup) * [Connecting the Data](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#connecting-the-data) * [Understanding the Data](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#understanding-the-data) * [Training a Predictor](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#training-a-predictor) * [Status of a Predictor](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#status-of-a-predictor) * [Making Predictions](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#making-predictions) * [Making a Single Prediction](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#making-a-single-prediction) * [Making Batch Predictions](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#making-batch-predictions) * [What’s Next?](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#what%E2%80%99s-next) This tutorial uses the Lightwood integration that requires the `mindsdb/mindsdb:lightwood` Docker image. [Learn more here](https://docs.mindsdb.com/setup/self-hosted/docker#install-mindsdb) . [​](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#introduction) Introduction -------------------------------------------------------------------------------------------------- In this tutorial, we’ll create and train a machine learning model, or as we call it, an `AI Table` or a `predictor`. By querying the model, we’ll predict the probability of churn for new customers of a telecoms company. Install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . Let’s get started. [​](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#data-setup) Data Setup ---------------------------------------------------------------------------------------------- ### [​](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#connecting-the-data) Connecting the Data There are a couple of ways you can get the data to follow through with this tutorial. * Connecting as a database * Connecting as a file You can connect to a demo database that we’ve prepared for you. It contains the data used throughout this tutorial (the `example_db.demo_data.customer_churn` table). Copy Ask AI CREATE DATABASE example_db WITH ENGINE = "postgres", PARAMETERS = { "user": "demo_user", "password": "demo_password", "host": "samples.mindsdb.com", "port": "5432", "database": "demo" }; Now you can run queries directly on the demo database. Let’s preview the data that we’ll use to train our predictor. Copy Ask AI SELECT * FROM example_db.demo_data.customer_churn LIMIT 10; You can download [the `CSV` data file here](https://github.com/mindsdb/mindsdb-examples/blob/master/classics/customer_churn/raw_data/WA_Fn-UseC_-Telco-Customer-Churn.csv) and upload it via [MindsDB SQL Editor](https://docs.mindsdb.com/connect/mindsdb_editor) .Follow [this guide](https://docs.mindsdb.com/sql/create/file) to find out how to upload a file to MindsDB.Now you can run queries directly on the file as if it were a table. Let’s preview the data that we’ll use to train our predictor. Copy Ask AI SELECT * FROM files.churn LIMIT 10; **Pay Attention to the Queries** From now on, we’ll use the `files.churn` file as a table. Make sure you replace it with `example_db.demo_data.customer_churn` if you connect the data as a database. ### [​](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#understanding-the-data) Understanding the Data We use the customer churn dataset, where each row is one customer, to predict whether the customer is going to stop using the company products. Below is the sample data stored in the `files.churn` table. Copy Ask AI +----------+------+-------------+-------+----------+------+------------+----------------+---------------+--------------+------------+----------------+-----------+-----------+---------------+--------------+----------------+-------------------------+--------------+------------+-----+ |customerID|gender|SeniorCitizen|Partner|Dependents|tenure|PhoneService|MultipleLines |InternetService|OnlineSecurity|OnlineBackup|DeviceProtection|TechSupport|StreamingTV|StreamingMovies|Contract |PaperlessBilling|PaymentMethod |MonthlyCharges|TotalCharges|Churn| +----------+------+-------------+-------+----------+------+------------+----------------+---------------+--------------+------------+----------------+-----------+-----------+---------------+--------------+----------------+-------------------------+--------------+------------+-----+ |7590-VHVEG|Female|0 |Yes |No |1 |No |No phone service|DSL |No |Yes |No |No |No |No |Month-to-month|Yes |Electronic check |29.85 |29.85 |No | |5575-GNVDE|Male |0 |No |No |34 |Yes |No |DSL |Yes |No |Yes |No |No |No |One year |No |Mailed check |56.95 |1889.5 |No | |3668-QPYBK|Male |0 |No |No |2 |Yes |No |DSL |Yes |Yes |No |No |No |No |Month-to-month|Yes |Mailed check |53.85 |108.15 |Yes | |7795-CFOCW|Male |0 |No |No |45 |No |No phone service|DSL |Yes |No |Yes |Yes |No |No |One year |No |Bank transfer (automatic)|42.3 |1840.75 |No | |9237-HQITU|Female|0 |No |No |2 |Yes |No |Fiber optic |No |No |No |No |No |No |Month-to-month|Yes |Electronic check |70.7 |151.65 |Yes | +----------+------+-------------+-------+----------+------+------------+----------------+---------------+--------------+------------+----------------+-----------+-----------+---------------+--------------+----------------+-------------------------+--------------+------------+-----+ Where: | Column | Description | Data Type | Usage | | --- | --- | --- | --- | | `CustomerId` | The identification number of a customer. | `character varying` | Feature | | `Gender` | The gender of a customer. | `character varying` | Feature | | `SeniorCitizen` | It indicates whether the customer is a senior citizen (`1`) or not (`0`). | `integer` | Feature | | `Partner` | It indicates whether the customer has a partner (`Yes`) or not (`No`). | `character varying` | Feature | | `Dependents` | It indicates whether the customer has dependents (`Yes`) or not (`No`). | `character varying` | Feature | | `Tenure` | Number of months the customer has been staying with the company. | `integer` | Feature | | `PhoneService` | It indicates whether the customer has a phone service (`Yes`) or not (`No`). | `character varying` | Feature | | `MultipleLines` | It indicates whether the customer has multiple lines (`Yes`) or not (`No`, `No phone service`). | `character varying` | Feature | | `InternetService` | Customer’s internet service provider (`DSL`, `Fiber optic`, `No`). | `character varying` | Feature | | `OnlineSecurity` | It indicates whether the customer has online security (`Yes`) or not (`No`, `No internet service`). | `character varying` | Feature | | `OnlineBackup` | It indicates whether the customer has online backup (`Yes`) or not (`No`, `No internet service`). | `character varying` | Feature | | `DeviceProtection` | It indicates whether the customer has device protection (`Yes`) or not (`No`, `No internet service`). | `character varying` | Feature | | `TechSupport` | It indicates whether the customer has tech support (`Yes`) or not (`No`, `No internet service`). | `character varying` | Feature | | `StreamingTv` | It indicates whether the customer has streaming TV (`Yes`) or not (`No`, `No internet service`). | `character varying` | Feature | | `StreamingMovies` | It indicates whether the customer has streaming movies (`Yes`) or not (`No`, `No internet service`). | `character varying` | Feature | | `Contract` | The contract term of the customer (`Month-to-month`, `One year`, `Two year`). | `character varying` | Feature | | `PaperlessBilling` | It indicates whether the customer has paperless billing (`Yes`) or not (`No`). | `character varying` | Feature | | `PaymentMethod` | Customer’s payment method (`Electronic check`, `Mailed check`, `Bank transfer (automatic)`, `Credit card (automatic)`). | `character varying` | Feature | | `MonthlyCharges` | The monthly charge amount. | `money` | Feature | | `TotalCharges` | The total amount charged to the customer. | `money` | Feature | | `Churn` | It indicates whether the customer churned (`Yes`) or not (`No`). | `character varying` | Label | **Labels and Features**A **label** is a column whose values will be predicted (the y variable in simple linear regression).A **feature** is a column used to train the model (the x variable in simple linear regression). [​](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#training-a-predictor) Training a Predictor ------------------------------------------------------------------------------------------------------------------ Let’s create and train the machine learning model. For that, we use the [`CREATE MODEL`](https://docs.mindsdb.com/sql/create/model) statement and specify the input columns used to train `FROM` (features) and what we want to `PREDICT` (labels). Copy Ask AI CREATE MODEL mindsdb.customer_churn_predictor FROM files (SELECT * FROM churn) PREDICT Churn; We use all of the columns as features, except for the `Churn` column, whose values will be predicted. [​](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#status-of-a-predictor) Status of a Predictor -------------------------------------------------------------------------------------------------------------------- A predictor may take a couple of minutes for the training to complete. You can monitor the status of the predictor by using this SQL command: Copy Ask AI DESCRIBE customer_churn_predictor; If we run it right after creating a predictor, we get this output: Copy Ask AI +------------+ | status | +------------+ | generating | +------------+ A bit later, this is the output: Copy Ask AI +----------+ | status | +----------+ | training | +----------+ And at last, this should be the output: Copy Ask AI +----------+ | status | +----------+ | complete | +----------+ Now, if the status of our predictor says `complete`, we can start making predictions! [​](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#making-predictions) Making Predictions -------------------------------------------------------------------------------------------------------------- ### [​](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#making-a-single-prediction) Making a Single Prediction You can make predictions by querying the predictor as if it were a table. The [`SELECT`](https://docs.mindsdb.com/sql/api/select) statement lets you make predictions for the label based on the chosen features. Copy Ask AI SELECT Churn, Churn_confidence, Churn_explain FROM mindsdb.customer_churn_predictor WHERE SeniorCitizen=0 AND Partner='Yes' AND Dependents='No' AND tenure=1 AND PhoneService='No' AND MultipleLines='No phone service' AND InternetService='DSL'; On execution, we get: Copy Ask AI +-------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Churn | Churn_confidence | Churn_explain | +-------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Yes | 0.7752808988764045 | {"predicted_value": "Yes", "confidence": 0.7752808988764045, "anomaly": null, "truth": null, "probability_class_No": 0.4756, "probability_class_Yes": 0.5244} | +-------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+ To get more accurate predictions, we should provide as much data as possible in the `WHERE` clause. Let’s run another query. Copy Ask AI SELECT Churn, Churn_confidence, Churn_explain FROM mindsdb.customer_churn_predictor WHERE SeniorCitizen=0 AND Partner='Yes' AND Dependents='No' AND tenure=1 AND PhoneService='No' AND MultipleLines='No phone service' AND InternetService='DSL' AND Contract='Month-to-month' AND MonthlyCharges=29.85 AND TotalCharges=29.85 AND OnlineBackup='Yes' AND OnlineSecurity='No' AND DeviceProtection='No' AND TechSupport='No' AND StreamingTV='No' AND StreamingMovies='No' AND PaperlessBilling='Yes' AND PaymentMethod='Electronic check'; On execution, we get: Copy Ask AI +-------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Churn | Churn_confidence | Churn_explain | +-------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Yes | 0.8202247191011236 | {"predicted_value": "Yes", "confidence": 0.8202247191011236, "anomaly": null, "truth": null, "probability_class_No": 0.4098, "probability_class_Yes": 0.5902} | +-------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+ MindsDB predicted the probability of this customer churning with confidence of around 82%. The previous query predicted it with confidence of around 79%. So providing more data improved the confidence level of predictions. ### [​](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#making-batch-predictions) Making Batch Predictions Also, you can make bulk predictions by joining a data table with your predictor using [`JOIN`](https://docs.mindsdb.com/sql/api/join) . Copy Ask AI SELECT t.customerID, t.Contract, t.MonthlyCharges, m.Churn FROM files.churn AS t JOIN mindsdb.customer_churn_predictor AS m LIMIT 100; On execution, we get: Copy Ask AI +----------------+-------------------+------------------+---------+ | customerID | Contract | MonthlyCharges | Churn | +----------------+-------------------+------------------+---------+ | 7590-VHVEG | Month-to-month | 29.85 | Yes | | 5575-GNVDE | One year | 56.95 | No | | 3668-QPYBK | Month-to-month | 53.85 | Yes | | 7795-CFOCW | One year | 42.3 | No | | 9237-HQITU | Month-to-month | 70.7 | Yes | +----------------+-------------------+------------------+---------+ [​](https://docs.mindsdb.com/use-cases/in-database_ml/customer-churn#what%E2%80%99s-next) What’s Next? --------------------------------------------------------------------------------------------------------- Have fun while trying it out yourself! * Bookmark [MindsDB repository on GitHub](https://github.com/mindsdb/mindsdb) . * Install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . * Engage with the MindsDB community on [Slack](https://mindsdb.com/joincommunity) or [GitHub](https://github.com/mindsdb/mindsdb/discussions) to ask questions and share your ideas and thoughts. If this tutorial was helpful, please give us a GitHub star [here](https://github.com/mindsdb/mindsdb) . Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/in-database_ml/customer-churn.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/in-database_ml/customer-churn) ⌘I --- # Finetune a Model - MindsDB [Skip to main content](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Finetune a Model [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Description](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune#description) * [Syntax](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune#syntax) * [Examples](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune#examples) * [Example 1: OpenAI Model Fine-Tuning](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune#example-1%3A-openai-model-fine-tuning) * [Example 2: Regression Model Fine-Tuning](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune#example-2%3A-regression-model-fine-tuning) * [Example 3: Classification Model Fine-Tuning](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune#example-3%3A-classification-model-fine-tuning) [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune#description) Description ------------------------------------------------------------------------------------- The `FINETUNE` statement lets you retrain a model with additional training data. ![](https://docs.google.com/drawings/d/e/2PACX-1vTwrR36VeRCMQYZ7AMQXS1gzMtgv6URfIlKFTUqZiTSZwsuXjiZCi8tIr4yU7NBs3_IuGzKgelvQ8l9/pub?w=955&h=460) Imagine you have a model that was trained with a certain dataset. Now there is more training data available and you wish to retrain this model with a new dataset. The `FINETUNE` statement lets you partially retrain the model, so it takes less time and resources than the [`RETRAIN`](https://docs.mindsdb.com/sql/api/retrain) statement. In the machine learning literature, this is also referred to as _fine-tuning_ a model. [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune#syntax) Syntax --------------------------------------------------------------------------- Here is the syntax: Copy Ask AI FINETUNE [MODEL] project_name.model_name FROM [integration_name | project_name] (SELECT column_name, ... FROM [integration_name. | project_name.]table_name [WHERE incremental_column > LAST]) [USING\ key = value,\ ...]; Where: | Expressions | Description | | --- | --- | | `project_name` | Name of the project where the model resides. | | `model_name` | Name of the model to be retrained. | | `integration_name` | Name of the integration created using the [`CREATE DATABASE`](https://docs.mindsdb.com/sql/create/database)
statement or file upload. | | `(SELECT column_name, ... FROM table_name)` | Selecting additional data to be used for retraining. | | `WHERE incremental_column > LAST` | Selecting only newly added data to be used to finetune the model. Learn more about the [`LAST` keyword here](https://docs.mindsdb.com/mindsdb_sql/sql/create/jobs#last)
. | | `USING key = value` | Optional. The `USING` clause lets you pass multiple parameters to the `FINETUNE` statement. | **Model Versions**Every time the model is finetuned or retrained, its new version is created with an incremented version number. Unless overridden, the most recent version becomes active when training completes.You can query for all model versions like this: Copy Ask AI SELECT * FROM project_name.models; For more information on managing model versions, check out our docs [here](https://docs.mindsdb.com/sql/api/manage-models-versions) . While the model is being generated and trained, it is not active. The model becomes active only after it completes generating and training. [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune#examples) Examples ------------------------------------------------------------------------------- ### [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune#example-1:-openai-model-fine-tuning) Example 1: [OpenAI Model Fine-Tuning](https://docs.mindsdb.com/finetune/openai) ### [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune#example-2:-regression-model-fine-tuning) Example 2: [Regression Model Fine-Tuning](https://docs.mindsdb.com/finetune/regression) ### [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune#example-3:-classification-model-fine-tuning) Example 3: [Classification Model Fine-Tuning](https://docs.mindsdb.com/finetune/classification) Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/mindsdb_sql/sql/api/finetune.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/mindsdb_sql/sql/api/finetune) ⌘I --- # Sentiment Analysis with MindsDB and OpenAI using SQL - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/data_enrichment/sentiment-analysis-inside-mysql-with-openai#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Sentiment Analysis with MindsDB and OpenAI using SQL [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Introduction](https://docs.mindsdb.com/use-cases/data_enrichment/sentiment-analysis-inside-mysql-with-openai#introduction) * [Prerequisites](https://docs.mindsdb.com/use-cases/data_enrichment/sentiment-analysis-inside-mysql-with-openai#prerequisites) * [Tutorial](https://docs.mindsdb.com/use-cases/data_enrichment/sentiment-analysis-inside-mysql-with-openai#tutorial) * [Leverage the NLP Capabilities with MindsDB](https://docs.mindsdb.com/use-cases/data_enrichment/sentiment-analysis-inside-mysql-with-openai#leverage-the-nlp-capabilities-with-mindsdb) * [What’s Next?](https://docs.mindsdb.com/use-cases/data_enrichment/sentiment-analysis-inside-mysql-with-openai#what%E2%80%99s-next) [​](https://docs.mindsdb.com/use-cases/data_enrichment/sentiment-analysis-inside-mysql-with-openai#introduction) Introduction -------------------------------------------------------------------------------------------------------------------------------- In this blog post, we present how to create OpenAI models within MindsDB. This example is a sentiment analysis where we infer emotions behind a text. The input data is taken from our sample MySQL database. [​](https://docs.mindsdb.com/use-cases/data_enrichment/sentiment-analysis-inside-mysql-with-openai#prerequisites) Prerequisites ---------------------------------------------------------------------------------------------------------------------------------- To follow along, install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) . [​](https://docs.mindsdb.com/use-cases/data_enrichment/sentiment-analysis-inside-mysql-with-openai#tutorial) Tutorial ------------------------------------------------------------------------------------------------------------------------ In this tutorial, we create a predictive model to infer emotions behind a text, a task also known as sentiment analysis. We use a table from our MySQL public demo database, so let’s start by connecting MindsDB to it: Copy Ask AI CREATE DATABASE mysql_demo_db WITH ENGINE = 'mysql', PARAMETERS = { "user": "user", "password": "MindsDBUser123!", "host": "samples.mindsdb.com", "port": "3306", "database": "public" }; Now that we’ve connected our database to MindsDB, let’s query the data to be used in the example: Copy Ask AI SELECT * FROM mysql_demo_db.amazon_reviews LIMIT 3; Here is the output: Copy Ask AI +-----------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ | product_name | review | +-----------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ | All-New Fire HD 8 Tablet, 8 HD Display, Wi-Fi, 16 GB - Includes Special Offers, Magenta | Late gift for my grandson. He is very happy with it. Easy for him (9yo ). | | All-New Fire HD 8 Tablet, 8 HD Display, Wi-Fi, 16 GB - Includes Special Offers, Magenta | I'm not super thrilled with the proprietary OS on this unit, but it does work okay and does what I n | | All-New Fire HD 8 Tablet, 8 HD Display, Wi-Fi, 16 GB - Includes Special Offers, Magenta | I purchased this Kindle Fire HD 8 was purchased for use by 5 and 8 yer old grandchildren. They basic | +-----------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ Let’s create a model table to identify sentiment for all reviews: Before creating an OpenAI model, please create an engine, providing your OpenAI API key: Copy Ask AI CREATE ML_ENGINE openai_engine FROM openai USING openai_api_key = 'your-openai-api-key'; Copy Ask AI CREATE MODEL sentiment_classifier_model PREDICT sentiment USING engine = 'openai_engine', prompt_template = 'describe the sentiment of the reviews strictly as "positive", "neutral", or "negative". "I love the product":positive "It is a scam":negative "{{review}}.":'; In practice, the `CREATE MODEL` statement triggers MindsDB to generate an AI table called `sentiment_classifier_model` that uses the OpenAI integration to predict a column named `sentiment`. The model lives inside the default `mindsdb` project. In MindsDB, projects are a natural way to keep artifacts, such as models or views, separate according to what predictive task they solve. You can learn more about MindsDB projects [here](https://docs.mindsdb.com/sql/project) . The `USING` clause specifies the parameters that this handler requires. * The `engine` parameter defines that we use the `openai` engine. * The `prompt_template` parameter conveys the structure of a message that is to be completed with additional text generated by the model. Follow [this instruction](https://docs.mindsdb.com/integrations/ai-engines/openai#setup) to set up the OpenAI integration in MindsDB. Once the `CREATE MODEL` statement has started execution, we can check the status of the creation process with the following query: Copy Ask AI DESCRIBE sentiment_classifier_model; It may take a while to register as complete depending on the internet connection. Once the creation is complete, the behavior is the same as with any other AI table – you can query it either by specifying synthetic data in the actual query: Copy Ask AI SELECT review, sentiment FROM sentiment_classifier_model WHERE review = 'It is ok.'; Here is the output data: Copy Ask AI +-----------+-----------+ | review | sentiment | +-----------+-----------+ | It is ok. | neutral | +-----------+-----------+ Or by joining with another table for batch predictions: Copy Ask AI SELECT input.review, output.sentiment FROM mysql_demo_db.amazon_reviews AS input JOIN sentiment_classifier_model AS output LIMIT 3; Here is the output data: Copy Ask AI +------------------------------------------------------------------------------------------------------+-----------+ | review | sentiment | +------------------------------------------------------------------------------------------------------+-----------+ | Late gift for my grandson. He is very happy with it. Easy for him (9yo ). | positive | | I'm not super thrilled with the proprietary OS on this unit, but it does work okay and does what I n | positive | | I purchased this Kindle Fire HD 8 was purchased for use by 5 and 8 yer old grandchildren. They basic | positive | +------------------------------------------------------------------------------------------------------+-----------+ The `amazon_reviews` table is used to make batch predictions. Upon joining the `sentiment_classifier_model` model with the `amazon_reviews` table, the model uses all values from the `review` column. [​](https://docs.mindsdb.com/use-cases/data_enrichment/sentiment-analysis-inside-mysql-with-openai#leverage-the-nlp-capabilities-with-mindsdb) Leverage the NLP Capabilities with MindsDB -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- By integrating databases and OpenAI using MindsDB, developers can easily extract insights from text data with just a few SQL commands. These powerful natural language processing (NLP) models are capable of answering questions with or without context and completing general prompts. Furthermore, these models are powered by large pre-trained language models from OpenAI, so there is no need for manual development work. Ultimately, this provides developers with an easy way to incorporate powerful NLP capabilities into their applications while saving time and resources compared to traditional ML development pipelines and methods. All in all, MindsDB makes it possible for developers to harness the power of OpenAI efficiently! MindsDB is now the fastest-growing open-source applied machine-learning platform in the world. Its community continues to contribute to more than 70 data-source and ML-framework integrations. Stay tuned for the upcoming features - including more control over the interface parameters and fine-tuning models directly from MindsDB! Experiment with OpenAI models within MindsDB and unlock the ML capability over your data in minutes. Finally, if MindsDB’s vision to democratize ML sounds exciting, head to our [community Slack](https://mindsdb.com/joincommunity) , where you can get help and find people to chat about using other available data sources, ML frameworks, or writing a handler to bring your own! Follow our introduction to MindsDB’s OpenAI integration [here](https://mindsdb.com/blog/extract-insights-from-text-inside-databases-using-openai-gpt3-and-mindsdb-integration) . Also, we’ve got a variety of tutorials that use MySQL and MongoDB: * [Question Answering in MySQL](https://docs.mindsdb.com/nlp/question-answering-inside-mysql-with-openai) * [Text Summarization in MySQL](https://docs.mindsdb.com/nlp/text-summarization-inside-mysql-with-openai) * [Sentiment Analysis in MongoDB](https://docs.mindsdb.com/nlp/sentiment-analysis-inside-mongodb-with-openai) * [Question Answering in MongoDB](https://docs.mindsdb.com/nlp/question-answering-inside-mongodb-with-openai) * [Text Summarization in MongoDB](https://docs.mindsdb.com/nlp/text-summarization-inside-mongodb-with-openai) [​](https://docs.mindsdb.com/use-cases/data_enrichment/sentiment-analysis-inside-mysql-with-openai#what%E2%80%99s-next) What’s Next? --------------------------------------------------------------------------------------------------------------------------------------- Have fun while trying it out yourself! * Bookmark [MindsDB repository on GitHub](https://github.com/mindsdb/mindsdb) . * Engage with the MindsDB community on [Slack](https://mindsdb.com/joincommunity) or [GitHub](https://github.com/mindsdb/mindsdb/discussions) to ask questions and share your ideas and thoughts. If this tutorial was helpful, please give us a GitHub star [here](https://github.com/mindsdb/mindsdb) . Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/data_enrichment/sentiment-analysis-inside-mysql-with-openai.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/data_enrichment/sentiment-analysis-inside-mysql-with-openai) ⌘I --- # Retrain a Model - MindsDB [Skip to main content](https://docs.mindsdb.com/mindsdb_sql/sql/api/retrain#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Retrain a Model [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Description](https://docs.mindsdb.com/mindsdb_sql/sql/api/retrain#description) * [Syntax](https://docs.mindsdb.com/mindsdb_sql/sql/api/retrain#syntax) * [When to RETRAIN the Model?](https://docs.mindsdb.com/mindsdb_sql/sql/api/retrain#when-to-retrain-the-model) * [Example](https://docs.mindsdb.com/mindsdb_sql/sql/api/retrain#example) [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/retrain#description) Description ------------------------------------------------------------------------------------ The `RETRAIN` statement is used to retrain the already trained predictors with the new data. The predictor is updated to leverage the new data in optimizing its predictive capabilities. Retraining takes at least as much time as the training process of the predictor did because now the dataset used to retrain has new or updated data in addition to the _old_ data. [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/retrain#syntax) Syntax -------------------------------------------------------------------------- Here is the syntax: Copy Ask AI RETRAIN [MODEL] project_name.predictor_name [FROM [integration_name | project_name]\ (SELECT column_name, ...\ FROM [integration_name. | project_name.]table_name)\ PREDICT target_name\ USING engine = 'engine_name',\ tag = 'tag_name',\ active = 0/1]; On execution, we get: Copy Ask AI Query OK, 0 rows affected (0.058 sec) Where: | Expressions | Description | | --- | --- | | `project_name` | Name of the project where the model resides. | | `predictor_name` | Name of the model to be retrained. | | `integration_name` | Optional. Name of the integration created using the [`CREATE DATABASE`](https://docs.mindsdb.com/sql/create/database)
statement or [file upload](https://docs.mindsdb.com/sql/create/file)
. | | `(SELECT column_name, ... FROM table_name)` | Optional. Selecting data to be used for training and validation. | | `target_column` | Optional. Column to be predicted. | | `engine_name` | You can optionally provide an ML engine, based on which the model is retrained. | | `tag_name` | You can optionally provide a tag that is visible in the `training_options` column of the `mindsdb.models` table. | | `active` | Optional. Setting it to `0` causes the retrained version to be inactive. And setting it to `1` causes the retrained version to be active. | **Model Versions** Every time the model is retrained, its new version is created with the incremented version number.You can query for all model versions like this: Copy Ask AI SELECT * FROM project_name.models; For more information on managing model versions, check out our [docs here](https://docs.mindsdb.com/sql/api/manage-models-versions) . [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/retrain#when-to-retrain-the-model) When to `RETRAIN` the Model? ------------------------------------------------------------------------------------------------------------------- It is advised to `RETRAIN` the predictor whenever the `update_status` column value from the `mindsdb.models` table is set to `available`. Here is when the `update_status` column value is set to `available`: * When the new version of MindsDB is available that causes the predictor to become obsolete. * When the new data is available in the table that was used to train the predictor. To find out whether you need to retrain your model, query the `mindsdb.models` table and look for the `update_status` column. Here are the possible values of the `update_status` column: | Name | Description | | --- | --- | | `available` | It indicates that the model should be updated. | | `updating` | It indicates that the retraining process of the model takes place. | | `up_to_date` | It indicates that your model is up to date and does not need to be retrained. | Let’s run the query. Copy Ask AI SELECT name, update_status FROM mindsdb.models WHERE name = 'predictor_name'; On execution, we get: Copy Ask AI +------------------+---------------+ | name | update_status | +------------------+---------------+ | predictor_name | up_to_date | +------------------+---------------+ Where: | Name | Description | | --- | --- | | `predictor_name` | Name of the model to be retrained. | | `update_status` | Column informing whether the model needs to be retrained. | Alternatively, use the `DESCRIBE` command as below: Copy Ask AI DESCRIBE MODEL predictor_name; [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/retrain#example) Example ---------------------------------------------------------------------------- Let’s look at an example using the `home_rentals_model` model. First, we check the status of the predictor. Copy Ask AI SELECT name, update_status FROM mindsdb.models WHERE name = 'home_rentals_model'; On execution, we get: Copy Ask AI +--------------------+---------------+ | name | update_status | +--------------------+---------------+ | home_rentals_model | available | +--------------------+---------------+ Alternatively, use the `DESCRIBE` command as below: Copy Ask AI DESCRIBE MODEL home_rentals_model; The `available` value of the `update_status` column informs us that we should retrain the model. Copy Ask AI RETRAIN mindsdb.home_rentals_model; On execution, we get: Copy Ask AI Query OK, 0 rows affected (0.058 sec) Now, let’s check the status again. Copy Ask AI SELECT name, update_status FROM mindsdb.models WHERE name = 'home_rentals_model'; On execution, we get: Copy Ask AI +--------------------+---------------+ | name | update_status | +--------------------+---------------+ | home_rentals_model | updating | +--------------------+---------------+ And after the retraining process is completed: Copy Ask AI SELECT name, update_status FROM mindsdb.models WHERE name = 'home_rentals_model'; On execution, we get: Copy Ask AI +--------------------+---------------+ | name | update_status | +--------------------+---------------+ | home_rentals_model | up_to_date | +--------------------+---------------+ Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/mindsdb_sql/sql/api/retrain.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/mindsdb_sql/sql/api/retrain) ⌘I --- # Usage Examples of Hugging Face Models Through Inference API - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/data_enrichment/hugging-face-inference-api-examples#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Usage Examples of Hugging Face Models Through Inference API [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Spam Classifier](https://docs.mindsdb.com/use-cases/data_enrichment/hugging-face-inference-api-examples#spam-classifier) * [Sentiment Classifier](https://docs.mindsdb.com/use-cases/data_enrichment/hugging-face-inference-api-examples#sentiment-classifier) * [Zero-Shot Classifier](https://docs.mindsdb.com/use-cases/data_enrichment/hugging-face-inference-api-examples#zero-shot-classifier) * [Summarization](https://docs.mindsdb.com/use-cases/data_enrichment/hugging-face-inference-api-examples#summarization) * [Fill Mask](https://docs.mindsdb.com/use-cases/data_enrichment/hugging-face-inference-api-examples#fill-mask) This document presents various use cases of Hugging Face models through Inference API from MindsDB. [​](https://docs.mindsdb.com/use-cases/data_enrichment/hugging-face-inference-api-examples#spam-classifier) Spam Classifier ------------------------------------------------------------------------------------------------------------------------------ Here is an example of a binary classification. The model determines whether a text string is spam or not. Copy Ask AI CREATE MODEL mindsdb.spam_classifier PREDICT PRED USING engine = 'hf_inference_api', task = 'text-classification', column = 'text_spammy'; Before querying for predictions, we should verify the status of the `spam_classifier` model. Copy Ask AI DESCRIBE spam_classifier; On execution, we get: Copy Ask AI +---------------+-------+--------+--------+-------+-------------+---------------+------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |NAME |PROJECT|STATUS |ACCURACY|PREDICT|UPDATE_STATUS|MINDSDB_VERSION|ERROR |SELECT_DATA_QUERY|TRAINING_OPTIONS | +---------------+-------+--------+--------+-------+-------------+---------------+------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |spam_classifier|mindsdb|complete|[NULL] |PRED |up_to_date |22.10.2.1 |[NULL]|[NULL] |{'target': 'PRED', 'using': {'engine': 'huggingface', 'task': 'text-classification', 'model_name': 'mrm8488/bert-tiny-finetuned-sms-spam-detection', 'input_column': 'text_spammy', 'labels': ['ham', 'spam']}}| +---------------+-------+--------+--------+-------+-------------+---------------+------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Once the status is `complete`, we can query for predictions. Copy Ask AI SELECT h.*, t.text_spammy AS input_text FROM example_db.demo_data.hf_test AS t JOIN mindsdb.spam_classifier AS h; On execution, we get: Copy Ask AI +----+---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+ |PRED|PRED_explain |input_text | +----+---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+ |spam|{'spam': 0.9051626920700073, 'ham': 0.09483727067708969} |Free entry in 2 a wkly comp to win FA Cup final tkts 21st May 2005. Text FA to 87121 to receive entry question(std txt rate)T&C's apply 08452810075over18's | |ham |{'ham': 0.9380123615264893, 'spam': 0.061987683176994324}|Nah I don't think he goes to usf, he lives around here though | |spam|{'spam': 0.9064534902572632, 'ham': 0.09354648739099503} |WINNER!! As a valued network customer you have been selected to receive a £900 prize reward! To claim call 09061701461. Claim code KL341. Valid 12 hours only. | +----+---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+ [​](https://docs.mindsdb.com/use-cases/data_enrichment/hugging-face-inference-api-examples#sentiment-classifier) Sentiment Classifier ---------------------------------------------------------------------------------------------------------------------------------------- Here is an example of a multi-value classification. The model determines the sentiment of a text string, where possible values are `negative`, `neutral`, and `positive`. Copy Ask AI CREATE MODEL mindsdb.sentiment_classifier PREDICT sentiment USING engine = 'hf_inference_api', task = 'text-classification', column = 'text_short', labels = ['negative', 'neutral', 'positive']; Before querying for predictions, we should verify the status of the `sentiment_classifier` model. Copy Ask AI DESCRIBE sentiment_classifier; On execution, we get: Copy Ask AI +--------------------+-------+--------+--------+---------+-------------+---------------+------+-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |NAME |PROJECT|STATUS |ACCURACY|PREDICT |UPDATE_STATUS|MINDSDB_VERSION|ERROR |SELECT_DATA_QUERY|TRAINING_OPTIONS | +--------------------+-------+--------+--------+---------+-------------+---------------+------+-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |sentiment_classifier|mindsdb|complete|[NULL] |sentiment|up_to_date |22.10.2.1 |[NULL]|[NULL] |{'target': 'sentiment', 'using': {'engine': 'huggingface', 'task': 'text-classification', 'model_name': 'cardiffnlp/twitter-roberta-base-sentiment', 'input_column': 'text_short', 'labels': ['negative', 'neutral', 'positive']}}| +--------------------+-------+--------+--------+---------+-------------+---------------+------+-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Once the status is `complete`, we can query for predictions. Copy Ask AI SELECT h.*, t.text_short AS input_text FROM example_db.demo_data.hf_test AS t JOIN mindsdb.sentiment_classifier AS h; On execution, we get: Copy Ask AI +---------+----------------------------------------------------------------------------------------------------+-------------------+ |sentiment|sentiment_explain |input_text | +---------+----------------------------------------------------------------------------------------------------+-------------------+ |negative |{'negative': 0.9679920077323914, 'neutral': 0.02736542373895645, 'positive': 0.0046426113694906235} |I hate tacos | |positive |{'positive': 0.7607280015945435, 'neutral': 0.2332666665315628, 'negative': 0.006005281116813421} |I want to dance | |positive |{'positive': 0.9835041761398315, 'neutral': 0.014900505542755127, 'negative': 0.0015953202964738011}|Baking is the best | +---------+----------------------------------------------------------------------------------------------------+-------------------+ [​](https://docs.mindsdb.com/use-cases/data_enrichment/hugging-face-inference-api-examples#zero-shot-classifier) Zero-Shot Classifier ---------------------------------------------------------------------------------------------------------------------------------------- Here is an example of a zero-shot classification. The model determines to which of the defined categories a text string belongs. Copy Ask AI CREATE MODEL mindsdb.zero_shot_tcd PREDICT topic USING engine = 'hf_inference_api', task = 'zero-shot-classification', candidate_labels = ['travel', 'cooking', 'dancing'], column = 'text_short'; Before querying for predictions, we should verify the status of the `zero_shot_tcd` model. Copy Ask AI DESCRIBE zero_shot_tcd; On execution, we get: Copy Ask AI +-------------+-------+--------+--------+--------+-------------+---------------+------+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |NAME |PROJECT|STATUS |ACCURACY|PREDICT |UPDATE_STATUS|MINDSDB_VERSION|ERROR |SELECT_DATA_QUERY|TRAINING_OPTIONS | +-------------+-------+--------+--------+--------+-------------+---------------+------+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |zero_shot_tcd|mindsdb|complete|[NULL] |topic |up_to_date |22.10.2.1 |[NULL]|[NULL] |{'target': 'topic', 'using': {'engine': 'huggingface', 'task': 'zero-shot-classification', 'model_name': 'facebook/bart-large-mnli', 'input_column': 'text_short', 'candidate_labels': ['travel', 'cooking', 'dancing']}}| +-------------+-------+--------+--------+--------+-------------+---------------+------+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Once the status is `complete`, we can query for predictions. Copy Ask AI SELECT h.*, t.text_short AS input_text FROM example_db.demo_data.hf_test AS t JOIN mindsdb.zero_shot_tcd AS h; On execution, we get: Copy Ask AI +-------+--------------------------------------------------------------------------------------------------+-------------------+ |topic |topic_explain |input_text | +-------+--------------------------------------------------------------------------------------------------+-------------------+ |cooking|{'cooking': 0.7530364990234375, 'travel': 0.1607145369052887, 'dancing': 0.08624900877475739} |I hate tacos | |dancing|{'dancing': 0.9746809601783752, 'travel': 0.015539299696683884, 'cooking': 0.009779711253941059} |I want to dance | |cooking|{'cooking': 0.9936348795890808, 'travel': 0.0034196735359728336, 'dancing': 0.0029454431496560574}|Baking is the best | +-------+--------------------------------------------------------------------------------------------------+-------------------+ [​](https://docs.mindsdb.com/use-cases/data_enrichment/hugging-face-inference-api-examples#summarization) Summarization -------------------------------------------------------------------------------------------------------------------------- Here is an example of input text summarization. Copy Ask AI CREATE MODEL mindsdb.summarizer_10_20 PREDICT text_summary USING engine = 'hf_inference_api', task = 'summarization', column = 'text_long', min_output_length = 10, max_output_length = 20; Before querying for predictions, we should verify the status of the `summarizer_10_20` model. Copy Ask AI DESCRIBE summarizer_10_20; On execution, we get: Copy Ask AI +----------------+-------+--------+--------+------------+-------------+---------------+------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |NAME |PROJECT|STATUS |ACCURACY|PREDICT |UPDATE_STATUS|MINDSDB_VERSION|ERROR |SELECT_DATA_QUERY|TRAINING_OPTIONS | +----------------+-------+--------+--------+------------+-------------+---------------+------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |summarizer_10_20|mindsdb|complete|[NULL] |text_summary|up_to_date |22.10.2.1 |[NULL]|[NULL] |{'target': 'text_summary', 'using': {'engine': 'huggingface', 'task': 'summarization', 'model_name': 'sshleifer/distilbart-cnn-12-6', 'input_column': 'text_long', 'min_output_length': 10, 'max_output_length': 20}}| +----------------+-------+--------+--------+------------+-------------+---------------+------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Once the status is `complete`, we can query for predictions. Copy Ask AI SELECT h.*, t.text_long AS input_text FROM example_db.demo_data.hf_test AS t JOIN mindsdb.summarizer_10_20 AS h; On execution, we get: Copy Ask AI +--------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |text_summary |input_text | +--------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |A taco is a traditional Mexican food consisting of a small hand-sized corn- or |A taco is a traditional Mexican food consisting of a small hand-sized corn- or wheat-based tortilla topped with a filling. The tortilla is then folded around the filling and eaten by hand. A taco can be made with a variety of fillings, including beef, pork, chicken, seafood, beans, vegetables, and cheese, allowing for great versatility and variety. | |Dance is a performing art form consisting of sequences of movement, either improvised or purposefully selected|Dance is a performing art form consisting of sequences of movement, either improvised or purposefully selected. This movement has aesthetic and often symbolic value.[nb 1] Dance can be categorized and described by its choreography, by its repertoire of movements, or by its historical period or place of origin. | |Baking is a method of preparing food that uses dry heat, typically in an oven |Baking is a method of preparing food that uses dry heat, typically in an oven, but can also be done in hot ashes, or on hot stones. The most common baked item is bread but many other types of foods can be baked. Heat is gradually transferred from the surface of cakes, cookies, and pieces of bread to their center. As heat travels through, it transforms batters and doughs into baked goods and more with a firm dry crust and a softer center. Baking can be combined with grilling to produce a hybrid barbecue variant by using both methods simultaneously, or one after the other. Baking is related to barbecuing because the concept of the masonry oven is similar to that of a smoke pit.| +--------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ [​](https://docs.mindsdb.com/use-cases/data_enrichment/hugging-face-inference-api-examples#fill-mask) Fill Mask ------------------------------------------------------------------------------------------------------------------ Here is an example of a masked language modeling task. Copy Ask AI CREATE MODEL mindsdb.fill_mask PREDICT text_filled USING engine = 'hf_inference_api', task = 'fill-mask', column = 'text'; Before querying for predictions, we should verify the status of the `fill_mask` model. Copy Ask AI DESCRIBE fill_mask; On execution, we get: Copy Ask AI +----------------+-------+--------+--------+------------+-------------+---------------+------+-----------------+--------------------------------------------------------------------------------------------------------------------+ |NAME |PROJECT|STATUS |ACCURACY|PREDICT |UPDATE_STATUS|MINDSDB_VERSION|ERROR |SELECT_DATA_QUERY|TRAINING_OPTIONS | +----------------+-------+--------+--------+------------+-------------+---------------+------+-----------------+--------------------------------------------------------------------------------------------------------------------+ |fill_mask |mindsdb|complete|[NULL] |text_filled |up_to_date |23.3.5.0 |[NULL]|[NULL] |{'target': 'text_filled', 'using': {'task': 'fill-mask', 'model_name': 'bert-base-uncased', 'input_column': 'text'}}| +----------------+-------+--------+--------+------------+-------------+---------------+------+-----------------+--------------------------------------------------------------------------------------------------------------------+ Once the status is `complete`, we can query for predictions. Copy Ask AI SELECT h.*, t.text AS input_text FROM demo.texts AS t JOIN mindsdb.fill_mask AS h; On execution, we get: Copy Ask AI +-------------------------+---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |text_filled |input_text |text_filled_explain | +-------------------------+---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |the food was great! |The [MASK] was great! |{'the food was great!': 0.16309359669685364, 'the party was great!': 0.06305009871721268, 'the fun was great!': 0.04633583873510361, 'the show was great!': 0.043319422751665115, 'the music was great!': 0.02990395948290825} | |the weather is good today|The weather is [MASK] today|{'the weather is good today': 0.22563229501247406, 'the weather is warm today': 0.07954009622335434, 'the weather is fine today': 0.047255873680114746, 'the weather is better today': 0.034303560853004456, 'the weather is mild today': 0.03092862293124199}| +-------------------------+---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/data_enrichment/hugging-face-inference-api-examples.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/data_enrichment/hugging-face-inference-api-examples) ⌘I --- # Page Not Found [Skip to main content](https://docs.mindsdb.com/integrations/ai-engines/link#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Page Not Found [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) 404 Page Not Found ============== We couldn't find the page. Maybe you were looking for one of these pages below? [Data Integrations](https://docs.mindsdb.com/integrations/data-overview#) [Use a Data Source](https://docs.mindsdb.com/mindsdb_sql/sql/api/use#) [Connect a Data Source](https://docs.mindsdb.com/mindsdb_sql/sql/create/database#) ⌘I --- # AI Workflow Automation - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/ai_workflow_automation/overview#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation AI Workflow Automation [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) With MindsDB, you can create, customize, and automate AI workflows that comprise of connecting a [data source](https://docs.mindsdb.com/integrations/data-overview) , deploying an [AI/ML model](https://docs.mindsdb.com/integrations/ai-overview) , and streaming predictions and forecast into your application. Use [jobs](https://docs.mindsdb.com/mindsdb_sql/sql/create/jobs) and [triggers](https://docs.mindsdb.com/mindsdb_sql/sql/create/trigger) to create custom automation. ![](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/assets/use_cases/ai_workflow_automation.jpg?w=2500&fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=4c004d0dddcd15454d6859ca02af1d4b) This section covers the following use cases: * Chatbot automation with jobs * Alert systems Available tutorials: [Slack Chatbot\ -------------](https://docs.mindsdb.com/use-cases/ai_workflow_automation/slack-chatbot) [Twitter Chatbot\ ---------------](https://docs.mindsdb.com/use-cases/ai_workflow_automation/twitter-chatbot) [Twilio Chatbot\ --------------](https://docs.mindsdb.com/use-cases/ai_workflow_automation/twilio-chatbot) [Customer Reviews Notifications\ ------------------------------](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications) [Real-time Trading Forecasts and Notifications\ ---------------------------------------------](https://docs.mindsdb.com/use-cases/ai_workflow_automation/real-time-trading-forecasts) Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/ai_workflow_automation/overview.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/ai_workflow_automation/overview) ⌘I --- # SDKs - MindsDB [Skip to main content](https://docs.mindsdb.com/sdks/overview#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation SDKs [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) MindsDB provides SDKs for Python, and JavaScript, enabling incorporation of AI building blocks into these development environments. This section introduces custom syntax provided by MindsDB to bring data and AI together inside Python, and JavaScript development environments. Follow these steps to get started: 1 Set up the development environment For Python, [install the package](https://docs.mindsdb.com/sdks/python/installation) . For JavaScript, [install the package](https://docs.mindsdb.com/sdks/javascript/installation) . 2 Connect a data source Connect a data source in [Python](https://docs.mindsdb.com/sdks/python/create_database) and [JavaScript](https://docs.mindsdb.com/sdks/javascript/create_database) . Explore all available [data sources here](https://docs.mindsdb.com/integrations/data-overview) . 3 Configure an AI engine Configure an AI engine in [Python](https://docs.mindsdb.com/sdks/python/create_ml_engine) and [JavaScript](https://docs.mindsdb.com/sdks/javascript/create_ml_engine) . Explore all available [AI engines here](https://docs.mindsdb.com/integrations/ai-overview) . 4 Create and deploy an AI/ML model Create and deploy an AI/ML model in [Python](https://docs.mindsdb.com/sdks/python/create_model) and [JavaScript](https://docs.mindsdb.com/sdks/javascript/create_model) . 5 Query for predictions Query for predictions in [Python](https://docs.mindsdb.com/sdks/python/get-batch-predictions) and [JavaScript](https://docs.mindsdb.com/sdks/javascript/batchQuery) . 6 Automate customized workflows Automate tasks by scheduling docs in [Python](https://docs.mindsdb.com/sdks/python/create_job) and [JavaScript](https://docs.mindsdb.com/sdks/javascript/create_job) . Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/sdks/overview.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/sdks/overview) ⌘I --- # Page Not Found [Skip to main content](https://docs.mindsdb.com/quickstart#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Page Not Found [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) 404 Page Not Found ============== We couldn't find the page. Maybe you were looking for one of these pages below? [Apache Solr](https://docs.mindsdb.com/integrations/data-integrations/apache-solr#usage) [Upload TXT files to MindsDB](https://docs.mindsdb.com/integrations/files/txt#upload-txt-files-to-mindsdb) [Disposable Email Domains and OpenAI](https://docs.mindsdb.com/faqs/disposable-email-doman-and-openai#) ⌘I --- # Fine-Tune the OpenAI Model - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/automated_finetuning/openai#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Fine-Tune the OpenAI Model [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) In this example we are going to **teach an OpenAI model, how to write MindsDB AI SQL queries** All OpenAI models belong to the group of Large Language Models (LLMs). By definition, these are pre-trained on large amounts of data. However, it is possible to fine-tune these models with a task-specific dataset for a defined use case. OpenAI supports fine-tuning of some of its models [listed here](https://platform.openai.com/docs/guides/fine-tuning) . And with MindsDB, you can easily fine-tune an OpenAI model making it more applicable to your specific use case. Let’s create a model to answer questions about MindsDB’s custom SQL syntax. First, create an OpenAI engine, passing your OpenAI API key: Copy Ask AI CREATE ML_ENGINE openai_engine FROM openai USING openai_api_key = 'your-openai-api-key'; Then, create a model using this engine: Copy Ask AI CREATE MODEL openai_davinci PREDICT completion USING engine = 'openai_engine', model_name = 'davinci-002', prompt_template = 'Return a valid SQL string for the following question about MindsDB in-database machine learning: {{prompt}}'; You can check model status with this command: Copy Ask AI DESCRIBE openai_davinci; Once the status is complete, we can query for predictions: Copy Ask AI SELECT prompt, completion FROM openai_davinci as m WHERE prompt = 'What is the SQL syntax to join input data with predictions from a MindsDB machine learning model?' USING max_tokens=400; On execution, we get: Copy Ask AI +---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ | prompt | completion | +---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ | What is the SQL syntax to join input data with predictions from a MindsDB machine learning model? | The SQL syntax is: SELECT * FROM input_data INNER JOIN predictions ON input_data.id = predictions.id | +---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ If you followed one of the MindsDB tutorials before, you’ll see that the syntax provided by the model is not exactly as expected. Now, we’ll fine-tune our model using a table that stores details about MindsDB’s custom SQL syntax. Upload [this data file](https://github.com/mindsdb/mindsdb/blob/main/docs/use-cases/automated_finetuning/data.csv) to MindsDB and use it to finetune the model. This is how you can fine-tune an OpenAI model: Copy Ask AI FINETUNE openai_davinci FROM files (SELECT prompt, completion FROM openai_learninghub_ft); The [`FINETUNE`](https://docs.mindsdb.com/sql/api/finetune) command creates a new version of the `openai_davinci` model. You can query all available versions as below: Copy Ask AI SELECT * FROM models WHERE name = 'openai_davinci'; While the model is being generated and trained, it is not active. The model becomes active only after it completes generating and training. Once the new version status is complete and active, we can query the model again, expecting a more accurate output. Copy Ask AI SELECT prompt, completion FROM openai_davinci as m WHERE prompt = 'What is the SQL syntax to join input data with predictions from a MindsDB machine learning model?' USING max_tokens=400; On execution, we get: Copy Ask AI +---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ | prompt | completion | +---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ | What is the SQL syntax to join input data with predictions from a MindsDB machine learning model? | SELECT * FROM mindsdb.models.my_model JOIN mindsdb.input_data_name; | +---------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------+ If you have dynamic data that gets updated regularly, you can set up an automated fine-tuning as below.Note that the data source must contain an incremental column, such as timestamp or integer, so MindsDB can pick up only the recently added data with the help of the [`LAST` keyword](https://docs.mindsdb.com/mindsdb_sql/sql/create/jobs#last) .Here is how to create and schedule a job to fine-tune the model periodically. Copy Ask AI CREATE JOB automated_finetuning ( FINETUNE openai_davinci FROM mindsdb (SELECT * FROM files.openai_learninghub_ft WHERE timestamp > LAST) ) EVERY 1 day IF ( SELECT * FROM files.openai_learninghub_ft WHERE timestamp > LAST ); Now your model will be fine-tuned with newly added data every day or every time there is new data available. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/automated_finetuning/openai.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/automated_finetuning/openai) ⌘I --- # Automated Fine-Tuning - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/automated_finetuning/overview#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Automated Fine-Tuning [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) Real-world use cases often deal with dynamic data that is updated regularly. MindsDB enables you to automate [fine-tuning](https://docs.mindsdb.com/mindsdb_sql/sql/api/finetune) of AI models to keep them up-to-date and as accurate as possible. You can set up [jobs](https://docs.mindsdb.com/mindsdb_sql/sql/create/jobs) that will trigger fine-tuning of AI models every time new data arrives. ![](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/assets/use_cases/automated_finetuning.jpg?w=2500&fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=2df6a1fa705be08cecf368813af33c38) This section covers the following use cases: * Fine-tuning of Large Language models * Fine-tuning of AutoML models Available tutorials: [Fine-tuning of OpenAI models\ ----------------------------](https://docs.mindsdb.com/use-cases/automated_finetuning/openai) [Fine-tuning of classification models\ ------------------------------------](https://docs.mindsdb.com/use-cases/automated_finetuning/classification) [Fine-tuning of regression models\ --------------------------------](https://docs.mindsdb.com/use-cases/automated_finetuning/regression) Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/automated_finetuning/overview.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/automated_finetuning/overview) ⌘I --- # Create, Train, and Deploy a Model - MindsDB [Skip to main content](https://docs.mindsdb.com/sdks/python/create_model#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Create, Train, and Deploy a Model [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Description](https://docs.mindsdb.com/sdks/python/create_model#description) * [Syntax](https://docs.mindsdb.com/sdks/python/create_model#syntax) [​](https://docs.mindsdb.com/sdks/python/create_model#description) Description --------------------------------------------------------------------------------- The `models.get()` and `models.create()` methods enable you to get an existing model or create and deploy a new model. [​](https://docs.mindsdb.com/sdks/python/create_model#syntax) Syntax ----------------------------------------------------------------------- Use the `models.get()` method to get an existing model: Copy Ask AI my_model = project.models.get('my_model') Or, the `create()` method to create and train a new model: Copy Ask AI my_model = project.models.create ( name = 'my_model', predict = 'target', query = my_table ) Please note that in the case of LLM models, the parameters can be stored in `options`. Here is the syntax to create an OpenAI model: Copy Ask AI sentiment_classifier = project.models.create ( name='sentiment_classifier', engine='openai', # alternatively: engine=server.ml_engines.openai predict='sentiment', options={ 'prompt_template':'answer this question: {{questions}}', 'model_name':'gpt4' } ) Alternatively, you can skip `options` and define parameters as arguments. Copy Ask AI sentiment_classifier = project.models.create ( name='sentiment_classifier', engine='openai', # alternatively: engine=server.ml_engines.openai predict='sentiment', prompt_template='answer this question: {{questions}}', model_name='gpt4' ) And in the case of time-series model, the additional options are stored in `timeseries_options`. Here is the syntax to create a time-series model: Copy Ask AI ts_model = project.models.create ( name='time_series_model', predict='target', query=my_table, timeseries_options={ 'order': 'order_date', 'group': 'category', 'window': 30, 'horizon': 4 } ) Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/sdks/python/create_model.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/sdks/python/create_model) ⌘I --- # Create, Train, and Deploy a Model - MindsDB [Skip to main content](https://docs.mindsdb.com/sdks/javascript/create_model#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Create, Train, and Deploy a Model [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Regression Model](https://docs.mindsdb.com/sdks/javascript/create_model#regression-model) * [Time Series Model](https://docs.mindsdb.com/sdks/javascript/create_model#time-series-model) * [OpenAI Model](https://docs.mindsdb.com/sdks/javascript/create_model#openai-model) Training a model requires various parameters, depending on the model type. Here we present examples of regression, time series, and OpenAI models. Here are some useful links: * [training options](https://mindsdb.github.io/mindsdb-js-sdk/interfaces/models_trainingOptions.TrainingOptions.html) , * [query options](https://mindsdb.github.io/mindsdb-js-sdk/interfaces/models_queryOptions.QueryOptions.html) , * [batch query options](https://mindsdb.github.io/mindsdb-js-sdk/interfaces/models_queryOptions.BatchQueryOptions.html) . #### [​](https://docs.mindsdb.com/sdks/javascript/create_model#regression-model) Regression Model Let’s look at an example of how to create and train a simple regression model, and then, use it for making predictions. Copy Ask AI // Defining training options const regressionTrainingOptions = { select: 'SELECT * FROM demo_data.home_rentals', integration: 'example_db' }; try { // Creating and training a model // The returned promise resolves when the model is created, NOT when training is actually complete let homeRentalPriceModel = await MindsDB.Models.trainModel( 'home_rentals_model', 'rental_price', 'mindsdb', regressionTrainingOptions); console.log('created a model'); // Waiting for the training to be complete while (homeRentalPriceModel.status !== 'complete' && homeRentalPriceModel.status !== 'error') { homeRentalPriceModel = await MindsDB.Models.getModel('home_rentals_model', 'mindsdb'); } // Checking model's status console.log('Model status: ' + homeRentalPriceModel.status); // Defining query options const queryOptions = { where: [\ 'sqft = 823',\ 'location = "good"',\ 'neighborhood = "downtown"',\ 'days_on_market = 10'\ ] } // Querying for a single prediction const rentalPricePrediction = await homeRentalPriceModel.query(queryOptions); console.log('Predicted value:'); console.log(rentalPricePrediction.value); console.log('Prediction insights:'); console.log(rentalPricePrediction.explain); console.log('Input data:'); console.log(rentalPricePrediction.data); } catch (error) { // Something went wrong training or querying console.log(error); } #### [​](https://docs.mindsdb.com/sdks/javascript/create_model#time-series-model) Time Series Model As time series models require more parameters, let’s go over an example of how to create and train a time series model, and then, use it for making batch predictions. Copy Ask AI // Defining training options const timeSeriesTrainingOptions = { integration: 'example_db', select: 'SELECT * FROM demo_data.house_sales', orderBy: 'saledate', groupBy: 'bedrooms', window: 8, horizon: 4 } try { // Creating and training a model let houseSalesForecastModel = await MindsDB.Models.trainModel( 'house_sales_model', 'ma', 'mindsdb', timeSeriesTrainingOptions); console.log('created a model'); // Waiting for the training to be complete while (houseSalesForecastModel.status !== 'complete' && houseSalesForecastModel.status !== 'error') { houseSalesForecastModel = await MindsDB.Models.getModel('house_sales_model', 'mindsdb'); } // Checking model's status console.log('Model status: ' + houseSalesForecastModel.status); // Describing a model const modelDescription = await houseSalesForecastModel.describe(); console.log('Model description:'); console.log(modelDescription); // Defining query options const queryOptions = { // Join model to this data source join: 'example_db.demo_data.house_sales', // When using batch queries, the 't' alias is used for the joined data source ('t' is short for training/test) // The 'm' alias is used for the trained model to be queried where: ['t.saledate > LATEST', 't.bedrooms = 2'], limit: 4 } // Querying for batch predictions const rentalPriceForecasts = await houseSalesForecastModel.batchQuery(queryOptions); console.log('Batch predictions:'); rentalPriceForecasts.forEach(f => { console.log(f.value); console.log(f.explain); console.log(f.data); }) } catch (error) { // Something went wrong training or predicting. console.log(error); } #### [​](https://docs.mindsdb.com/sdks/javascript/create_model#openai-model) OpenAI Model Here is how to create and deploy an OpenAI model from JavaScript code: Copy Ask AI // Defining training options const trainingOptions = { using: {engine: 'openai', prompt_template: 'describe the sentiment of the reviews strictly as "positive", "neutral", or "negative". "I love the product":positive "It is a scam":negative "{{review}}.":'} }; try { // Creating and training a model let openai_js = await MindsDB.Models.trainModel( 'openai_js', 'sentiment', 'mindsdb', trainingOptions); console.log('created a model'); // Waiting for the training to be complete while (openai_js.status !== 'complete' && openai_js.status !== 'error') { openai_js = await MindsDB.Models.getModel('openai_js', 'mindsdb'); } // Checking model's status console.log('Model status: ' + openai_js.status); // Defining query options const queryOptions = { where: [\ 'review = \'It is ok.\''\ ] } // Querying for a single prediction openai_js = await openai_js.query(queryOptions); console.log('Predicted value:'); console.log(openai_js.value); console.log('Prediction insights:'); console.log(openai_js.explain); console.log('Input data:'); console.log(openai_js.data); } catch (error) { // Something went wrong training or querying console.log(error); } Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/sdks/javascript/create_model.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/sdks/javascript/create_model) ⌘I --- # Create a Job - MindsDB [Skip to main content](https://docs.mindsdb.com/sdks/javascript/create_job#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Create a Job [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) This feature is in progress. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/sdks/javascript/create_job.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/sdks/javascript/create_job) ⌘I --- # Configure an ML Engine - MindsDB [Skip to main content](https://docs.mindsdb.com/sdks/python/create_ml_engine#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Configure an ML Engine [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) Here is how you can create an ML engine directly from Python code: Copy Ask AI server.ml_engines.create( 'ml_engine_name', 'ml_engine_handler', connection_data={'_api_key': '111'} ) Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/sdks/python/create_ml_engine.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/sdks/python/create_ml_engine) ⌘I --- # Fine-Tune the Classification Model - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/automated_finetuning/classification#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Fine-Tune the Classification Model [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) In this example, we again use our sample PostgreSQL database. First, we create and train the model using a subset of the `customer_churn` data, considering only female customers. Copy Ask AI CREATE MODEL mindsdb.adjust_customer_churn_model FROM example_db (SELECT * FROM demo_data.customer_churn WHERE gender = 'Female') PREDICT churn; On execution, we get: Copy Ask AI Query successfully completed We can check its status using this command: Copy Ask AI DESCRIBE MODEL adjust_customer_churn_model; Once the status is complete, we can query for predictions. Copy Ask AI SELECT churn, churn_explain FROM mindsdb.adjust_customer_churn_model WHERE seniorcitizen = 0 AND partner = 'Yes' AND dependents = 'No' AND tenure = 1 AND phoneservice = 'No' AND multiplelines = 'No phone service' AND internetservice = 'DSL'; On execution, we get: Copy Ask AI +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------+ | churn | churn_explain | +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------+ | No | {"predicted_value": "No", "confidence": 0.9887640449438202, "anomaly": null, "truth": null, "probability_class_No": 0.934, "probability_class_Yes": 0.066} | +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------+ Let’s adjust this model with more training data. Now we also consider male customers. Copy Ask AI FINETUNE mindsdb.adjust_customer_churn_model FROM example_db (SELECT * FROM demo_data.customer_churn WHERE gender = 'Male'); While the model is being generated and trained, it is not active. The model becomes active only after it completes generating and training. To check the status and versions of the model, run this command: Copy Ask AI SELECT name, engine, project, active, version, status FROM mindsdb.models WHERE name = 'adjust_customer_churn_model'; On execution, we get: Copy Ask AI +-----------------------------+-----------+---------+--------+---------+----------+ | name | engine | project | active | version | status | +-----------------------------+-----------+---------+--------+---------+----------+ | adjust_customer_churn_model | lightwood | mindsdb | false | 1 | complete | | adjust_customer_churn_model | lightwood | mindsdb | true | 2 | complete | +-----------------------------+-----------+---------+--------+---------+----------+ Alternatively, use the `DESCRIBE` command as below: Copy Ask AI DESCRIBE MODEL adjust_customer_churn_model; Let’s query for a prediction again. Copy Ask AI SELECT churn, churn_explain FROM mindsdb.adjust_customer_churn_model WHERE seniorcitizen = 0 AND partner = 'Yes' AND dependents = 'No' AND tenure = 1 AND phoneservice = 'No' AND multiplelines = 'No phone service' AND internetservice = 'DSL'; On execution, we get: Copy Ask AI +--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+ | churn | churn_explain | +--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+ | No | {"predicted_value": "No", "confidence": 0.9887640449438202, "anomaly": null, "truth": null, "probability_class_No": 0.9294, "probability_class_Yes": 0.0706} | +--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+ Here after adjusting the model, there are no significant changes to the predictions. However, the probability class for `Yes` and `No` values has been updated. The probability of a `Yes` value has increased slightly, while the probability of a `No` value has decreased. If you have dynamic data that gets updated regularly, you can set up an automated fine-tuning as below.Note that the data source must contain an incremental column, such as timestamp or integer, so MindsDB can pick up only the recently added data with the help of the [`LAST` keyword](https://docs.mindsdb.com/mindsdb_sql/sql/create/jobs#last) .Here is how to create and schedule a job to fine-tune the model periodically. Copy Ask AI CREATE JOB automated_finetuning ( FINETUNE adjust_customer_churn_model FROM mindsdb (SELECT * FROM example_db.customer_churn WHERE timestamp > LAST) ) EVERY 1 day IF ( SELECT * FROM example_db.customer_churn WHERE timestamp > LAST ); Now your model will be fine-tuned with newly added data every day or every time there is new data available. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/automated_finetuning/classification.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/automated_finetuning/classification) ⌘I --- # Automate Real-Time Trading Data Forecasts - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/ai_workflow_automation/real-time-trading-forecasts#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Automate Real-Time Trading Data Forecasts [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Connect a data source](https://docs.mindsdb.com/use-cases/ai_workflow_automation/real-time-trading-forecasts#connect-a-data-source) * [Deploy a time-series model](https://docs.mindsdb.com/use-cases/ai_workflow_automation/real-time-trading-forecasts#deploy-a-time-series-model) * [Make forecasts](https://docs.mindsdb.com/use-cases/ai_workflow_automation/real-time-trading-forecasts#make-forecasts) * [Connect Slack](https://docs.mindsdb.com/use-cases/ai_workflow_automation/real-time-trading-forecasts#connect-slack) * [Automate real-time forecasts](https://docs.mindsdb.com/use-cases/ai_workflow_automation/real-time-trading-forecasts#automate-real-time-forecasts) MindsDB enables you to automate AI workflows between any source of data and any AI/ML Model. The core building block of this automation is a job that allows anything in MindsDB to be run either on a timer (e.g. every day) or based on a trigger (e.g. when a new row is added to the database). In this tutorial we will use a job to automate real-time forecasts for the BTC/USDT crypto price as Slack notifications. [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/real-time-trading-forecasts#connect-a-data-source) Connect a data source ----------------------------------------------------------------------------------------------------------------------------------------- MindsDB can connect to any source of data - a database, warehouse, stream or app. Here, we’ll connect to Binance API to get a feed of real-time price information. Copy Ask AI CREATE DATABASE my_binance WITH ENGINE = 'binance'; We now have access to the Binance API, which updates data every minute so the interval between data rows in one minute. Let’s take a look at the data for the crypto pair we’ll ultimately use. Copy Ask AI SELECT * FROM my_binance.aggregated_trade_data WHERE symbol = 'BTCUSDT' LIMIT 10; [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/real-time-trading-forecasts#deploy-a-time-series-model) Deploy a time-series model --------------------------------------------------------------------------------------------------------------------------------------------------- The Binance trade data is updated every minute. As a trader, you might want to predict the open prices for the next 10 minutes - so let’s set it up. We’ll use a forecasting engine called Lightwood for ease and speed but you’re also able to train your own model if you like. Copy Ask AI CREATE MODEL cryptocurrency_forecast_model FROM my_binance ( SELECT * FROM aggregated_trade_data WHERE symbol = 'BTCUSDT' ) PREDICT open_price ORDER BY open_time WINDOW 100 HORIZON 10; Here’s what’s going on in the `CREATE MODEL` statement: * `CREATE MODEL`: It is used to create, train, and deploy an ML model. By default, MindsDB’s AutoML will automatically choose the best model for your data but this can be overridden (docs). * `FROM`: Here, we specify which of our integrations to use. Anything that is between the parentheses is the data that will be used to train the model - here, the latest Binance data from the connection we’ve already made to Binance is used. * `PREDICT`: It specifies the target column - here, the open price of the BTC/USDT trading pair is to be forecasted. The following elements are unique to forecasting models in MindsDB: * As it is a forecasting model, you should use ORDER BY to order the data by a date column - here, it is the open time when the open price takes effect. * The `WINDOW` clause defines the window the model looks back at while making forecasts - here, the model looks back at sets of 100 rows (intervals of 100 minutes). * The `HORIZON` clause defines how many rows into the future the model will forecast - here, it forecasts the next 10 rows (the next 10 minutes). After executing the `CREATE MODEL` statement as above, you can check the progress status using this query: Copy Ask AI DESCRIBE cryptocurrency_forecast_model; The time it takes to train the model depends on the amount of training data. In this case, it takes about 2 minutes on MindsDB Cloud. Once the status reads complete, we’re ready to make some forecasts! [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/real-time-trading-forecasts#make-forecasts) Make forecasts --------------------------------------------------------------------------------------------------------------------------- First, we’ll save the Binance data into a view, which will be the input data for making forecasts. Copy Ask AI CREATE VIEW btcusdt_recent AS ( SELECT * FROM my_binance.aggregated_trade_data WHERE symbol = 'BTCUSDT' ); Next, we query for forecasts by joining the model with the Binance input data table. Copy Ask AI SELECT to_timestamp(cast(m.open_time as bigint)) AS open_time, m.open_price, m.open_price_explain FROM btcusdt_recent AS d JOIN cryptocurrency_forecast_model AS m WHERE d.open_time > LATEST; Please note that the Binance data is updated every minute, so every time you query the model, you will get forecasts for the following 10 minutes (as defined by the `HORIZON` clause). The next thing we can do is automate price alerts. Here we’ll choose Slack as our preferred place to receive the alerts but this could be any other system that MindsDB integrates with. [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/real-time-trading-forecasts#connect-slack) Connect Slack ------------------------------------------------------------------------------------------------------------------------- Follow these instructions to set up your Slack app and generate a Slack bot token. Once you get the Slack bot token and integrate your Slack app into one of the Slack channels, you can connect it to MindsDB. Copy Ask AI CREATE DATABASE btcusdt_slack_app WITH ENGINE = 'slack', PARAMETERS = { "token": "xoxb-..." }; Here is how to send messages to a Slack channel: Copy Ask AI INSERT INTO btcusdt_slack_app.messages (channel_id, text) VALUES("slack-channel-id", "BTCUSDT forecasts coming soon."); So, let’s put it all together again. [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/real-time-trading-forecasts#automate-real-time-forecasts) Automate real-time forecasts ------------------------------------------------------------------------------------------------------------------------------------------------------- By now you have connected Binance to MindsDB, deployed and trained a time-series model, and set up the Slack connection. Let’s create a job that will retrain your model periodically using the latest Binance data (which allows us to keep improving the accuracy and performance of the model) and send real-time forecasts of the BTC/USDT trading pair for the next 10 minutes as Slack notifications. Copy Ask AI CREATE JOB btcusdt_forecasts_to_slack ( -- step 1: retrain the model with new data to improve its accuracy -- RETRAIN cryptocurrency_forecast_model FROM my_binance ( SELECT * FROM aggregated_trade_data WHERE symbol = 'BTCUSDT' ) USING join_learn_process = true; -- step 2: make fresh forecasts for the following 10 minutes and insert it into slack -- INSERT INTO btcusdt_slack_app.messages (channel_id, text) VALUES("slack-channel-id", "Here are the BTCUSDT forecasts for the next 10 minutes:"); INSERT INTO btcusdt_slack_app.messages (channel_id, text) SELECT "slack-channel-id" AS channel_id, concat('timestamp: ', cast(to_timestamp(cast(m.open_time as bigint)) as string), ' -> open price: ', m.open_price) AS text FROM btcusdt_recent AS d JOIN cryptocurrency_forecast_model AS m WHERE d.open_time > LATEST; ) EVERY 5 minutes -- Make sure to highlight the whole query to be able to execute it -- ; So there you have it - you’ve successfully built a fully automated end-to-end alert system for crypto prices. Happy trading! Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/ai_workflow_automation/real-time-trading-forecasts.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/ai_workflow_automation/real-time-trading-forecasts) ⌘I --- # Fine-Tune the Regression Model - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/automated_finetuning/regression#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Fine-Tune the Regression Model [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) In this example, we use our sample PostgreSQL database. You can connect to it like this: Copy Ask AI CREATE DATABASE example_db WITH ENGINE = "postgres", PARAMETERS = { "user": "demo_user", "password": "demo_password", "host": "samples.mindsdb.com", "port": "5432", "database": "demo" }; First, we create and train the model using a subset of the `home_rentals` data, considering properties that have been on the market less than 10 days. Copy Ask AI CREATE MODEL mindsdb.adjust_home_rentals_model FROM example_db (SELECT * FROM demo_data.home_rentals WHERE days_on_market < 10) PREDICT rental_price; On execution, we get: Copy Ask AI Query successfully completed We can check its status using this command: Copy Ask AI DESCRIBE MODEL adjust_home_rentals_model; Once the status is complete, we can query for predictions. Copy Ask AI SELECT rental_price, rental_price_explain FROM mindsdb.adjust_home_rentals_model WHERE sqft = 1000 AND location = 'great' AND neighborhood = 'berkeley_hills' AND number_of_rooms = 2 AND number_of_bathrooms = 1 AND days_on_market = 40; On execution, we get: Copy Ask AI +---------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | rental_price | rental_price_explain | +---------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | 2621 | {"predicted_value": 2621, "confidence": 0.99, "anomaly": null, "truth": null, "confidence_lower_bound": 2523, "confidence_upper_bound": 2719} | +---------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ Let’s adjust this model with more training data. Now we consider properties that have been on the market for 10 or more days. Copy Ask AI FINETUNE mindsdb.adjust_home_rentals_model FROM example_db (SELECT * FROM demo_data.home_rentals WHERE days_on_market >= 10); While the model is being generated and trained, it is not active. The model becomes active only after it completes generating and training. To check the status and versions of the model, run this command: Copy Ask AI SELECT name, engine, project, active, version, status FROM mindsdb.models WHERE name = 'adjust_home_rentals_model'; On execution, we get: Copy Ask AI +---------------------------+-----------+---------+--------+---------+----------+ | name | engine | project | active | version | status | +---------------------------+-----------+---------+--------+---------+----------+ | adjust_home_rentals_model | lightwood | mindsdb | false | 1 | complete | | adjust_home_rentals_model | lightwood | mindsdb | true | 2 | complete | +---------------------------+-----------+---------+--------+---------+----------+ Please note that the longer the property is on the market, the lower its rental price. Hence, we can expect the `rental_price` prediction to be lower. Copy Ask AI SELECT rental_price, rental_price_explain FROM mindsdb.adjust_home_rentals_model WHERE sqft = 1000 AND location = 'great' AND neighborhood = 'berkeley_hills' AND number_of_rooms = 2 AND number_of_bathrooms = 1 AND days_on_market = 40; On execution, we get: Copy Ask AI +---------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | rental_price | rental_price_explain | +---------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | 2055 | {"predicted_value": 2055, "confidence": 0.99, "anomaly": null, "truth": null, "confidence_lower_bound": 1957, "confidence_upper_bound": 2153} | +---------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ If you have dynamic data that gets updated regularly, you can set up an automated fine-tuning as below.Note that the data source must contain an incremental column, such as timestamp or integer, so MindsDB can pick up only the recently added data with the help of the [`LAST` keyword](https://docs.mindsdb.com/mindsdb_sql/sql/create/jobs#last) .Here is how to create and schedule a job to fine-tune the model periodically. Copy Ask AI CREATE JOB automated_finetuning ( FINETUNE adjust_home_rentals_model FROM mindsdb (SELECT * FROM example_db.home_rentals WHERE timestamp > LAST) ) EVERY 1 day IF ( SELECT * FROM example_db.home_rentals WHERE timestamp > LAST ); Now your model will be fine-tuned with newly added data every day or every time there is new data available. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/automated_finetuning/regression.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/automated_finetuning/regression) ⌘I --- # Get Batch Predictions - MindsDB [Skip to main content](https://docs.mindsdb.com/sdks/python/get-batch-predictions#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Get Batch Predictions [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Description](https://docs.mindsdb.com/sdks/python/get-batch-predictions#description) * [Syntax](https://docs.mindsdb.com/sdks/python/get-batch-predictions#syntax) [​](https://docs.mindsdb.com/sdks/python/get-batch-predictions#description) Description ------------------------------------------------------------------------------------------ The `predict()` function fetches predictions from the model table. [​](https://docs.mindsdb.com/sdks/python/get-batch-predictions#syntax) Syntax -------------------------------------------------------------------------------- Use the `predict()` method to make batch predictions by passing the data table as its argument: Copy Ask AI my_model.predict(my_table.limit(10)) When querying for predictions, you can specify the `partition_size` parameter to split data into partitions and run prediction on different workers. Note that the [ML task queue](https://docs.mindsdb.com/setup/custom-config#overview-of-config-parameters) needs to be enabled to use this parameter.To use the `partition_size` parameter, provide the below argument to the `predict` function, specifying the partition size, like this: Copy Ask AI my_model.predict(df, params={'partition_size': 2}) Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/sdks/python/get-batch-predictions.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/sdks/python/get-batch-predictions) ⌘I --- # Build a Twilio Chatbot with MindsDB and OpenAI - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/ai_workflow_automation/twilio-chatbot#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Build a Twilio Chatbot with MindsDB and OpenAI [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Step 1. Create OpenAI models with a bit of personality](https://docs.mindsdb.com/use-cases/ai_workflow_automation/twilio-chatbot#step-1-create-openai-models-with-a-bit-of-personality) * [Step 2. Set up your Twilio account and connect it to MindsDB](https://docs.mindsdb.com/use-cases/ai_workflow_automation/twilio-chatbot#step-2-set-up-your-twilio-account-and-connect-it-to-mindsdb) * [Step 3. Automate the Twilio bot with MindsDB](https://docs.mindsdb.com/use-cases/ai_workflow_automation/twilio-chatbot#step-3-automate-the-twilio-bot-with-mindsdb) In this tutorial, we’ll use MindsDB’s integration with Twilio and the custom Jobs feature to implement a chatbot that will reply to text messages. The replies will include a text response generated by OpenAI’s GPT-4 model and an image response generated by the OpenAI’s DallE 3 model. ![](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/assets/twilio-chatbot-diagram.png?w=2500&fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=8dd5daa66dd26acedff66c605f9540bc) Read along to follow the tutorial. [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/twilio-chatbot#step-1-create-openai-models-with-a-bit-of-personality) Step 1. Create OpenAI models with a bit of personality --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- In order to create an AI model, you’ll need an [OpenAI account](https://openai.com/) and an [API key](https://platform.openai.com/account/api-keys) . You’ll also need a MindsDB installation - you can find an open-source version [here](https://github.com/mindsdb/mindsdb) . Then go to your MindsDB SQL Editor and enter the following commands to create AI models: **1\. Model to generate a text response:** Before creating an OpenAI model, please create an engine, providing your OpenAI API key: Copy Ask AI CREATE ML_ENGINE openai_engine FROM openai USING openai_api_key = 'sk-xxx'; Now you can create a model: Copy Ask AI CREATE MODEL twilio_bot_model PREDICT answer USING engine = 'openai_engine', max_tokens = 500, prompt_template = 'Pretend you are a mashup of Bill Murray and Taylor Swift. Provide a short description of an image using the style of Bill Murray and Taylor Swift that answers users questions: {{body}}'; The `CREATE MODEL` command creates and deploys the model within MindsDB. Here we use the OpenAI GPT-3.5 Turbo model to generate text responses to users’ questions. The `prompt_template` message sets the personality of the bot - here, it is a mashup of Bill Murray and Taylor Swift. Please note that the `prompt_template` message contains the `{{body}}` variable, which will be replaced by the body of the received message upon joining the model with the table that stores messages. Let’s test it: Copy Ask AI SELECT body, answer FROM twilio_bot_model WHERE body = 'hey, can you draw a cat in the moon?'; Here is a sample reply: ![](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/assets/twilio-text-model-response.png?w=2500&fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=3a1f3a73cc2b324f198f3c5148e7089e) **2\. Model to generate an image response:** We’ll use the OpenAI DallE 3 model to generate images as part of the responses. Copy Ask AI CREATE MODEL twilio_bot_image_model PREDICT img_url USING engine = 'openai_engine', mode = 'image', model_name = 'dall-e-3', prompt_template = 'Make a photorealistic image. Here is the description: {{answer}}, 4k, digital painting'; The `CREATE MODEL` command creates and deploys the model within MindsDB. Here we use the OpenAI DallE 3 model to generate images based on the Billor Swift’s text response. The `prompt_template` message contains the `{{answer}}` variable. This variable is replaced by the prediction of the previous model upon chaining the two models. Let’s test it: Copy Ask AI SELECT textresponse.body, textresponse.answer, imageresponse.img_url FROM (SELECT body, answer FROM twilio_bot_model WHERE body = 'hey, can you draw a cat in the moon?') AS textresponse JOIN twilio_bot_image_model AS imageresponse; Here is a sample reply: ![](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/assets/twilio-image-model-response.png?w=2500&fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=93003d0c5cafd9dabb2b97db0576701d) The DallE 3 model provides a link to the generated image. ![](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/assets/twilio-image-model-image.png?w=2500&fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=cd28312cda34e47a4c86ca8eabd5c4e9) [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/twilio-chatbot#step-2-set-up-your-twilio-account-and-connect-it-to-mindsdb) Step 2. Set up your Twilio account and connect it to MindsDB --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- You can set up a Twilio account [here](https://twilio.com/try-twilio) , and then you get a virtual phone number in the console. This virtual number will be the one that sends a text to your personal number. Save the account string identifier (SID), auth token, and virtual phone number. Use this command to connect the Twilio account to MindsDB: Copy Ask AI CREATE DATABASE twilio WITH ENGINE = 'twilio', PARAMETERS = { "account_sid":"todo", "auth_token":"todo" }; Check out [this usage guide](https://github.com/mindsdb/mindsdb/tree/main/mindsdb/integrations/handlers/twilio_handler#example-usage) to learn how to query and insert Twilio messages from MindsDB. [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/twilio-chatbot#step-3-automate-the-twilio-bot-with-mindsdb) Step 3. Automate the Twilio bot with MindsDB ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- We use the custom Jobs feature to schedule query execution. Copy Ask AI CREATE JOB twilio_bot_images_job ( INSERT INTO twilio.messages (to_number, from_number, body, media_url) SELECT outputtext.to_number AS to_number, outputtext.from_number AS from_number, outputtext.answer AS body, outputimage.img_url AS media_url FROM ( SELECT input.from_number AS to_number, input.to_number AS from_number, output.answer AS answer FROM twilio.messages AS input JOIN twilio_bot_model AS output WHERE input.sent_at > LAST AND input.msg_status = 'received' ) AS outputtext JOIN twilio_bot_image_model AS outputimage ) EVERY 2 minutes; You can create a job using the `CREATE JOB` statement. Within parenthesis, provide all statements to be executed by the job. Finally, schedule a job - here it’ll run once every two minutes. This job inserts replies to Twilio messages into the `messages` table. We provide the `SELECT` statement as an argument to the `INSERT` statement. Note that the inner `SELECT` statement uses one model to generate a text response (aliased as `outputtext`). Then, the output is joined with another model that generates an image (aliased as `outputimage`) based on the text response generated by the first model. You can monitor this job with the following commands: Copy Ask AI SHOW JOBS WHERE name='twilio_bot_images_job'; SELECT * FROM jobs WHERE name='twilio_bot_images_job'; SELECT * FROM log.jobs_history WHERE project = 'mindsdb' AND name='twilio_bot_images_job'; Here is a sample reply: ![](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/assets/twilio-chatbot-response.png?w=2500&fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=9ee80107d94f4e1d0464d5816d62676d) Follow [this tutorial](https://mindsdb.com/blog/build-your-own-midjourney-in-sql) to create a Twitter chatbot. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/ai_workflow_automation/twilio-chatbot.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/ai_workflow_automation/twilio-chatbot) ⌘I --- # Automate notifications about incoming customer reviews - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Automate notifications about incoming customer reviews [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Data setup](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications#data-setup) * [Model 1 setup](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications#model-1-setup) * [Predictions from Model 1](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications#predictions-from-model-1) * [Automation](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications#automation) * [Model 2 setup](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications#model-2-setup) * [Predictions from Model 2](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications#predictions-from-model-2) * [Automation and Chaining Models 1 & 2](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications#automation-and-chaining-models-1-%26-2) This tutorial presents how to chain OpenAI models within MindsDB to analyze text sentiment and generate responses, which will be sent in the form of Slack notifications. [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications#data-setup) Data setup ---------------------------------------------------------------------------------------------------------------------- Connect your database to MindsDB. Copy Ask AI CREATE DATABASE local_postgres WITH ENGINE = 'postgres', PARAMETERS = { "host": "4.tcp.eu.ngrok.io", "port": 12888, "database": "postgres", "user": "postgres", "password": "password" }; Query the input data table. Copy Ask AI SELECT * FROM local_postgres.demo.amazon_reviews; Copy Ask AI +----------------------------+-----------------------------+------------------------+ | created_at | product_name | review | +----------------------------+-----------------------------+------------------------+ | 2023-11-08 17:23:21.028485 | Power Adapter | It is a great product. | | 2023-11-08 17:23:21.028485 | Bluetooth and Wi-Fi Speaker | It is ok. | | 2023-11-08 17:23:21.028485 | Kindle eReader | It doesn’t work. | +----------------------------+-----------------------------+------------------------+ [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications#model-1-setup) Model 1 setup ---------------------------------------------------------------------------------------------------------------------------- Configure an AI engine, providing the OpenAI API key. Copy Ask AI CREATE ML_ENGINE openai_engine FROM openai USING openai_api_key = 'sk-xxx'; Deploy a model using this AI engine. Copy Ask AI CREATE MODEL sentiment_classifier PREDICT sentiment USING engine = 'openai_engine', model_name = 'gpt-4', prompt_template = 'describe the sentiment of the reviews strictly as "positive", "neutral", or "negative". "I love the product":positive "It is a scam":negative "{{review}}.":'; Check its status. Copy Ask AI DESCRIBE sentiment_classifier; [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications#predictions-from-model-1) Predictions from Model 1 -------------------------------------------------------------------------------------------------------------------------------------------------- You can make a single predictions, providing input to the mode in the `WHERE` clause. Copy Ask AI SELECT review, sentiment FROM sentiment_classifier WHERE review = 'It is ok.'; Or, make batch predictions, joining the data table with the model. Copy Ask AI SELECT input.review, output.sentiment FROM local_postgres.demo.amazon_reviews AS input JOIN sentiment_classifier AS output; [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications#automation) Automation ---------------------------------------------------------------------------------------------------------------------- The alert system will send notification to Slack. Here is how to [connect Slack to MindsDB](https://docs.mindsdb.com/integrations/app-integrations/slack#method-2-chatbot-responds-on-a-defined-slack-channel) . Copy Ask AI CREATE DATABASE customer_reviews_slack_app WITH ENGINE = 'slack', PARAMETERS = { "token": "xoxb-xxx" }; Send a test message to test the connection. Copy Ask AI INSERT INTO customer_reviews_slack_app.messages (channel_id, text) VALUES("customer-reviews-channel-id", "Testing Slack connection"); [Create a job](https://docs.mindsdb.com/mindsdb_sql/sql/create/jobs) to send notification every time a negative review is received. Copy Ask AI CREATE JOB customer_reviews_notifications ( INSERT INTO customer_reviews_slack_app.messages (channel_id, text) SELECT "customer-reviews-channel-id" as channel_id, concat('Product: ', input.product_name, chr(10), 'Received negative review at: ', input.created_at, chr(10), 'Review: ', input.review) as text FROM local_postgres.demo.amazon_reviews AS input JOIN sentiment_classifier AS output WHERE input.created_at > LAST AND output.sentiment = 'negative' ) EVERY 1 minute; These commands are used to monitor the job. Copy Ask AI SHOW JOBS WHERE name = 'customer_reviews_notifications'; SELECT * FROM mindsdb.jobs WHERE name = 'customer_reviews_notifications'; SELECT * FROM log.jobs_history WHERE project = 'mindsdb' AND name = 'customer_reviews_notifications'; Use this command to disable the job. Copy Ask AI DROP JOB customer_reviews_notifications; [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications#model-2-setup) Model 2 setup ---------------------------------------------------------------------------------------------------------------------------- Deploy a model using the AI engine created earlier. Copy Ask AI CREATE MODEL response_model PREDICT response USING engine = 'openai_engine', model_name = 'gpt-4', prompt_template = 'briefly respond to the customer review: {{review}}'; Check its status. Copy Ask AI DESCRIBE response_model; [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications#predictions-from-model-2) Predictions from Model 2 -------------------------------------------------------------------------------------------------------------------------------------------------- You can make a single predictions, providing input to the mode in the `WHERE` clause. Copy Ask AI SELECT review, response FROM response_model WHERE review = 'It is ok.'; Or, make batch predictions, joining the data table with the model. Copy Ask AI SELECT input.review, output.response FROM local_postgres.demo.amazon_reviews AS input JOIN response_model AS output; [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/customer-reviews-notifications#automation-and-chaining-models-1-&-2) Automation and Chaining Models 1 & 2 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- [Create a job](https://docs.mindsdb.com/mindsdb_sql/sql/create/jobs) to send notification, including a sample response, every time a positive review is received. Copy Ask AI CREATE JOB customer_reviews_and_responses_notifications ( INSERT INTO customer_reviews_slack_app.messages (channel_id, text) SELECT "customer-reviews-channel-id" as channel_id, concat('---------', chr(10), 'Product: ', input.product_name, chr(10), 'Received ', input.sentiment, ' review at: ', input.created_at, chr(10), 'Review: ', input.review, chr(10), 'Sample response: ', output.response) as text FROM (SELECT inp.created_at AS created_at, inp.product_name AS product_name, inp.review AS review, outp.sentiment AS sentiment FROM local_postgres.demo.amazon_reviews AS inp JOIN sentiment_classifier AS outp WHERE inp.created_at > LAST) AS input --'2023-10-03 16:50:00' AND inp.created_at > "{{PREVIOUS_START_DATETIME}}" JOIN response_model AS output WHERE input.sentiment = 'positive'; ) EVERY 1 minute; These commands are used to monitor the job. Copy Ask AI SELECT * FROM mindsdb.jobs WHERE name = 'customer_reviews_and_responses_notifications'; SELECT * FROM log.jobs_history WHERE project = 'mindsdb' AND name = 'customer_reviews_and_responses_notifications'; Use this command to disable the job. Copy Ask AI DROP JOB customer_reviews_and_responses_notifications; Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/ai_workflow_automation/customer-reviews-notifications.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/ai_workflow_automation/customer-reviews-notifications) ⌘I --- # Manage Model Versions - MindsDB [Skip to main content](https://docs.mindsdb.com/mindsdb_sql/sql/api/manage-models-versions#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Manage Model Versions [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Creating a Model](https://docs.mindsdb.com/mindsdb_sql/sql/api/manage-models-versions#creating-a-model) * [Retraining a Model](https://docs.mindsdb.com/mindsdb_sql/sql/api/manage-models-versions#retraining-a-model) * [Using Active Model Version](https://docs.mindsdb.com/mindsdb_sql/sql/api/manage-models-versions#using-active-model-version) * [Using Specific Model Version](https://docs.mindsdb.com/mindsdb_sql/sql/api/manage-models-versions#using-specific-model-version) * [Setting Model Version as Active](https://docs.mindsdb.com/mindsdb_sql/sql/api/manage-models-versions#setting-model-version-as-active) * [Deleting Specific Model Version](https://docs.mindsdb.com/mindsdb_sql/sql/api/manage-models-versions#deleting-specific-model-version) * [Deleting All Model Versions](https://docs.mindsdb.com/mindsdb_sql/sql/api/manage-models-versions#deleting-all-model-versions) [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/manage-models-versions#creating-a-model) Creating a Model ------------------------------------------------------------------------------------------------------------- To create a model, use the [`CREATE MODEL`](https://docs.mindsdb.com/sql/create/model) statement. Copy Ask AI CREATE MODEL mindsdb.home_rentals FROM example_db (SELECT * FROM demo_data.home_rentals) PREDICT rental_price USING engine = 'lightwood', tag = 'my model'; Now, your model has one version. You can verify by querying the `models` table. Copy Ask AI DESCRIBE MODEL home_rentals; On execution, we get: Copy Ask AI +------------+---------+-------+------+-------+--------+--------+------------+-------------+---------------+------+------------------------------------+---------------------------------------+----------------------+---------------------+------+--------------------------+-------------+ |NAME |ENGINE |PROJECT|ACTIVE|VERSION|STATUS |ACCURACY|PREDICT |UPDATE_STATUS|MINDSDB_VERSION|ERROR |SELECT_DATA_QUERY |TRAINING_OPTIONS |CURRENT_TRAINING_PHASE|TOTAL_TRAINING_PHASES|TAG |CREATED_AT |TRAINING_TIME| +------------+---------+-------+------+-------+--------+--------+------------+-------------+---------------+------+------------------------------------+---------------------------------------+----------------------+---------------------+------+--------------------------+-------------+ |home_rentals|lightwood|mindsdb|true |1 |complete|0.999 |rental_price|up_to_date |22.11.3.2 |[NULL]|SELECT * FROM demo_data.home_rentals|{'target': 'rental_price', 'using': {}}|5 |5 |[NULL]|2024-02-07 16:01:04.990958|19.946 | +------------+---------+-------+------+-------+--------+--------+------------+-------------+---------------+------+------------------------------------+---------------------------------------+----------------------+---------------------+------+--------------------------+-------------+ [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/manage-models-versions#retraining-a-model) Retraining a Model ----------------------------------------------------------------------------------------------------------------- To retrain a model, use the [`RETRAIN`](https://docs.mindsdb.com/sql/api/retrain) statement. Copy Ask AI RETRAIN mindsdb.home_rentals; Let’s query for the model versions again. Copy Ask AI DESCRIBE MODEL home_rentals; On execution, we get: Copy Ask AI +------------+---------+-------+------+-------+--------+--------+------------+-------------+---------------+------+------------------------------------+---------------------------------------+----------------------+---------------------+------+--------------------------+-------------+ |NAME |ENGINE |PROJECT|ACTIVE|VERSION|STATUS |ACCURACY|PREDICT |UPDATE_STATUS|MINDSDB_VERSION|ERROR |SELECT_DATA_QUERY |TRAINING_OPTIONS |CURRENT_TRAINING_PHASE|TOTAL_TRAINING_PHASES|TAG |CREATED_AT |TRAINING_TIME| +------------+---------+-------+------+-------+--------+--------+------------+-------------+---------------+------+------------------------------------+---------------------------------------+----------------------+---------------------+------+--------------------------+-------------+ |home_rentals|lightwood|mindsdb|true |1 |complete|0.999 |rental_price|up_to_date |22.11.3.2 |[NULL]|SELECT * FROM demo_data.home_rentals|{'target': 'rental_price', 'using': {}}|5 |5 |[NULL]|2024-02-07 16:01:04.990958|19.946 | |home_rentals|lightwood|mindsdb|true |2 |complete|0.999 |rental_price|up_to_date |22.11.3.2 |[NULL]|SELECT * FROM demo_data.home_rentals|{'target': 'rental_price', 'using': {}}|5 |5 |[NULL]|2024-02-07 17:01:04.990958|21.923 | +------------+---------+-------+------+-------+--------+--------+------------+-------------+---------------+------+------------------------------------+---------------------------------------+----------------------+---------------------+------+--------------------------+-------------+ [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/manage-models-versions#using-active-model-version) Using Active Model Version --------------------------------------------------------------------------------------------------------------------------------- To use the currently active model version, run this query: Copy Ask AI SELECT * FROM mindsdb.home_rentals AS p JOIN example_db.demo_data.home_rentals AS d; [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/manage-models-versions#using-specific-model-version) Using Specific Model Version ------------------------------------------------------------------------------------------------------------------------------------- To use a specific model version, even if it is set to inactive, run this query: Copy Ask AI SELECT * FROM mindsdb.home_rentals.1 AS p JOIN example_db.demo_data.home_rentals AS d; [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/manage-models-versions#setting-model-version-as-active) Setting Model Version as Active ------------------------------------------------------------------------------------------------------------------------------------------- To set a specific model version as active, run the below statement: Copy Ask AI SET model_active = home_rentals.1; [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/manage-models-versions#deleting-specific-model-version) Deleting Specific Model Version ------------------------------------------------------------------------------------------------------------------------------------------- To delete a specific model version, run the below statement: Copy Ask AI DROP MODEL home_rentals.2 Please note that you cannot delete the version that is active. [​](https://docs.mindsdb.com/mindsdb_sql/sql/api/manage-models-versions#deleting-all-model-versions) Deleting All Model Versions ----------------------------------------------------------------------------------------------------------------------------------- To delete all models version, run the `DROP MODEL` statement: Copy Ask AI DROP MODEL mindsdb.home_rentals; Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/mindsdb_sql/sql/api/manage-models-versions.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/mindsdb_sql/sql/api/manage-models-versions) ⌘I --- # Build a Slack Chatbot with MindsDB and OpenAI - MindsDB [Skip to main content](https://docs.mindsdb.com/use-cases/ai_workflow_automation/slack-chatbot#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Build a Slack Chatbot with MindsDB and OpenAI [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Getting Started](https://docs.mindsdb.com/use-cases/ai_workflow_automation/slack-chatbot#getting-started) * [Usage](https://docs.mindsdb.com/use-cases/ai_workflow_automation/slack-chatbot#usage) * [1\. Crafting the GPT-4 Model:](https://docs.mindsdb.com/use-cases/ai_workflow_automation/slack-chatbot#1-crafting-the-gpt-4-model%3A) * [2\. Feeding Personality into Our Model](https://docs.mindsdb.com/use-cases/ai_workflow_automation/slack-chatbot#2-feeding-personality-into-our-model) * [3\. Let’s Connect our GPT Model to Slack!](https://docs.mindsdb.com/use-cases/ai_workflow_automation/slack-chatbot#3-let%E2%80%99s-connect-our-gpt-model-to-slack) * [4\. Posting Messages using SQL](https://docs.mindsdb.com/use-cases/ai_workflow_automation/slack-chatbot#4-posting-messages-using-sql) * [5\. Let’s automate this](https://docs.mindsdb.com/use-cases/ai_workflow_automation/slack-chatbot#5-let%E2%80%99s-automate-this) The objective of this tutorial is to create an AI-powered personalized chatbot by utilizing the MindsDB’s Slack connector, and combining it with OpenAI’s GPT-4 Model. To illustrate practically, we will create a Slack bot - **@Whiz\_Fizz** - which will reply to the user’s queries with proper context and with a unique persona while responding. It is a weird magician 🪄 and a Space Science Expert! Let’s see how it responds. ![](https://mintcdn.com/mindsdb/tkxKy44mj_2VlYcf/assets/SLBot-Hero-Whizfizz.png?w=2500&fit=max&auto=format&n=tkxKy44mj_2VlYcf&q=85&s=3666f3c475b623175099b40da1420185) Before jumping more into it. Let’s first see how to create a bot and connect it to our Slack Workspace. [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/slack-chatbot#getting-started) Getting Started --------------------------------------------------------------------------------------------------------------- * Install MindsDB locally via [Docker](https://docs.mindsdb.com/setup/self-hosted/docker) or [Docker Desktop](https://docs.mindsdb.com/setup/self-hosted/docker-desktop) * [Create a Slack Account](https://slack.com/get-started#/createnew) and follow [this instruction](https://docs.mindsdb.com/integrations/app-integrations/slack) to connect Slack to MindsDB. * Go to your MindsDB Editor [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/slack-chatbot#usage) Usage ------------------------------------------------------------------------------------------- This query will create a database called `mindsdb_slack` that comes with the `channels` table. Copy Ask AI CREATE DATABASE mindsdb_slack WITH ENGINE = 'slack', PARAMETERS = { "token": "xoxb-..." }; Here is how to retrieve the 10 messages after specific timestamp: Copy Ask AI SELECT * FROM mindsdb_slack.messages WHERE channel_id = "" AND created_at > '2023-07-25 00:13:07' -- created_at stores the timestamp when the message was created LIMIT 10; You can also retrieve messages in alphabetical order: Copy Ask AI SELECT * FROM mindsdb_slack.messages WHERE channel_id = "" ORDER BY text ASC LIMIT 5; By default, it retrieves by the order the messages were sent, unless specified as ascending/descending. Here is how to post messages: Copy Ask AI INSERT INTO mindsdb_slack.messages (channel_id, text) VALUES ("", "Hey MindsDB, Thanks to you! Now I can respond to my Slack messages through SQL Queries. 🚀 "), ("", "It's never been that easy to build ML apps using MindsDB!"); Whoops! Sent it by mistake? No worries! Use this to delete a specific message: Copy Ask AI DELETE FROM mindsdb_slack.messages WHERE channel_id = "" AND ts = "1688863707.197229"; Now, let’s roll up our sleeves and start building the GPT-4 Model together. ### [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/slack-chatbot#1-crafting-the-gpt-4-model:) 1\. Crafting the GPT-4 Model: _Generating a [Machine Learning model](https://docs.mindsdb.com/nlp/nlp-mindsdb-openai) with MindsDB feels like taking a thrilling elevator ride in Burj Khalifa (You don’t realize, that you made it)!_ Here `gpt_model` represents our GPT-4 Model. Before creating an OpenAI model, please create an engine, providing your OpenAI API key: Copy Ask AI CREATE ML_ENGINE openai_engine FROM openai USING openai_api_key = 'your-openai-api-key'; Copy Ask AI CREATE MODEL mindsdb.gpt_model PREDICT response USING engine = 'openai_engine', max_tokens = 300, model_name = 'gpt-4', prompt_template = 'From input message: {{text}}\ write a short response to the user in the following format:\ Hi, I am an automated bot here to help you, Can you please elaborate the issue which you are facing! ✨🚀 '; The critical attribute here is `prompt_template` where we tell the GPT model how to respond to the questions asked by the user. Let’s see how it works: Copy Ask AI SELECT text, response FROM mindsdb.gpt_model WHERE text = 'Hi, can you please explain me more about MindsDB?'; ![](https://mintcdn.com/mindsdb/tkxKy44mj_2VlYcf/assets/SLBot-response1.png?w=2500&fit=max&auto=format&n=tkxKy44mj_2VlYcf&q=85&s=93031a96ecb7a8ffb353081c4efbe59c) ### [​](https://docs.mindsdb.com/use-cases/ai_workflow_automation/slack-chatbot#2-feeding-personality-into-our-model) 2\. Feeding Personality into Our Model Alright, so the old model’s replies were _good_. But hey, we can use some prompt template tricks to make it respond the way we want. Let’s do some Prompt Engineering. Now, let’s make a model called `whizfizz_model` with a prompt template that gives GPT a wild personality that eludes a playful and magical aura. Imagine scientific knowledge with whimsical storytelling to create a unique and enchanting experience. We’ll call him **WhizFizz**: Copy Ask AI CREATE MODEL mindsdb.whizfizz_model PREDICT response USING engine = 'openai_engine', max_tokens = 300, model_name = 'gpt-4', prompt_template = 'From input message: {{text}}\ write a short response in less than 40 words to some user in the following format:\ Hi there, WhizFizz here! LAST AND t.user = 'user_id' -- to avoid the bot replying to its own messages, include users to which bot should reply --AND t.user != 'bot_id' -- alternatively, to avoid the bot replying to its own messages, exclude the user id of the bot ) EVERY hour; The `LAST` keyword is used to ensure the query fetches only the newly added messages. Learn more [here](https://docs.mindsdb.com/mindsdb_sql/sql/create/jobs#last) . That sums up the tutorial! Here it will continually check for new messages posted in the channel and will respond to all newly added messages providing responses generated by OpenAI’s GPT model in the style of WhizFizz. To check the `jobs` and `jobs_history`, we can use the following: Copy Ask AI SHOW JOBS WHERE name = 'gpt4_slack_job'; SELECT * FROM mindsdb.jobs WHERE name = 'gpt4_slack_job'; SELECT * FROM log.jobs_history WHERE project = 'mindsdb' AND name = 'gpt4_slack_job'; To stop the scheduled job, we can use the following: Copy Ask AI DROP JOB gpt4_slack_job; Alternatively, you can create a trigger on Slack, instead of scheduling a job. This way, every time new messages are posted, the trigger executes. Copy Ask AI CREATE TRIGGER slack_trigger ON mindsdb_slack.messages ( INSERT INTO mindsdb_slack.messages(channel_id, text) SELECT t.channel_id as channel_id, a.sentiment as text, FROM data_table t JOIN model_table as a WHERE t.channel_id = '' AND t.user != 'bot_id' -- exclude bot ); **What’s next?**Check out [How to Generate Images using OpenAI with MindsDB](https://docs.mindsdb.com/sql/tutorials/image-generator) to see another interesting use case of OpenAI integration. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/use-cases/ai_workflow_automation/slack-chatbot.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/use-cases/ai_workflow_automation/slack-chatbot) ⌘I --- # Configure an ML Engine - MindsDB [Skip to main content](https://docs.mindsdb.com/sdks/javascript/create_ml_engine#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Configure an ML Engine [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) This feature is in progress. Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/sdks/javascript/create_ml_engine.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/sdks/javascript/create_ml_engine) ⌘I --- # Get Batch Predictions - MindsDB [Skip to main content](https://docs.mindsdb.com/sdks/javascript/batchQuery#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Get Batch Predictions [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) On this page * [Description](https://docs.mindsdb.com/sdks/javascript/batchQuery#description) * [Syntax](https://docs.mindsdb.com/sdks/javascript/batchQuery#syntax) [​](https://docs.mindsdb.com/sdks/javascript/batchQuery#description) Description ----------------------------------------------------------------------------------- The `batchQuery()` function fetches batch predictions from the model by joining it with the data table. [​](https://docs.mindsdb.com/sdks/javascript/batchQuery#syntax) Syntax ------------------------------------------------------------------------- Here is the syntax: Copy Ask AI await model_name.batchQuery(batchQueryOptions); Here are some useful links: * [training options](https://mindsdb.github.io/mindsdb-js-sdk/interfaces/models_trainingOptions.TrainingOptions.html) , * [query options](https://mindsdb.github.io/mindsdb-js-sdk/interfaces/models_queryOptions.QueryOptions.html) , * [batch query options](https://mindsdb.github.io/mindsdb-js-sdk/interfaces/models_queryOptions.BatchQueryOptions.html) . Was this page helpful? YesNo [Suggest edits](https://github.com/mindsdb/mindsdb/edit/main/docs/sdks/javascript/batchQuery.mdx) [Raise issue](https://github.com/mindsdb/mindsdb/issues/new?title=Issue%20on%20docs&body=Path:%20/sdks/javascript/batchQuery) ⌘I --- # Page Not Found [Skip to main content](https://docs.mindsdb.com/nlp/nlp-mindsdb-openai#content-area) [MindsDB home page![light logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/light.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f30c11693efebe948265e9f53e935db3)![dark logo](https://mintcdn.com/mindsdb/QF5BKvjknzzY0II3/logo/dark.svg?fit=max&auto=format&n=QF5BKvjknzzY0II3&q=85&s=f2314d55d2cc12ea09eb1b914c8aa5b6)](https://docs.mindsdb.com/) Search... ⌘KAsk AI Search... Navigation Page Not Found [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) [Documentation](https://docs.mindsdb.com/mindsdb) [Connect](https://docs.mindsdb.com/mindsdb-connect) [Unify](https://docs.mindsdb.com/mindsdb-unify) [Respond](https://docs.mindsdb.com/mindsdb-respond) [MCP API](https://docs.mindsdb.com/model-context-protocol/overview) [SDKs & APIs](https://docs.mindsdb.com/overview_sdks_apis) [Contribute](https://docs.mindsdb.com/contribute/contribute) [FAQs](https://docs.mindsdb.com/faqs/benefits) * [Slack](https://mindsdb.com/joincommunity) * [GitHub](https://github.com/mindsdb/mindsdb) * [Website](https://mindsdb.com/) * [Watch Video](https://www.youtube.com/watch?v=HPwUPJ3NWLI) 404 Page Not Found ============== We couldn't find the page. Maybe you were looking for one of these pages below? [MindsDB's MCP Server with OpenAI's Remote MCP](https://docs.mindsdb.com/model-context-protocol/openai#) [Disposable Email Domains and OpenAI](https://docs.mindsdb.com/faqs/disposable-email-doman-and-openai#) [MindsDB's MCP Server Usage and Tools](https://docs.mindsdb.com/model-context-protocol/usage#mindsdbs-mcp-server-usage-and-tools) ⌘I ---