Databases 15 min read

How to Build Predictive and Generative AI Apps with MySQL AI

MySQL AI adds built‑in LLMs, embeddings, vector storage, AutoML and a graphical console to on‑premise MySQL, enabling developers to create predictive and generative AI applications—including fraud detection, semantic search, RAG and NL2SQL—without external vector databases or GPUs.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
How to Build Predictive and Generative AI Apps with MySQL AI

What is MySQL AI?

MySQL AI is an on‑premise feature of MySQL Enterprise that embeds large language models (LLM) and embedding models that run on CPU, a built‑in vector store, semantic search, AutoML, and a graphical console called MySQL Studio. All AI capabilities are exposed through SQL functions, stored procedures, and REST APIs, callable from MySQL Shell, Python, Java, or any MySQL client.

MySQL AI application cases diagram
MySQL AI application cases diagram

Key use cases

Predictive AI : fraud detection, inventory monitoring, demand forecasting, loan‑default risk assessment, anomaly detection in streaming logs.

Generative AI : multi‑language content creation, document summarisation, retrieval‑augmented generation (RAG) for private document search, NL2SQL, and other GenAI scenarios.

Getting started with MySQL AI

All capabilities are available via SQL functions, stored procedures, and REST endpoints. The following two examples illustrate typical workflows.

Example 1: Retrieval‑augmented generation (RAG)

The RAG workflow consists of three steps: (i) copy a document to a MySQL‑accessible directory, (ii) load the document into the vector store, and (iii) query the document with natural language.

Step 1 – Copy the file

sudo cp /home/john_doe/Olympics_2024.pdf /var/lib/mysql-files

Step 2 – Load the document into the vector store

CALL sys.VECTOR_STORE_LOAD(
  'file:///var/lib/mysql-files/2024_Summer_Olympics_Wikipedia.pdf',
  JSON_OBJECT('schema_name','mlcorpus','table_name','vector_store_data_1')
);

Step 3 – Query with

sys.ML_RAG
CALL sys.ML_RAG(
  "Where were the 2024 Summer Olympics held?",
  @output,
  JSON_OBJECT(
    'model_options',JSON_OBJECT('model_id','llama3.2-3b-instruct-v1'),
    'vector_store',JSON_ARRAY('mlcorpus.vector_store_data_1')
  )
);
SELECT JSON_PRETTY(@output);

The call returns the answer: "The 2024 Summer Olympics were held in France."

Example 2: Credit‑card fraud detection

This example uses MySQL AI’s AutoML pipeline for unsupervised anomaly detection.

Step 1 – Train a model

SET @model = NULL;
CALL sys.ML_TRAIN(
  'mlcorpus.creditcard_train',
  NULL,
  JSON_OBJECT(
    'task','anomaly_detection',
    'exclude_column_list',JSON_ARRAY('Class')
  ),
  @model
);

Step 2 – Generate predictions on test data

CALL sys.ML_PREDICT_TABLE(
  'mlcorpus.creditcard_test',
  @model,
  'mlcorpus.creditcard_test_predictions',
  NULL
);
SELECT Time, Amount, ml_results FROM mlcorpus.creditcard_test_predictions;

Development tools provided by MySQL AI

MySQL Studio – a unified graphical interface that includes an SQL workshop, a chat UI for vector‑store queries, and Jupyter‑compatible notebooks.

Python SDK – provides MyLLM (generation), MyEmbeddings (embeddings), MyVectorStore (vector store) for LangChain integration, and AutoML wrappers such as MyModel, MyClassifier, MyAnomalyDetector, MyRegressor, and MyGenericTransformer.

Model Context Protocol (MCP) – an open standard that enables LLM‑driven applications to call external tools or data sources via a client‑server model, simplifying integration of AI into existing workflows.

Natural language to SQL (NL2SQL)

Users can pose questions in plain language. The system extracts relevant schema metadata, appends it to the prompt, and sends it to the LLM. The generated SQL is automatically validated; only verified statements are executed, allowing non‑technical users to explore data safely.

References

MySQL AI announcement: https://blogs.oracle.com/mysql/announcing-mysql-ai

RAG notebook example: https://github.com/oracle-samples/heatwave-ml/blob/main/python/mysqlai/rag_chat.ipynb

Fraud‑detection notebook example: https://github.com/oracle-samples/heatwave-ml/blob/main/python/mysqlai/fraud_detection_creditcard.ipynb

Oracle E‑Delivery trial download: https://edelivery.oracle.com/

RAGGenerative AIAutoMLdatabase AIPython SDKMySQL AIPredictive AI
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.