Skip to content

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

  1. Create a directory for MindsDB data persistence:

    Terminal window
    mkdir mdb_data
  2. 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
  3. Access MindsDB interface at http://localhost:47334

  4. 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.

mindsdb-config

  1. Configure MindsDB to use RelaxAI by creating an AI engine in the MindsDB SQL editor:

    CREATE ML_ENGINE relax_engine
    FROM openai
    USING
    api_base = 'https://api.relax.ai/v1',
    api_key = 'RELAX_API_KEY';
  2. Create a model using RelaxAI:

    CREATE MODEL my_ai_model
    PREDICT response
    USING
    engine = 'relax_engine',
    model_name = 'Llama-4-Maverick-17B-128E',
    prompt_template = 'Your prompt template here: {{text}}';
  3. 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_agent
    USING
    model = {
    "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';
  4. To run the agent and get responses from your dataset in natural language, you can use the following SQL command:

    SELECT * FROM relax_agent
    WHERE question = 'What is the average sepal length of Setosa species?';

    mindsdb-response

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 UI
  • 47335: MySQL wire protocol
  • 47337: MCP server
  • 47338: A2A API (if enabled)

Commands and Usage

MindsDB uses SQL syntax for all AI operations:

Basic Operations:

-- Connect to a data source
CREATE DATABASE my_postgres
WITH ENGINE = 'postgresql',
PARAMETERS = {
"host": "localhost",
"port": 5432,
"database": "mydb",
"user": "user",
"password": "password"
};
-- Create a predictive model
CREATE MODEL sales_predictor
FROM my_postgres (SELECT * FROM sales_data)
PREDICT amount
USING engine = 'relax_engine';
-- Make predictions
SELECT * FROM sales_predictor
WHERE 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 MySQL
CREATE DATABASE mysql_db
WITH ENGINE = 'mysql',
PARAMETERS = {
"host": "mysql-server",
"port": 3306,
"database": "mydb",
"user": "root",
"password": "password"
};
-- Connect to MongoDB
CREATE DATABASE mongo_db
WITH ENGINE = 'mongodb',
PARAMETERS = {
"host": "mongodb://localhost:27017",
"database": "mydb"
};
-- Query across multiple sources
SELECT m.*, p.*
FROM mysql_db.users m
JOIN postgres_db.orders p
ON 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 of localhost
  • 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

Resources