All Products
Search
Document Center

ApsaraDB RDS:Vector storage

Last Updated:Dec 04, 2025

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 VECTOR data 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_DIM

    Gets the vector dimensions.

    VEC_FROMTEXT

    Converts a string to a vector.

    TO_VECTOR

    STRING_TO_VECTOR

    VEC_TOTEXT

    Converts a vector to a string.

    FROM_VECTOR

    VECTOR_TO_STRING

    VEC_DISTANCE

    Calculates 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_EUCLIDEAN

    VEC_DISTANCE_COSINE

  • High-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: 20251031 or 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 inplace syntax 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 vector type 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

vidx_default_distance

• Description: The default vector distance type.
• Scope: Session.
• Data type: String.
• Default value: EUCLIDEAN.
• Valid values:

  • EUCLIDEAN: Euclidean distance. Calculates the straight-line distance (geometric distance) between two vectors in a multidimensional space.

  • COSINE: Cosine distance. Calculates the cosine of the angle between two vectors to measure directional similarity, ignoring vector length.

vidx_hnsw_default_m

• Description: The default m value for an HNSW index (the maximum number of output nodes for each node in the graph).
• Scope: Session.
• Data type: Integer.
• Default value: 6.
• Value range: [3, 200].

vidx_hnsw_ef_search

• Description: The default ef_search value for HNSW index queries (the search range).
• Scope: Session.
• Data type: Integer.
• Default value: 20.
• Value range: [1, 10000].

vidx_hnsw_cache_size

• Description: The maximum memory that the HNSW index cache can use, in bytes.
• Scope: Global.
• Data type: BigInt.
• Default value: 1048576.
• Value range: [1048576, 18446744073709551615].

Modify parameters

  1. 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.

  2. In the navigation pane on the left, click Parameter.

  3. On the Modifiable Parameters tab, search for the parameter to modify and set its value.

  4. Click OK and then Apply Changes. In the dialog box that appears, select when the changes will take effect.

Note

All vector-related parameters are dynamic parameters. Modifications take effect immediately without an instance restart.

Enable and use the feature

Note

Enabling or disabling the vector feature does not require an instance restart.

Step 1: Enable vector support

  1. Go to the RDS console, select the destination region, and click the instance ID.

  2. On the Basic Information page, in the Status section, find Vector Storage and click Enable.

  3. 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;