Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
MySQL | PostgreSQL | SQL Server
Auf dieser Seite wird die Syntax für Cloud SQL-Erweiterungen der DDL-Anweisungen (Data Definition Language, Datendefinitionssprache) für MySQL definiert.
VECTOR-Anweisungen
Dieser Abschnitt enthält Informationen zu VECTOR-Anweisungen.
USING SCANN: erforderlich. Der Index-Typ, der beim Erstellen des Vektorindex verwendet werden soll. Mit diesem Algorithmus wird ein ScaNN-Index erstellt.
SCANN ist der einzige unterstützte Wert. Dieser Parameter kann nicht geändert werden.
QUANTIZER: Optional. Dieser Parameter bildet einen hochdimensionalen Vektor auf eine komprimierte Darstellung ab. SQ8 ist der einzige unterstützte Wert. Sie können diesen Parameter nicht ändern.
NUM_LEAVES: Optional. Gibt an, wie viele Partitionen (Blätter) erstellt werden sollen.
Ändern Sie diese Einstellung nur, wenn Sie sich gut mit der ANN-Suche und Ihrem Dataset auskennen. Die angegebene Zahl darf nicht größer sein als die Anzahl der Einbettungen in der Basistabelle.
DISTANCE_MEASURE: erforderlich. Eine mathematische Formel, mit der die Ähnlichkeit zweier Vektoren berechnet wird. Sie müssen in diesem Parameter dasselbe Distanzmaß festlegen wie die Distanz in den approx_distance-Suchoptionen. Folgende Laterale werden unterstützt:
L2_SQUARED
COSINE
DOT_PRODUCT
Beispiel
Im folgenden Beispiel wird gezeigt, wie Sie einen Vektorindex für die Tabelle table_name erstellen.
Fügt einer vorhandenen Tabelle einen Vektorindex hinzu. Für Vektorsuchen ist SCANN als Indexoption erforderlich und der Quantisierungstyp muss SQ8 sein.
USING SCANN: erforderlich. Der Index-Typ, der beim Erstellen des Vektorindex verwendet werden soll. Mit diesem Algorithmus wird ein ScaNN-Index erstellt.
SCANN ist der einzige unterstützte Wert. Dieser Parameter kann nicht geändert werden.
QUANTIZER: Optional. Dieser Parameter bildet einen hochdimensionalen Vektor auf eine komprimierte Darstellung ab. SQ8 ist der einzige unterstützte Wert. Sie können diesen Parameter nicht ändern.
NUM_LEAVES: Optional. Gibt an, wie viele Partitionen (Blätter) erstellt werden sollen.
Ändern Sie diese Einstellung nur, wenn Sie sich gut mit der ANN-Suche und Ihrem Dataset auskennen. Die angegebene Zahl darf nicht größer sein als die Anzahl der Einbettungen in der Basistabelle.
DISTANCE_MEASURE: erforderlich. Eine mathematische Formel, mit der die Ähnlichkeit zweier Vektoren berechnet wird. Sie müssen in diesem Parameter dasselbe Distanzmaß festlegen wie die Distanz in den approx_distance-Suchoptionen. Folgende Laterale werden unterstützt:
L2_SQUARED
COSINE
DOT_PRODUCT
Beispiel
Im folgenden Beispiel wird gezeigt, wie Sie der Tabelle t1 einen Vektorindex hinzufügen.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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)."]]