MySQL 9.0 Adds Native Vector Support & In-Database AI: RAG, AutoML, Local Deployment
MySQL 9.0 introduces a native VECTOR data type for storing embeddings, while MySQL AI (enterprise) and HeatWave GenAI (cloud) add in-database semantic search, RAG with citations, and AutoML for classification—all accessible via SQL, enabling AI workloads without moving data out of the database.
MySQL Embraces AI: Native Vector Storage and In-Database Intelligence
MySQL, the open-source relational database first released in 1995 and now under Oracle, has long handled structured data—users, orders, inventory—with SQL, transactions, replication, and backups. For years, vector embeddings and generative AI required separate services and data pipelines. In July 2024, MySQL 9.0 added a native VECTOR column type, and Oracle's cloud service HeatWave integrated generative AI directly into the database. For on-premises deployments, the Enterprise Edition offers MySQL AI , a local option that brings the same capabilities to your own hardware.
Three Pillars of MySQL AI Support
The AI features fall into three categories:
Vector columns as first-class citizens. Starting with MySQL 9.0, a table can contain a VECTOR column. A vector is an array of single-precision floats (default 2048 dimensions, max 16383) representing the semantic position of text. Community Edition can create such columns and use STRING_TO_VECTOR() to insert and VECTOR_TO_STRING() to read back. These columns cannot serve as primary keys or regular indexes.
Semantic search and retrieval-augmented generation (RAG) inside the database. The DISTANCE() function computes cosine, dot-product, or Euclidean distance between vectors. Documents (PDF, HTML, TXT, PPT, DOCX) are chunked, embedded, and stored in ordinary MySQL tables. A natural-language question invokes sys.ML_RAG, which retrieves relevant chunks and feeds them to an in-database large language model to produce an answer with citations. Since MySQL 9.5.0 on HeatWave, semantic similarity and keyword matching can be combined in a single query.
In-database predictive machine learning (AutoML). sys.ML_TRAIN builds a classification or regression model on a business table—for example, predicting whether a customer will reorder. Training and inference both run via SQL; data never leaves the database.
The vector column itself is available in Community Edition from 9.0 onward. The in-database LLM, vector store automation, and AutoML require either MySQL AI (Enterprise Edition, on-premises) or HeatWave GenAI (cloud).
Running Entirely On-Premises with MySQL AI
MySQL AI is the Enterprise Edition's local deployment package. It bundles the LLM, vector store, and AutoML, running models on CPU—no GPU required. Documents reside in a local directory (default /var/lib/mysql-files). Loading a PDF into the vector store is a single call:
CALL sys.VECTOR_STORE_LOAD(
'file:///var/lib/mysql-files/demo-directory/return-policy.pdf',
@options
);Subsequent queries use the same routines— ML_EMBED_ROW, ML_RAG, ML_TRAIN —as the cloud version. Applications developed locally can later migrate to HeatWave without code changes; only the document path switches from file:// to an object-storage reference. MySQL AI currently supports Oracle Linux 8 and RHEL 8, requires an Enterprise license, and Oracle recommends a minimum of 32 logical CPUs, 128 GB RAM, and 512 GB disk. Community Edition is suitable for learning the VECTOR type and basic distance calculations.
From Question to Answer: The RAG Flow
Consider a shop's return-policy PDF. The LLM has seen public data but not this specific document. The flow is:
Ingest the PDF: chunk, embed, store vectors in a MySQL table.
User asks: "How many days for a return?"
The system embeds the question, finds the nearest vectors via DISTANCE(), retrieves the corresponding text chunks.
Those chunks are passed to the in-database LLM, which generates an answer grounded in the retrieved text and includes citations.
This ensures answers follow the shop's actual policy and allows verification against the source segments.
Three Hands-On Examples
The following examples use 3-dimensional vectors for readability; real embeddings have hundreds of dimensions and must use the same model for both documents and queries.
1. Create a Q&A Table with a Vector Column
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; STRING_TO_VECTOR()parses a bracketed string; VECTOR_TO_STRING() reverses it. TO_VECTOR() and FROM_VECTOR() are synonyms.
2. Find the Closest Answer Using Cosine Distance
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;The third argument can be 'DOT' or 'EUCLIDEAN'. Smaller scores indicate closer matches.
3. Let the Database Answer from Documents (RAG)
In MySQL AI or HeatWave, embed a single sentence:
SET @text = '签收后 7 天内可以退货,运费满 99 元包邮。';
SELECT sys.ML_EMBED_ROW(@text, JSON_OBJECT('model_id', 'all_minilm_l12_v2'))
INTO @text_embedding;For full-table embedding use sys.ML_EMBED_TABLE. PDFs are loaded via sys.VECTOR_STORE_LOAD (local file:// path or cloud object storage). Querying:
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 returned JSON contains text (the generated answer) and citations (referenced chunks with distances). The language parameter uses two-letter codes (default en); Chinese knowledge bases require checking the version's supported language list. Since MySQL 9.2.1, retrieval matches the embedding model used for the vector store, so questions and documents must share the same model.
AutoML Example: Predicting Repeat Purchases
CALL sys.ML_TRAIN(
'db_shop.t_order',
'will_buy_again',
JSON_OBJECT('task', 'classification'),
@model
);RAG answers "find similar passages then generate"; AutoML learns a classifier from historical data. Both are invoked via SQL but solve different problems.
Is It Production-Ready Today?
If you already use MySQL and want customer-service, policy, or product documentation queryable via natural language:
For fully local execution, choose Enterprise Edition's MySQL AI (CPU-based).
If cloud is acceptable, use HeatWave GenAI.
The SQL routines are identical, so a local prototype can move to HeatWave later for better performance and richer features. Business data stays in MySQL; SQL remains the entry point.
Community Edition users can start experimenting with the VECTOR type and DISTANCE() using the first example. However, vector columns lack indexes; at scale, recall strategies and dimension choices must follow official guidelines. These examples demonstrate the workflow; production deployment requires re-engineering for data volume and latency requirements.
MySQL remains the transactional database for orders and inventory. The change is that semantic search, cited answer generation, and predictive modeling can now begin from the same SQL session.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
java1234
Former senior programmer at a Fortune Global 500 company, dedicated to sharing Java expertise. Visit Feng's site: Java Knowledge Sharing, www.java1234.com
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
