USING SCANN: Obligatorio. Es el tipo de índice que se usará cuando se cree el índice de vectores. Este algoritmo crea un índice de ScaNN.
SCANN es el único valor admitido. No puedes modificar este parámetro.
QUANTIZER: Opcional. Este parámetro asigna un vector de alta dimensión a una representación comprimida. SQ8 es el único valor admitido. No puedes modificar este parámetro.
NUM_LEAVES: Opcional. Especifica cuántas particiones (hojas) se deben crear.
Solo cambia este parámetro de configuración de su valor predeterminado si comprendes bien la búsqueda de ANN y tu conjunto de datos. El número especificado no puede ser mayor que la cantidad de incorporaciones en la tabla base.
DISTANCE_MEASURE: Obligatorio. Es una fórmula matemática que calcula la similitud de dos vectores. Debes establecer la misma medida de distancia en este parámetro que la distancia en las opciones de búsqueda de approx_distance. Los laterales admitidos son los siguientes:
L2_SQUARED
COSINE
DOT_PRODUCT
Ejemplo
En el siguiente ejemplo, se muestra cómo crear un índice vectorial en la tabla table_name.
Agrega un índice de vectores a una tabla existente. Las búsquedas de vectores requieren SCANN como opción de índice, y el tipo de cuantificación debe ser SQ8.
USING SCANN: Obligatorio. Es el tipo de índice que se usará cuando se cree el índice de vectores. Este algoritmo crea un índice de ScaNN.
SCANN es el único valor admitido. No puedes modificar este parámetro.
QUANTIZER: Opcional. Este parámetro asigna un vector de alta dimensión a una representación comprimida. SQ8 es el único valor admitido. No puedes modificar este parámetro.
NUM_LEAVES: Opcional. Especifica cuántas particiones (hojas) se deben crear.
Solo cambia este parámetro de configuración de su valor predeterminado si comprendes bien la búsqueda de ANN y tu conjunto de datos. El número especificado no puede ser mayor que la cantidad de incorporaciones en la tabla base.
DISTANCE_MEASURE: Obligatorio. Es una fórmula matemática que calcula la similitud de dos vectores. Debes establecer la misma medida de distancia en este parámetro que la distancia en las opciones de búsqueda de approx_distance. Los laterales admitidos son los siguientes:
L2_SQUARED
COSINE
DOT_PRODUCT
Ejemplo
En el siguiente ejemplo, se muestra cómo agregar un índice vectorial en la tabla t1.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (UTC)"],[],[],null,["# Cloud SQL Data Definition Language (DDL)\n\n\u003cbr /\u003e\n\nMySQL \\| PostgreSQL \\| SQL Server\n\n\u003cbr /\u003e\n\nThis page defines the syntax for Cloud SQL extensions to the MySQL data\ndefinition language (DDL) statements.\n\nVECTOR statements\n-----------------\n\nThis section has information about `VECTOR` statements.\n\n### CREATE VECTOR INDEX\n\nCreates a vector index. \n\n CREATE VECTOR INDEX index_name\n [opt_index_type]\n ON table_name (column_name)\n [index_options]\n\n where opt_index_type is:\n | USING SCANN\n\n where index_option is :\n USING SCANN\n | [QUANTIZER=SQ8]\n | [NUM_LEAVES=int_value]\n | DISTANCE_MEASURE=L2_SQUARED|DOT_PRODUCT|COSINE\n\n**Parameters**\n\n- **`USING SCANN`** : required. The index type to use when creating the vector index. This algorithm creates a [ScaNN\n index](https://research.google/blog/announcing-scann-efficient-vector-similarity-search/). `SCANN` is the only supported value. You can't modify this parameter.\n- **`QUANTIZER`** : optional. This parameter maps a high-dimensional vector to a compressed representation. `SQ8` is the only supported value. You can't modify this parameter.\n- **`NUM_LEAVES`**: optional. Specifies how many partitions (leaves) to build. Only change this setting from its default setting if you have a good understanding of ANN search and your dataset. The number specified can't be larger than the number of embeddings in the base table.\n- **`DISTANCE_MEASURE`** : required. A mathematical formula that calculates the similarity of two vectors. You must set the same distance measure in this parameter as the distance in the `approx_distance` search options. The supported laterals are:\n - `L2_SQUARED`\n - `COSINE`\n - `DOT_PRODUCT`\n\n**Example**\n\nThe following example shows how to create a vector index on the `table_name`\ntable \n\n CREATE\n VECTOR INDEX index1\n ON table_name(vector_column_name)\n USING SCANN QUANTIZER = SQ8 DISTANCE_MEASURE = l2_squared;\n\n### ALTER TABLE\n\nAdds a vector index to an existing table. Vector searches require `SCANN`\nas the index option and the quantization type must\nbe `SQ8`. \n\n ALTER TABLE table_name\n ADD VECTOR INDEX index_name(key_part)[index_option];\n\n WHERE key_part is:{ _col_name_[(_length_)] | (_expr_) }\n WHERE\n index_option\n is:USING\n SCANN\n | [QUANTIZER = SQ8]\n | [NUM_LEAVES = int_value]\n | DISTANCE_MEASURE\n = L2_SQUARED | DOT_PRODUCT | COSINE\n\n**Parameters**\n\n- **`USING SCANN`** : required. The index type to use when creating the vector index. This algorithm creates a [ScaNN\n index](https://research.google/blog/announcing-scann-efficient-vector-similarity-search/). `SCANN` is the only supported value. You can't modify this parameter.\n- **`QUANTIZER`** : optional. This parameter maps a high-dimensional vector to a compressed representation. `SQ8` is the only supported value. You can't modify this parameter.\n- **`NUM_LEAVES`**: optional. Specifies how many partitions (leaves) to build. Only change this setting from its default setting if you have a good understanding of ANN search and your dataset. The number specified can't be larger than the number of embeddings in the base table.\n- **`DISTANCE_MEASURE`** : required. A mathematical formula that calculates the similarity of two vectors. You must set the same distance measure in this parameter as the distance in the `approx_distance` search options. The supported laterals are:\n - `L2_SQUARED`\n - `COSINE`\n - `DOT_PRODUCT`\n\n**Example**\n\nThe following example shows how to add a vector index on the `t1` table. \n\n ALTER TABLE t1 ADD VECTOR INDEX index1(j)\n USING SCANN QUANTIZER = SQ8 DISTANCE_MEASURE = l2_squared;\n\nWhat's next\n-----------\n\n- Read the [overview about vector search on Cloud SQL](/sql/docs/mysql/vector-search).\n- Learn how to [enable and disable vector embeddings on your instance](/sql/docs/mysql/enable-vector-search).\n- Learn how to [generate vector embeddings](/sql/docs/mysql/generate-manage-vector-embeddings#generate_vector_embeddings_based_on_row_data).\n- Learn how to [create vector indexes](/sql/docs/mysql/create-manage-vector-indexes).\n- Learn how to [perform searches on vector embeddings](/sql/docs/mysql/search-filter-vector-embeddings)."]]