MindsDB Integration
Overview
MindsDB is an open-source AI data automation platform that brings AI capabilities directly to your databases. It enables developers to build AI-powered applications using familiar SQL syntax, connecting to over 200 data sources and integrating with various AI frameworks without requiring deep ML expertise.
Ideal for developers and data teams who want to add AI capabilities to their existing data infrastructure without complex ML pipelines or ETL processes.
Key Features
- SQL-Based AI: Use standard SQL to create, train, and deploy AI models
- 200+ Data Connectors: Connect to databases, SaaS apps, file systems, and APIs
- Federated Query Engine: Query multiple data sources as if they were a single database
- AI Tables: Create virtual tables for models, agents, and knowledge bases
- Built-in MCP Server: Native Model Context Protocol support for AI applications
- Real-time Processing: Schedule jobs and triggers for automated AI workflows
- Model Agnostic: Integrate with OpenAI, Anthropic, Hugging Face, and custom models
Use Cases
- Build AI agents that answer questions across federated enterprise data
- Create predictive models for business forecasting and analytics
- Implement real-time sentiment analysis and text classification
- Develop chatbots with access to live database information
- Automate data transformation and enrichment with AI
- Generate insights from structured and unstructured data
Setup Instructions
-
Create a directory for MindsDB data persistence:
Terminal window mkdir mdb_data -
Run MindsDB using Docker with the necessary ports and configuration:
Terminal window docker run --name mindsdb_container \-e MINDSDB_APIS=http,mysql,mcp \-p 47334:47334 \-p 47335:47335 \-p 47337:47337 \-v $(pwd)/mdb_data:/root/mdb_storage \mindsdb/mindsdb -
Access MindsDB interface at
http://localhost:47334
-
You can either configure MindsDB for a Default, Reranking or Embeddings model via the GUI to connect to RelaxAI or use the SQL editor directly. Make note to refer the correct model names for the RelaxAI API.
-
Configure MindsDB to use RelaxAI by creating an AI engine in the MindsDB SQL editor:
CREATE ML_ENGINE relax_engineFROM openaiUSINGapi_base = 'https://api.relax.ai/v1',api_key = 'RELAX_API_KEY'; -
Create a model using RelaxAI:
CREATE MODEL my_ai_modelPREDICT responseUSINGengine = 'relax_engine',model_name = 'Llama-4-Maverick-17B-128E',prompt_template = 'Your prompt template here: {{text}}'; -
Create an agent if you prefer to handle requests and structured responses from your knowledge base, there’s option to connect with multiple external datasources as well. For reference check the official documentation.
CREATE AGENT relax_agentUSINGmodel = {"provider": "openai","model_name" : "Llama-4-Maverick-17B-128E","api_key": "RELAX_API_KEY","base_url": "https://api.relax.ai/v1"},data = {"knowledge_bases": ["datasource.iris"],"tables": ["iris"]},prompt_template = 'iris is a classic dataset in machine learning, particularly for beginners, containing measurements of iris flowers from three different species: Setosa, Versicolor, and Virginica. Its a multivariate dataset with four features for each flower: sepal length, sepal width, petal length, and petal width, all measured in centimeters'; -
To run the agent and get responses from your dataset in natural language, you can use the following SQL command:
SELECT * FROM relax_agentWHERE question = 'What is the average sepal length of Setosa species?';
Configuration Options
Docker Environment Variables:
MINDSDB_APIS
: Enable specific APIs (http, mysql, mcp, a2a)MINDSDB_USERNAME
: Set admin username (optional)MINDSDB_PASSWORD
: Set admin password (optional)MINDSDB_A2A_HOST
: Set host for remote access (if needed)
Port Mappings:
47334
: HTTP API and Web UI47335
: MySQL wire protocol47337
: MCP server47338
: A2A API (if enabled)
Commands and Usage
MindsDB uses SQL syntax for all AI operations:
Basic Operations:
-- Connect to a data sourceCREATE DATABASE my_postgresWITH ENGINE = 'postgresql',PARAMETERS = { "host": "localhost", "port": 5432, "database": "mydb", "user": "user", "password": "password"};
-- Create a predictive modelCREATE MODEL sales_predictorFROM my_postgres (SELECT * FROM sales_data)PREDICT amountUSING engine = 'relax_engine';
-- Make predictionsSELECT * FROM sales_predictorWHERE date > '2024-01-01';
Advanced Features:
- AI Tables: Create agents, models, and knowledge bases as SQL tables
- Jobs: Schedule recurring AI tasks with
CREATE JOB
- Triggers: React to data changes with
CREATE TRIGGER
- Views: Create unified views across multiple data sources
Working with Data Sources
MindsDB can connect to various data sources:
-- Connect to MySQLCREATE DATABASE mysql_dbWITH ENGINE = 'mysql',PARAMETERS = { "host": "mysql-server", "port": 3306, "database": "mydb", "user": "root", "password": "password"};
-- Connect to MongoDBCREATE DATABASE mongo_dbWITH ENGINE = 'mongodb',PARAMETERS = { "host": "mongodb://localhost:27017", "database": "mydb"};
-- Query across multiple sourcesSELECT m.*, p.*FROM mysql_db.users mJOIN postgres_db.orders pON m.user_id = p.user_id;
Best Practices
- Use persistent volumes to maintain data between container restarts
- Install only required integrations to keep the container lightweight
- Test models with small datasets before running on production data
- Use jobs for scheduled AI tasks instead of external schedulers
- Monitor resource usage as AI operations can be compute-intensive
- Leverage views to simplify complex multi-source queries
Troubleshooting
- Container not starting: Check if ports 47334-47338 are available
- Connection refused: When connecting integrations in other containers, use
http://host.docker.internal
instead oflocalhost
- Model errors: Verify API credentials and endpoint configuration
- Missing dependencies: Install integration dependencies via Settings → Manage Integrations in the UI
- Performance issues: Consider using MindsDB Cloud for production workloads