A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloud.google.com/sql/docs/mysql/understand-example-embedding-workflow below:

Understand an example of an embedding workflow | Cloud SQL for MySQL

Understand an example of an embedding workflow

Stay organized with collections Save and categorize content based on your preferences.

Preview — Cloud SQL for MySQL integration with Vertex AI

This feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the Service Specific Terms. You can process personal data for this feature as outlined in the Cloud Data Processing Addendum, subject to the obligations and restrictions described in the agreement under which you access Google Cloud. Pre-GA features are available "as is" and might have limited support. For more information, see the launch stage descriptions.

This page provides an example of a workflow that demonstrates how the mysql.ml_embedding() function works with the data that's stored in your tables and the mysql vector query functionality. The example uses plain-text input to fetch a result from a database that relies on large language model (LLM)-driven semantic parsing of the text's meaning.

An example scenario of an embedding workflow

Imagine a database running on Cloud SQL for MySQL with the following aspects:

Even though this database stores complaints about items, these complaints are stored as plain text, making it challenging to query. For example, if you want to see which items have the most complaints from customers who received the wrong color of merchandise, then you can perform ordinary SQL queries on the table, looking for various keyword matches. However, this approach matches only rows that contain those exact keywords.

For example, a basic SQL query such as SELECT * FROM item WHERE complaints LIKE "%wrong color%" doesn't return a row where the complaints field contains only The picture shows a blue one, but the one I received was red.

SQL queries using LLM-powered embeddings can help bridge this gap. By applying embeddings, you can query the table in this example for items where complaints have semantic similarity to a given text prompt, such as "It was the wrong color".

The following steps show how to enable this in the example scenario described earlier.

Prepare the table

Before you run LLM-based queries on the content of the items table, you must prepare the table to store and index embeddings based on your existing data.

Create a column to store embeddings

Add a column to the table to store embeddings.

sql ALTER TABLE items ADD COLUMN complaint_embedding vector(768) using varbinary;

This example specifies 768 as an argument because that's how many dimensions the textembedding-gecko LLM supports. For more information, see Generate an embedding.

The example applies the vector data type to the column to simplify using pgvector functions and operators with the column's values.

Populate the new column

Use the mysql.ml_embedding() function to populate this new column with embeddings based on the value of each row's text that appears in the complaints column. In this example, Cloud SQL generates the embeddings using the LLM with the ID of textembedding-gecko, version 004.

UPDATE items SET complaint_embedding = mysql.ml_embedding('text-embedding-005', complaints);

This example casts the binary return value of

mysql.ml_embedding()

into a

vector

value implicitly to store the value in the

vector

column that you created in

Create a column to store embeddings

.

Create an index

To improve performance, add an index to the items table.

CREATE VECTOR INDEX complaint_embed_idx ON items(complaint_embedding)
  USING SCANN DISTANCE_MEASURE=COSINE;

For more information on creating this type of index, see Create a nearest-neighbor index. Also, for more information on tuning the index by setting parameters, see Query and index embeddings.

Run LLM-powered queries with provided text

You can now make semantic nearest-neighbor queries on the items table. The following query uses the approx_distance function to complete the following actions:

The query displays the id and name values of the first sorted row.

SELECT mysql.ML_EMBEDDING('text-embedding-005', 'It was the wrong color') into @query_vector;

select id, name from items order by approx_distance(complaint_embedding , @query_vector,'distance_measure=cosine') limit 10;
What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-09 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-09 UTC."],[],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4