Databases 14 min read

MySQL 9.0+ Goes Full AI: Native Vectors, RAG & AutoML in One Database

MySQL 9.0+ introduces native VECTOR type, built-in semantic search with RAG, and AutoML via SQL, enabling AI workloads without external services; the article details three core capabilities, two deployment modes (local enterprise edition and cloud HeatWave), complete query logic, and three runnable code examples for vector storage, similarity search, and document-based RAG.

Su San Talks Tech
Su San Talks Tech
Su San Talks Tech
MySQL 9.0+ Goes Full AI: Native Vectors, RAG & AutoML in One Database

As the industry's most mainstream relational database, MySQL has accompanied developers for decades. Its core strengths have long been transaction stability, structured data handling, and mature operations, making it the default storage for most business systems. However, after AI adoption grew, traditional databases showed gaps: vector retrieval, intelligent Q&A, and data prediction required separate services.

Classic MySQL Positioning and Past Limitations

Born in 1995 and now under Oracle, MySQL became the standard for websites and backend systems thanks to its open-source, stable, and lightweight nature. It excels at structured data: tables store users, orders, inventory; SQL enables efficient queries; transactions guarantee consistency; replication, permissions, and backups support stable production runs.

Before AI, implementing semantic search, intelligent Q&A, or prediction meant standing up separate vector services and ML frameworks, manually migrating MySQL data — a cumbersome, high-maintenance process.

Starting with MySQL 9.0 (July 2024), the official release introduced a native VECTOR type, paired with cloud HeatWave generative AI and on-premise Enterprise Edition MySQL AI, giving the database true intelligent capabilities.

Three Core AI Capabilities

The intelligent upgrade splits into three modules, each covering a core scenario: vector storage, intelligent Q&A, and machine learning.

1. Native Vector Column Storage for Semantic Data

MySQL 9.0+ supports defining VECTOR fields in tables. A vector is a set of floating-point numbers quantifying semantic features of text or documents; semantically similar content yields closely aligned vectors.

The community edition can create vector columns directly, using STRING_TO_VECTOR and VECTOR_TO_STRING functions for easy write/read. The field defaults to 2048 dimensions, supports up to 16383 single-precision floats, and currently cannot serve as a primary key or ordinary index.

2. Built-in Semantic Retrieval and RAG Intelligent Q&A

The database includes a DISTANCE function supporting cosine distance, dot product, and Euclidean distance to precisely judge semantic similarity between two pieces of content.

The system auto-parses PDF, TXT, HTML, PPT, DOCX, and other documents, automatically chunks them, generates vectors, and stores them in tables. Leveraging the built-in sys.ML_RAG capability, natural-language questions trigger automatic matching of relevant document fragments, combined with a large model to generate cited, accurate answers.

MySQL 9.5.0's cloud HeatWave version further supports fused keyword and semantic retrieval, significantly boosting precision.

3. In-Database AutoML Machine Learning Prediction

No external ML platform needed: call sys.ML_TRAIN via SQL to train models directly on raw business tables, enabling classification tasks like user repurchase prediction or risk scoring.

Data never leaves the database; training and prediction complete in one place, eliminating migration and cross-platform scheduling overhead.

Two Deployment Modes: On-Premise Private & Cloud

MySQL AI offers two solutions fitting private on-premise and lightweight cloud scenarios.

1. On-Premise Private: MySQL AI Enterprise Edition

Suits scenarios where data must stay off-cloud and run fully locally. The Enterprise Edition bundles the large model, vector storage, and AutoML; runs on CPU only, no GPU required.

Local documents simply go into a designated server directory (default /var/lib/mysql-files); dedicated statements handle document reading, chunking, and vector ingestion — all data stays local, secure, and controlled.

Supported on Oracle Linux 8 and Red Hat Enterprise Linux 8; requires Enterprise license. Official baseline recommendation: 32-core CPU, 128 GB RAM, 512 GB disk. Locally developed AI business code migrates seamlessly to cloud without major rewrite.

2. Cloud Deployment: HeatWave GenAI

The cloud version reads document resources from object storage, reuses the same RAG and ML calling syntax as on-premise, but delivers stronger performance and richer features — ideal for online workloads demanding high response speed and concurrency.

MySQL AI Q&A Complete Running Logic

Many wonder how database AI Q&A differs from generic LLM Q&A. The core advantage is alignment with private business data.

Generic LLMs rely only on public knowledge and cannot adapt to enterprise-specific return policies, membership systems, or pricing rules.

MySQL AI first vectorizes private documents and business rules into the database. When a user asks, it prioritizes matching proprietary fragments from the database, then feeds them to the large model for synthesis. Answers are precise, controllable, traceable — perfect for intelligent customer service and knowledge-base Q&A.

Three Ready-to-Use Practical Examples

The following cases work on MySQL 9.0+, covering both community edition basics and enterprise edition full AI capabilities; code is directly reusable for testing.

Case 1: Create a Business Q&A Table with Vector Column

Build a dedicated knowledge-base table storing business questions, standard answers, and corresponding vectors to support semantic retrieval.

CREATE DATABASE db_shop;
USE db_shop;
CREATE TABLE t_faq (
  id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  question VARCHAR(200) NOT NULL,
  answer TEXT NOT NULL,
  embedding VECTOR(3) NOT NULL
);
INSERT INTO t_faq (question, answer, embedding) VALUES
('怎么退货', '签收后 7 天内可申请退货。', STRING_TO_VECTOR('[0.90, 0.10, 0.05'])),
('运费怎么算', '满 99 元包邮,否则收取 8 元。', STRING_TO_VECTOR('[0.10, 0.85, 0.15'])),
('会员有什么权益', '会员下单享 9 折,生日当月再减 20 元。', STRING_TO_VECTOR('[0.15, 0.10, 0.90']));
SELECT id, question, VECTOR_TO_STRING(embedding) AS embedding_text FROM t_faq;

The two conversion functions enable mutual transformation between vectors and readable strings, making vector storage and query intuitive.

Case 2: Intelligent Q&A via Similarity Matching

Using cosine distance, match user questions against knowledge-base content for precise recall of the best answer; smaller distance means higher semantic match.

SET @q = STRING_TO_VECTOR('[0.88, 0.12, 0.06]');
SELECT id, question, answer, DISTANCE(embedding, @q, 'COSINE') AS score
FROM t_faq
ORDER BY score
LIMIT 2;

Besides cosine, dot product and Euclidean distance are also supported, allowing flexible choice per business scenario.

Case 3: Document Vector Ingestion and RAG Intelligent Q&A

Leverage the built-in model to vectorize text, combine with a private knowledge base for exclusive content Q&A, supporting multi-format document parsing and multi-language adaptation.

-- Text content vectorization
SET @text = '签收后 7 天内可以退货,运费满 99 元包邮。';
SELECT sys.ML_EMBED_ROW(@text, JSON_OBJECT('model_id', 'all_minilm_l12_v2')) INTO @text_embedding;

-- RAG intelligent Q&A call
SET @query = 'What is the return window?';
SET @options = JSON_OBJECT(
  'vector_store', JSON_ARRAY('db_shop.demo_embeddings'),
  'model_options', JSON_OBJECT('language', 'en')
);
CALL sys.ML_RAG(@query, @output, @options);
SELECT JSON_PRETTY(@output);

The final result includes the model's answer and referenced document fragments, ensuring answers are grounded and verifiable. Meanwhile, ML_TRAIN can train classification models on business data for intelligent analytics like user repurchase prediction.

Feasibility Analysis: Is It Production-Ready Now?

For existing MySQL workloads, this AI upgrade fits with high compatibility — no need to refactor the original business architecture.

If pure private deployment and zero data leakage are required, choose MySQL AI Enterprise Edition; runs on CPU, meets local knowledge-base Q&A and prediction needs. For cloud-eligible workloads, choose HeatWave GenAI for stronger performance and richer features.

Both solutions share identical syntax; local development migrates to cloud seamlessly. The community edition only offers basic vector column capabilities; advanced semantic retrieval, RAG Q&A, and ML require Enterprise or cloud editions.

Currently vector columns lack index support; massive-data scenarios need retrieval logic optimization. Validate the flow in test environments first, then iterate for production.

Summary

MySQL is no longer just a traditional transactional database. Through native AI capabilities, it achieves a trinity of structured data storage, semantic intelligent retrieval, and automated machine learning.

Business data stays entirely inside the database; SQL alone enables intelligent Q&A and data prediction, drastically cutting development, deployment, and operational costs of traditional AI applications — representing the core future direction of database intelligence.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

SQLRAGVector DatabaseMySQLHeatWaveAutoMLAI IntegrationDatabase AI
Su San Talks Tech
Written by

Su San Talks Tech

Su San, former staff at several leading tech companies, is a top creator on Juejin and a premium creator on CSDN, and runs the free coding practice site www.susan.net.cn.

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.