RDS for MySQL provides enterprise-grade vector data processing capabilities. It natively supports the storage and computation of vector data with up to 16,383 dimensions, includes mainstream vector operation functions, and uses a highly optimized Hierarchical Navigable Small World (HNSW) algorithm for efficient nearest neighbor searches. You can create indexes on full-dimension vector columns.
Features
RDS for MySQL natively supports vector data processing, including vector storage, similarity calculations, and high-performance index creation. It provides ready-to-use vector solutions for scenarios such as large-scale semantic retrieval, Artificial Intelligence Recommendation, and multi-modal analysis. You can use standard SQL interfaces to seamlessly combine high-precision vector matching with complex business logic. This lets you quickly deploy innovative AI applications using a low-cost and highly compatible architecture.
Efficient storage, access, and computation of high-dimensional vectors: You can store floating-point vector data with up to 16,383 dimensions using the
VECTORdata type. This feature is compatible with standard SQL interfaces, which lets you directly write, update, and manage vectorized data in batches. The supported mainstream vector processing functions are as follows:Function name
Description
VECTOR_DIMGets the vector dimensions.
VEC_FROMTEXTConverts a string to a vector.
TO_VECTORSTRING_TO_VECTORVEC_TOTEXTConverts a vector to a string.
FROM_VECTORVECTOR_TO_STRINGVEC_DISTANCECalculates the distance between two vectors. If one of the parameters is an index column, the distance type of the index is automatically detected.
VEC_DISTANCE_EUCLIDEANVEC_DISTANCE_COSINEHigh-performance vector index: Vector indexes are built using a highly optimized HNSW algorithm. Technologies such as single instruction multiple data (SIMD) hardware acceleration, Bloom filter search pruning, and LIMIT condition pushdown significantly improve the retrieval efficiency of large-scale vector data. This feature also supports mixed storage and joint queries of vector and scalar data.
Open ecosystem, ready to use: This feature is fully compatible with the MySQL protocol. It supports Java Database Connectivity (JDBC)/ORM tools and mainstream developer frameworks. It integrates with Alibaba Cloud services such as DTS and DMS to provide full lifecycle capabilities, including data synchronization, management, backup, and recovery. You can upgrade existing instances with one click without creating a new cluster.
Usage scope
Database version: MySQL 8.0.
Minor engine version:
20251031or later. If your instance does not meet this version requirement, upgrade the minor engine version or the major database version.The following limitations apply to this feature:
Vector indexes can be created only on tables that use the InnoDB engine.
The primary key of the table cannot exceed 256 bytes in length.
The
inplacesyntax cannot be used to create, modify, or delete vector indexes.Vector indexes cannot be set to
INVISIBLE.Tables that contain vector indexes do not support the Recycle Bin feature.
Data modification and queries on vector indexes support only the Read Committed (RC) isolation level.
Because of the randomness of the HNSW algorithm, which includes random levels and heuristic algorithms, the graph structures of vector indexes on the primary and standby instances are not guaranteed to be identical.
If you use the
vectortype in stored procedures or functions in the source database, synchronization or migration to a destination database that does not support vectors will fail.
Parameter management
Parameter description
Parameter name | Description |
| • Description: The default vector distance type.
|
| • Description: The default m value for an HNSW index (the maximum number of output nodes for each node in the graph). |
| • Description: The default ef_search value for HNSW index queries (the search range). |
| • Description: The maximum memory that the HNSW index cache can use, in bytes. |
Modify parameters
Go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the ID of the instance.
In the navigation pane on the left, click Parameter.
On the Modifiable Parameters tab, search for the parameter to modify and set its value.
Click OK and then Apply Changes. In the dialog box that appears, select when the changes will take effect.
All vector-related parameters are dynamic parameters. Modifications take effect immediately without an instance restart.
Enable and use the feature
Enabling or disabling the vector feature does not require an instance restart.
Step 1: Enable vector support
Go to the RDS console, select the destination region, and click the instance ID.
On the Basic Information page, in the Status section, find Vector Storage and click Enable.
The feature takes effect immediately after the status changes to Enabled.
Step 2: Create a table and a vector index
-- Create a table that contains a 5-dimension vector column and an HNSW index
CREATE TABLE product_embeddings (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
product_name VARCHAR(255),
embedding VECTOR(5) NOT NULL,
-- Create a vector index and specify the M value and distance calculation method
VECTOR INDEX idx_embedding(embedding) M=16 DISTANCE=COSINE
);Step 3: Insert data
-- Use the VEC_FROMTEXT function to insert vector data
INSERT INTO product_embeddings (product_name, embedding) VALUES
('product_A', VEC_FROMTEXT('[0.1, 0.2, 0.3, 0.4, 0.5]')),
('product_B', VEC_FROMTEXT('[0.6, 0.7, 0.8, 0.9, 1.0]')),
('product_C', VEC_FROMTEXT('[0.11, 0.22, 0.33, 0.44, 0.55]'));Step 4: Perform a vector similarity query
-- Find the two products most similar to the given vector '[0.1, 0.2, 0.3, 0.4, 0.51]'
SELECT
id,
product_name,
VEC_DISTANCE(embedding, VEC_FROMTEXT('[0.1, 0.2, 0.3, 0.4, 0.51]')) AS similarity_score
FROM
product_embeddings
ORDER BY
similarity_score ASC -- The smaller the COSINE distance, the more similar the vectors are
LIMIT 2;