MindsDB Docker Extension: Build ML powered apps at a much faster pace

Ajeet Singh Raina - Jan 1 - - Dev Community

Imagine a world where anyone, regardless of technical expertise, can easily harness the power of artificial intelligence (AI) to gain insights from their data. Where building and deploying machine learning models is as intuitive as querying a database. This is the future promised by MindsDB, a revolutionary open-source platform that's democratizing AI for everyone.

MindsDB = SQL + AI

MindsDB combines both AI and SQL functions in one; users can create, train, optimize, and deploy ML models without the need for external tools. Data analysts can create and visualize forecasts without having to navigate the complexities of ML pipelines.MindsDB is open-source and works with well-known databases like MySQL, Postgres, Redit, Snowflakes, etc.

How MindsDB works?

MindsDB boasts a unique architecture designed to bridge the gap between developers and AI through its AI SQL Server approach. Here's a breakdown of its key components:

1. AI Building Blocks:

These are MindsDB's core functionalities represented as virtual tables accessible via SQL queries. They include:

  • Models: Trained machine learning models, allowing predictions and inferences.
  • Agents: Pre-built AI functions for tasks like sentiment analysis or chatbots.
  • Knowledge Bases: Structured knowledge graphs for entity recognition and relationship extraction.

2. SQL Interface:

MindsDB leverages your existing SQL knowledge, allowing you to:

  • Fine-tune Models: Improve existing models using your data within familiar SQL syntax.
  • Create AI Tables: Define new AI components like agents or knowledge bases using CREATE statements.
  • Query AI Results: Integrate AI insights into your applications and pipelines using JOINs, filtering, and other familiar operations.

3. Datasources:

MindsDB can access data from various sources to fuel your AI models:

  • Databases: Connect directly to popular relational and NoSQL databases.
  • Applications: Integrate with APIs and web services for real-time data streams.
  • Vector Stores: Utilize dedicated data structures for efficient retrieval of high-dimensional data.

4. Jobs and Triggers:

Automate AI-powered tasks and workflows:

  • Jobs: Schedule queries or model training at specific times or intervals.
  • Triggers: React to data changes automatically by invoking AI operations.

5. Underlying Engine:

MindsDB utilizes various open-source AI frameworks under the hood to handle model training and inference, like PyTorch, TensorFlow, and ONNX. These frameworks remain transparent to the user, who interacts only through the SQL interface.

Why do you need MindsDB Docker Extension?

For data scientists who want to build ML models with MindsDB but aren't Docker pros, setting up this powerful tool can be daunting. Docker's intricacies like networking and volumes often stand in the way. Enter the MindsDB Docker Extension: a single-click solution that lets you skip the Docker deep dive and jump straight to model building.

This extension works its magic behind the scenes, downloading the necessary image, configuring everything just right, and making MindsDB readily accessible within Docker Desktop. No more fussing with commands or deciphering network jargon. You're free to focus on what you do best - analyzing data and building your predictive models.

Gone are the days of wrestling with updates. The extension takes care of keeping MindsDB current, ensuring you always have the latest features and bug fixes at your fingertips. All this translates to a streamlined workflow, freeing up your valuable time for what matters most: unlocking the power of machine learning.

The MindsDB Docker Extension empowers developers to:

  • Integrate AI seamlessly into containerized workflows. Ensure consistent environments from development to production.
  • Share and deploy AI models with ease.
  • Optimize resource usage and security.
  • Streamline deployment to production.

Getting Started

Pre-requisite

  • Docker Desktop(Mac/Linux/Windows)

Install MindsDB Docker Extension

Open Docker Desktop > Dashboard > Extensions and search for "MindsDB" > Click on "Install"

Image3

You will need to wait for 1 minutes to get it fully installed on your laptop.

Image3

Don't panic if you see this blank screen for next 20-30 seconds. Have patience and wait till the complete app is up and running.

Image4

You will soon the MindsDB Dashboard as shown below:

Image5

Predicting Text Sentiment with OpenAI GPT

You can find this sample tutorial in the MindsDB "Learning Hub" section. In this sample example, you will create a predictive model to infer emotions behind a text, a task also known as sentiment analysis. The model, or an AI table, leverages OpenAI’s large language models to complete this task.

Connect a Database

Start by connecting a demo database using the CREATE DATABASE statement:



CREATE DATABASE mysql_reviews_db
WITH ENGINE = "mysql",
PARAMETERS = {
    "user": "user",
    "password": "MindsDBUser123!",
    "host": "db-demo-data.cwoyhfn6bzs0.us-east-1.rds.amazonaws.com",
    "port": "3306",
    "database": "public"
    };


Enter fullscreen mode Exit fullscreen mode

Image6

Let’s look at the data stored in the amazon_reviewstable that contains the input columns for the model:



SELECT *
FROM mysql_reviews_db.amazon_reviews;


Enter fullscreen mode Exit fullscreen mode

Image7

Configure an OpenAI Engine in MindsDB

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.



CREATE ML_ENGINE openai_engine
FROM openai
USING
    api_key = 'your-openai-api-key';


Enter fullscreen mode Exit fullscreen mode

Create an OpenAI GPT Model

Our integration automatically manages requests to pre-trained large language models from OpenAI. For example, we can create a model for text sentiment analysis like this:



CREATE MODEL sentiment_classifier_gpt
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}}.":';


Enter fullscreen mode Exit fullscreen mode

Image8

In practice, the CREATE MODEL statement triggers MindsDB to generate an AI table called sentiment_classifier_gpt that uses the OpenAI integration to predict a column named sentiment.

The USINGclause specifies the parameters that this handler requires. You can check our documentation for detailed explanations of all parameters that can be used when creating various models with the OpenAI engine.

Once the above query has started execution, we can check the status of the creation process with the following query:



SELECT * FROM models
WHERE name = 'sentiment_classifier_gpt';


Enter fullscreen mode Exit fullscreen mode

It may take a while to register as completedepending on the internet connection.

Image9

Make a Single Prediction

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:



SELECT review, sentiment
FROM sentiment_classifier_gpt
WHERE review = 'It is ok.';


Enter fullscreen mode Exit fullscreen mode

Image10

Make Batch Predictions

Or by joining with another table for batch predictions:



SELECT input.review, output.sentiment
FROM mysql_reviews_db.amazon_reviews AS input
JOIN sentiment_classifier_gpt AS output
LIMIT 5;


Enter fullscreen mode Exit fullscreen mode

The amazon_reviewstable is used to make batch predictions. Upon joining the sentiment_classifier_gptmodel with the amazon_reviewstable, the model uses all values from the reviewcolumn.

Image12

MindsDB enables in-database ML with your favorite frameworks. You need just a handler for MindsDB to integrate the ML framework of your interest.

Conclusion

In essence, MindsDB aims to make AI accessible and approachable for developers by leveraging familiar SQL tools and integrating seamlessly with existing workflows. This enables developers to build AI applications without extensive machine learning expertise, paving the way for wider adoption and democratization of AI.

References

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .