Cloud SQL for PostgreSQL:向量嵌入使用入门

1. 简介

在此 Codelab 中,您将学习如何通过将向量搜索与 Gemini Enterprise Agent Platform 嵌入相结合来使用 Cloud SQL for PostgreSQL AI 集成。

架构图:显示了 Cloud SQL 与 Gemini Enterprise Agent Platform 的集成

前提条件

  • 对 Google Cloud 和 Google Cloud 控制台有基本的了解
  • 具备命令行界面和 Cloud Shell 方面的基本经验

您将执行的操作

所需条件

  • Google Cloud 账号和 Google Cloud 项目
  • 网络浏览器,例如 Chrome

2. 设置和要求

项目设置

  1. 登录 Google Cloud 控制台。如果您还没有 Google 账号(Gmail 或 Google Workspace),则必须创建一个 Google 账号。

请改用个人账号,而不是工作账号或学校账号。

  1. 创建新项目或重复使用现有项目。如需在 Google Cloud 控制台中创建新项目,请点击工具栏中的选择项目。

Google Cloud 控制台中的“选择项目”对话框

在选择项目对话框中,点击新项目。

37d264871000675d.png

在对话框中,输入项目名称并选择位置。

96d86d3d5655cdbe.png

  • 项目名称是此项目参与者的显示名称。Google API 不会使用项目名称,并且您可以随时更改项目名称。
  • 项目 ID 在所有 Google Cloud 项目中是唯一的,并且是不可变的(一经设置便无法更改)。Google Cloud 控制台会自动生成唯一 ID,但您可以自定义该 ID。如果您不喜欢生成的 ID,可以生成另一个随机 ID,也可以提供自己的 ID 来检查其可用性。在大多数 Codelab 中,您都需要引用项目 ID,该 ID 通常用 占位符标识。
  • 第三个值是项目编号,一些 API 会使用该值。如需详细了解所有这三个值,请参阅创建和管理项目文档。

启用结算功能

设置个人结算账号

如果您使用 Google Cloud 赠金设置了结算,则可以跳过此步骤。

如需设置个人结算账号,请在 Google Cloud Billing 控制台中启用结算功能。

注意:

  • 完成本实验所用的 Google Cloud 资源费用不到 5 美元。
  • 请按照本实验结束时的步骤删除资源,以免产生进一步的费用。
  • 新用户符合参与 300 美元免费试用计划的条件。

启动 Cloud Shell

虽然您可以从计算机远程操作 Google Cloud,但在此 Codelab 中,您将使用 Google Cloud Shell,这是一个在云端运行的命令行环境。

在 Google Cloud 控制台工具栏中,点击激活 Cloud Shell:

激活 Cloud Shell

或者,您也可以在 Google Cloud 控制台中按 g 键,然后按 s 键,或打开 Cloud Shell。

预配并连接到环境只需片刻时间。完成后,您应该会看到已连接的终端:

Google Cloud Shell 终端的屏幕截图,显示环境已连接

此虚拟机已加载您需要的所有开发工具。它提供了一个持久的 5 GB 主目录,并且在 Google Cloud 中运行,从而增强了网络性能和身份验证功能。您在此 Codelab 中的所有工作都可以在浏览器中完成。

3. 启用 API

如需使用 Cloud SQL、Compute Engine、Service Networking 和 Gemini Enterprise Agent Platform,请在您的 Google Cloud 项目中启用它们各自的 API。

在 Cloud Shell 终端中,确保项目 ID 已设置:

gcloud config set project <PROJECT_ID>

设置 PROJECT_ID 环境变量:

PROJECT_ID=$(gcloud config get-value project)

启用所有必需的服务:

gcloud services enable sqladmin.googleapis.com \
                       compute.googleapis.com \
                       cloudresourcemanager.googleapis.com \
                       servicenetworking.googleapis.com \
                       aiplatform.googleapis.com

预期输出:

student@cloudshell:~ (test-project-001-402417)$ gcloud config set project test-project-001-402417
Updated property [core/project].
student@cloudshell:~ (test-project-001-402417)$ PROJECT_ID=$(gcloud config get-value project)
Your active configuration is: [cloudshell-14650]
student@cloudshell:~ (test-project-001-402417)$ 
student@cloudshell:~ (test-project-001-402417)$ gcloud services enable sqladmin.googleapis.com \
                       compute.googleapis.com \
                       cloudresourcemanager.googleapis.com \
                       servicenetworking.googleapis.com \
                       aiplatform.googleapis.com
Operation "operations/acat.p2-4470404856-1f44ebd8-894e-4356-bea7-b84165a57442" finished successfully.

您可以在文档中了解每个已启用的 API。

4. 创建 Cloud SQL 实例

创建与 Gemini Enterprise Agent Platform 数据库集成的 Cloud SQL 实例。

创建数据库密码

为默认数据库用户定义密码。您可以自行定义密码,也可以使用随机函数生成密码:

export CLOUDSQL_PASSWORD=$(openssl rand -hex 16)

显示生成的密码值:

echo $CLOUDSQL_PASSWORD

记下生成的密码,以便稍后使用。

创建 Cloud SQL for PostgreSQL 实例

您可以使用多种方法创建 Cloud SQL 实例,包括 Google Cloud 控制台、Terraform 或 Google Cloud CLI (gcloud)。在此 Codelab 中,您将使用 gcloud。如需了解如何使用其他工具创建实例,请参阅创建实例文档。

在 Cloud Shell 中,运行以下命令以创建实例:

gcloud sql instances create my-cloudsql-instance \
--database-version=POSTGRES_18 \
--tier=db-custom-1-3840 \
--region=us-central1 \
--edition=ENTERPRISE \
--enable-google-ml-integration \
--database-flags cloudsql.enable_google_ml_integration=on

创建实例后,为默认用户 (postgres) 设置密码,并验证您是否可以连接:

gcloud sql users set-password postgres \
    --instance=my-cloudsql-instance \
    --password=$CLOUDSQL_PASSWORD

使用 gcloud sql connect 连接到实例。当系统提示时,输入密码:

gcloud sql connect my-cloudsql-instance --user=postgres

按 Ctrl+D 或输入 exit 退出 psql 会话:

exit

启用 Gemini Enterprise Agent Platform 集成

向 Cloud SQL 服务账号授予必要的 IAM 角色,以启用 Gemini Enterprise Agent Platform 集成。

检索 Cloud SQL 服务账号电子邮件地址,并将其导出为环境变量:

SERVICE_ACCOUNT_EMAIL=$(gcloud sql instances describe my-cloudsql-instance --format="value(serviceAccountEmailAddress)")
echo $SERVICE_ACCOUNT_EMAIL

将 roles/aiplatform.user 角色授予 Cloud SQL 服务账号:

PROJECT_ID=$(gcloud config get-value project)
gcloud projects add-iam-policy-binding $PROJECT_ID \
  --member="serviceAccount:$SERVICE_ACCOUNT_EMAIL" \
  --role="roles/aiplatform.user"

如需详细了解实例创建和配置,请参阅将 Cloud SQL 与 Gemini Enterprise Agent Platform 集成。

5. 准备数据库

创建数据库并启用向量支持。

创建数据库

创建一个名为 quickstart_db 的数据库。 您可以使用数据库客户端(例如 psql)、Google Cloud CLI 或 Cloud SQL Studio 创建数据库。在此步骤中,请使用 gcloud。

在 Cloud Shell 中,运行以下命令以创建数据库:

gcloud sql databases create quickstart_db --instance=my-cloudsql-instance

启用扩展程序

如需使用 Gemini Enterprise Agent Platform 和矢量,请在 quickstart_db 数据库中启用两个扩展程序:google_ml_integration 和 vector。

在 Cloud Shell 中,连接到数据库:

gcloud sql connect my-cloudsql-instance --database quickstart_db --user=postgres

当系统提示时,输入您的数据库密码。

在 SQL 会话中,运行以下命令:

CREATE EXTENSION IF NOT EXISTS google_ml_integration CASCADE;
CREATE EXTENSION IF NOT EXISTS vector CASCADE;

退出 SQL 会话:

exit;

6. 加载数据

在数据库中创建表,并使用以 CSV 格式存储在公共 Cloud Storage 存储桶中的虚构 Cymbal Store 数据集文件加载数据。

首先,创建所需的架构对象。运行 gcloud sql connect 和 gcloud storage 以下载并导入架构:

在 Cloud Shell 中,运行以下命令(系统提示时,输入为实例创建的密码):

gcloud storage cat gs://cloud-training/gcc/gcc-tech-004/cymbal_demo_schema.sql | gcloud sql connect my-cloudsql-instance --database quickstart_db --user=postgres

此命令会连接到数据库并执行下载的 SQL 代码,以创建表、索引和序列。

接下来,从 Cloud Storage 下载 CSV 数据文件:

gcloud storage cp gs://cloud-training/gcc/gcc-tech-004/cymbal_products.csv .
gcloud storage cp gs://cloud-training/gcc/gcc-tech-004/cymbal_inventory.csv .
gcloud storage cp gs://cloud-training/gcc/gcc-tech-004/cymbal_stores.csv .

连接到数据库:

gcloud sql connect my-cloudsql-instance --database quickstart_db --user=postgres

从 CSV 文件导入数据:

\copy cymbal_products from 'cymbal_products.csv' csv header
\copy cymbal_inventory from 'cymbal_inventory.csv' csv header
\copy cymbal_stores from 'cymbal_stores.csv' csv header

如果您使用自己的数据,并且 CSV 文件与 Google Cloud 控制台中的 Cloud SQL 导入工具兼容,则可以使用控制台而不是命令行。

7. 创建嵌入

使用 Gemini Enterprise Agent Platform 中的 text-embedding-005 模型为产品说明构建嵌入,并将其存储为向量数据。

如果您的会话已断开连接,请连接到数据库:

gcloud sql connect my-cloudsql-instance --database quickstart_db --user=postgres

使用 embedding 函数在 cymbal_products 表中创建一个名为 embedding 的生成列。此命令会创建一个存储的生成列,用于存储根据表中所有行的 product_description 列生成的向量嵌入。模型指定为第一个参数,源文本列指定为第二个参数:

ALTER TABLE cymbal_products ADD COLUMN embedding vector(768) GENERATED ALWAYS AS (google_ml.embedding('text-embedding-005', product_description)) STORED;

对于 900 到 1000 行,此过程通常需要 1 到 5 分钟。

当您向表中插入新行或更新现有行的 product_description 时,embedding 列会自动更新。

8. 运行相似度搜索

通过比较为商品描述计算的向量嵌入与搜索查询的嵌入,运行相似度搜索。

您可以使用 gcloud sql connect 从命令行运行 SQL 查询,也可以从 Cloud SQL Studio 运行 SQL 查询。Cloud SQL Studio 提供了一种更便捷的方式来编辑和执行输出中包含多行的长 SQL 语句。

启动 Cloud SQL Studio

  1. 在 Google Cloud 控制台中,前往 Cloud SQL 实例,然后点击 my-cloudsql-instance。

Google Cloud 控制台中的 Cloud SQL 实例列表

  1. 在导航菜单中,点击 Cloud SQL Studio。

Cloud SQL Studio 菜单项

  1. 在身份验证对话框中,输入数据库名称和凭据:
    • 数据库:quickstart_db
    • 用户:postgres
    • 密码:
  2. 点击身份验证。

Cloud SQL Studio 身份验证对话框

  1. 点击编辑器标签页,打开 SQL 编辑器。

Cloud SQL Studio SQL 编辑器标签页

运行查询

运行查询,以检索与客户查询“What kind of fruit trees grow well here?”(哪些果树在这里长得好?)最相关的 10 种商品。

SELECT
        cp.product_name,
        left(cp.product_description,80) as description,
        cp.sale_price,
        cs.zip_code,
        (cp.embedding <=> embedding('text-embedding-005','What kind of fruit trees grow well here?')::vector) as distance
FROM
        cymbal_products cp
JOIN cymbal_inventory ci on
        ci.uniq_id=cp.uniq_id
JOIN cymbal_stores cs on
        cs.store_id=ci.store_id
        AND ci.inventory>0
        AND cs.store_id = 1583
ORDER BY
        distance ASC
LIMIT 10;

在 Cloud SQL Studio 中,输入查询,然后点击运行(或在 psql 会话中运行查询):

在 Cloud SQL Studio 中运行 SQL 查询

该查询会返回按余弦距离排序的匹配商品:

product_name       |                                   description                                    | sale_price | zip_code |      distance       
-------------------------+----------------------------------------------------------------------------------+------------+----------+---------------------
 Cherry Tree             | This is a beautiful cherry tree that will produce delicious cherries. It is an d |      75.00 |    93230 | 0.43922018972266397
 Meyer Lemon Tree        | Meyer Lemon trees are California's favorite lemon tree! Grow your own lemons by  |         34 |    93230 |  0.4685112926118228
 Toyon                   | This is a beautiful toyon tree that can grow to be over 20 feet tall. It is an e |      10.00 |    93230 |  0.4835677149651668
 California Lilac        | This is a beautiful lilac tree that can grow to be over 10 feet tall. It is an d |       5.00 |    93230 |  0.4947204525907498
 California Peppertree   | This is a beautiful peppertree that can grow to be over 30 feet tall. It is an e |      25.00 |    93230 |  0.5054166905547247
 California Black Walnut | This is a beautiful walnut tree that can grow to be over 80 feet tall. It is a d |     100.00 |    93230 |  0.5084219510932597
 California Sycamore     | This is a beautiful sycamore tree that can grow to be over 100 feet tall. It is  |     300.00 |    93230 |  0.5140519790508755
 Coast Live Oak          | This is a beautiful oak tree that can grow to be over 100 feet tall. It is an ev |     500.00 |    93230 |  0.5143126438081371
 Fremont Cottonwood      | This is a beautiful cottonwood tree that can grow to be over 100 feet tall. It i |     200.00 |    93230 |  0.5174774727252058
 Madrone                 | This is a beautiful madrona tree that can grow to be over 80 feet tall. It is an |      50.00 |    93230 |  0.5227400803389093
(10 rows)

9. 使用检索到的数据改进 LLM 回答

通过在提示中将查询结果作为接地背景信息传递给 Gemini Enterprise Agent Platform 基础语言模型,改进对客户端应用的生成式 AI 回答。

要实现这一目标,需要完成以下步骤:

  1. 根据 Cloud SQL 中的向量搜索结果生成 JSON 载荷。
  2. 在 Agent Platform Studio 中测试提示。
  3. 使用 google_ml 集成直接从 SQL 执行端到端提示。

以 JSON 格式生成输出

修改查询,将结果格式设置为 JSON 并返回一行:

WITH trees as (
SELECT
        cp.product_name,
        left(cp.product_description,80) as description,
        cp.sale_price,
        cs.zip_code,
        cp.uniq_id as product_id
FROM
        cymbal_products cp
JOIN cymbal_inventory ci on
        ci.uniq_id=cp.uniq_id
JOIN cymbal_stores cs on
        cs.store_id=ci.store_id
        AND ci.inventory>0
        AND cs.store_id = 1583
ORDER BY
        (cp.embedding <=> embedding('text-embedding-005','What kind of fruit trees grow well here?')::vector) ASC
LIMIT 1)
SELECT json_agg(trees) FROM trees;

预期 JSON 输出:

[{"product_name":"Cherry Tree","description":"This is a beautiful cherry tree that will produce delicious cherries. It is an d","sale_price":75.00,"zip_code":93230,"product_id":"d536e9e823296a2eba198e52dd23e712"}]

在 Agent Platform Studio 中运行提示

在 Agent Platform Studio 中,将生成的 JSON 作为提示中的上下文提供给生成式模型。

  1. 在 Google Cloud 控制台中,打开 Agent Platform Studio。

Agent Platform Studio 导航

  1. 在 Agent Platform Studio 中输入以下提示:

在 Agent Platform Studio 中输入提示

You are a friendly advisor helping to find a product based on the customer's needs.
Based on the client request we have loaded a list of products closely related to search.
The list in JSON format with list of values like {"product_name":"name","description":"some description","sale_price":10,"zip_code": 10234, "product_id": "02056727942aeb714dc9a2313654e1b0"}
Here is the list of products:
<JSON_OUTPUT>
The customer asked "What tree is growing the best here?"
You should give information about the product, price and some supplemental information.
Do not ask any additional questions and assume location based on the zip code provided in the list of products.

将 替换为查询返回的 JSON 响应:

You are a friendly advisor helping to find a product based on the customer's needs.
Based on the client request we have loaded a list of products closely related to search.
The list in JSON format with list of values like {"product_name":"name","description":"some description","sale_price":10,"zip_code": 10234, "product_id": "02056727942aeb714dc9a2313654e1b0"}
Here is the list of products:
[{"product_name":"Cherry Tree","description":"This is a beautiful cherry tree that will produce delicious cherries. It is an d","sale_price":75.00,"zip_code":93230,"product_id":"d536e9e823296a2eba198e52dd23e712"}]
The customer asked "What tree is growing the best here?"
You should give information about the product, price and some supplemental information.
Do not ask any additional questions and assume location based on the zip code provided in the list of products.

Agent Platform Studio 中的提示

  1. 运行提示。

Agent Platform Studio 中的提示结果

答案包含价格、说明以及模型根据树木和位置信息从外部来源获取的补充信息。

在 psql 中运行提示

您还可以将 Cloud SQL AI 集成与 Gemini Enterprise Agent Platform 搭配使用,直接在 SQL 中获取生成式模型的回答。首先,注册模型。

  1. 如有必要,请将扩展程序升级到 1.4.3 版或更高版本。连接到 quickstart_db 并运行:
SELECT extversion from pg_extension where extname='google_ml_integration';

如果返回的版本低于 1.4.3,请运行:

ALTER EXTENSION google_ml_integration UPDATE TO '1.4.3';
  1. 检查 google_ml_integration.enable_model_support 数据库标志:
SHOW google_ml_integration.enable_model_support;

如果标志为 off,请在 Cloud Shell 中更新数据库标志:

gcloud sql instances patch my-cloudsql-instance \
--database-flags google_ml_integration.enable_model_support=on,cloudsql.enable_google_ml_integration=on

此操作需要 1 到 3 分钟。再次验证设置:

SHOW google_ml_integration.enable_model_support;
  1. 注册 gemini-3.5-flash 模型以生成回答(将 替换为您的项目 ID):
CALL
  google_ml.create_model(
    model_id => 'gemini-3.5-flash',
    model_request_url => 'https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/global/publishers/google/models/gemini-3.5-flash:generateContent',
    model_provider => 'google',
    model_auth_type => 'cloudsql_service_agent_iam');

验证已注册的模型:

SELECT model_id, model_type FROM google_ml.model_info_view WHERE model_id='gemini-3.5-flash';
  1. 运行完整的 SQL 查询以检索向量搜索结果,并将其直接传递给 gemini-3.5-flash:
WITH trees AS (
SELECT
        cp.product_name,
        cp.product_description AS description,
        cp.sale_price,
        cs.zip_code,
        cp.uniq_id AS product_id
FROM
        cymbal_products cp
JOIN cymbal_inventory ci ON
        ci.uniq_id = cp.uniq_id
JOIN cymbal_stores cs ON
        cs.store_id = ci.store_id
        AND ci.inventory>0
        AND cs.store_id = 1583
ORDER BY
        (cp.embedding <=> embedding('text-embedding-005',
        'What kind of fruit trees grow well here?')::vector) ASC
LIMIT 1),
prompt AS (
SELECT
        'You are a friendly advisor helping to find a product based on the customer''s needs.
Based on the client request we have loaded a list of products closely related to search.
The list in JSON format with list of values like {"product_name":"name","product_description":"some description","sale_price":10}
Here is the list of products:' || json_agg(trees) || 'The customer asked "What kind of fruit trees grow well here?"
You should give information about the product, price and some supplemental information' AS prompt_text
FROM
        trees),
response AS (
SELECT
        google_ml.predict_row( model_id =>'gemini-3.5-flash',
        request_body => json_build_object('contents',
        json_build_object('role',
        'user',
        'parts',
        json_build_object('text',
        prompt_text))))->'candidates'->0->'content'->'parts'->0->'text' AS resp
FROM
        prompt)
SELECT
REPLACE(resp::text, '\n', CHR(10))
FROM
        response;

预期输出:

"Hello there! If you're looking for a wonderful fruit tree to plant, I have a fantastic option for you: ### **Cherry Tree** * **Price:** $75.00 * **Product ID:** `d536e9e823296a2eba198e52dd23e712` --- ### **Why it's a great choice:** * **Fruit & Shade:** Not only will it produce delicious, sweet cherries, but it also grows into a beautiful 15-foot deciduous tree that provides excellent shade and privacy for your yard. * **Seasonal Beauty:** Its leaves are a lovely dark green throughout the summer and transition into a striking red during the fall. * **Ideal Growing Conditions:** Cherry trees thrive best in cool, moist climates with sandy soil and are suitable for **USDA hardiness zones 4–9**. If your local climate matches these conditions, this Cherry Tree would make a beautiful and tasty addition to your garden! Let me know if you'd like more details or help placing an order."

10. 创建最近邻索引

对于包含数百万个向量的大型数据集,向量搜索可能需要大量计算资源。为了提高查询性能,请在向量嵌入上创建索引。

创建 HNSW 索引

分层可导航小世界 (HNSW) 是一种基于图的向量索引。

如需在 embedding 列上构建 HNSW 索引,请指定距离函数 (vector_cosine_ops) 和可选参数(例如 m 和 ef_construction)。如需了解详情,请参阅使用向量嵌入。

CREATE INDEX cymbal_products_embeddings_hnsw ON cymbal_products
  USING hnsw (embedding vector_cosine_ops)
  WITH (m = 16, ef_construction = 64);

预期输出:

quickstart_db=> CREATE INDEX cymbal_products_embeddings_hnsw ON cymbal_products
  USING hnsw (embedding vector_cosine_ops)
  WITH (m = 16, ef_construction = 64);
CREATE INDEX
quickstart_db=>

比较查询性能

使用 EXPLAIN (ANALYZE) 运行向量搜索查询,以验证查询规划器是否使用了索引:

EXPLAIN (ANALYZE) 
WITH trees as (
SELECT
        cp.product_name,
        left(cp.product_description,80) as description,
        cp.sale_price,
        cs.zip_code,
        cp.uniq_id as product_id
FROM
        cymbal_products cp
JOIN cymbal_inventory ci on
        ci.uniq_id=cp.uniq_id
JOIN cymbal_stores cs on
        cs.store_id=ci.store_id
        AND ci.inventory>0
        AND cs.store_id = 1583
ORDER BY
        (cp.embedding <=> embedding('text-embedding-005','What kind of fruit trees grow well here?')::vector) ASC
LIMIT 1)
SELECT json_agg(trees) FROM trees;

预期输出:

 Aggregate  (cost=779.12..779.13 rows=1 width=32) (actual time=1.066..1.069 rows=1 loops=1)
   ->  Subquery Scan on trees  (cost=769.05..779.12 rows=1 width=142) (actual time=1.038..1.041 rows=1 loops=1)
         ->  Limit  (cost=769.05..779.11 rows=1 width=158) (actual time=1.022..1.024 rows=1 loops=1)
               ->  Nested Loop  (cost=769.05..9339.69 rows=852 width=158) (actual time=1.020..1.021 rows=1 loops=1)
                     ->  Nested Loop  (cost=768.77..9316.48 rows=852 width=945) (actual time=0.858..0.859 rows=1 loops=1)
                           ->  Index Scan using cymbal_products_embeddings_hnsw on cymbal_products cp  (cost=768.34..2572.47 rows=941 width=941) (actual time=0.532..0.539 rows=3 loops=1)
...
 Planning Time: 112.398 ms
 Execution Time: 1.221 ms

执行计划显示 Index Scan using cymbal_products_embeddings_hnsw。

运行不含 EXPLAIN 的查询:

WITH trees as (
SELECT
        cp.product_name,
        left(cp.product_description,80) as description,
        cp.sale_price,
        cs.zip_code,
        cp.uniq_id as product_id
FROM
        cymbal_products cp
JOIN cymbal_inventory ci on
        ci.uniq_id=cp.uniq_id
JOIN cymbal_stores cs on
        cs.store_id=ci.store_id
        AND ci.inventory>0
        AND cs.store_id = 1583
ORDER BY
        (cp.embedding <=> embedding('text-embedding-005','What kind of fruit trees grow well here?')::vector) ASC
LIMIT 1)
SELECT json_agg(trees) FROM trees;

预期输出:

[{"product_name":"Cherry Tree","description":"This is a beautiful cherry tree that will produce delicious cherries. It is an d","sale_price":75.00,"zip_code":93230,"product_id":"d536e9e823296a2eba198e52dd23e712"}]

如需详细了解 LangChain 和矢量索引,并查看相关示例,请参阅 Cloud SQL AI 概览文档。

11. 清理资源

完成此 Codelab 后,删除 Cloud SQL 实例。

如果您的会话已断开连接,请在 Cloud Shell 中设置项目和环境变量:

export INSTANCE_NAME=my-cloudsql-instance
export PROJECT_ID=$(gcloud config get-value project)

删除实例:

gcloud sql instances delete $INSTANCE_NAME --project=$PROJECT_ID

预期输出:

student@cloudshell:~$ gcloud sql instances delete $INSTANCE_NAME --project=$PROJECT_ID
All of the instance data will be lost when the instance is deleted.

Do you want to continue (Y/n)?  y

Deleting Cloud SQL instance...done.                                                                                                                
Deleted [https://sandbox.googleapis.com/v1beta4/projects/test-project-001-402417/instances/my-cloudsql-instance].

12. 恭喜

恭喜!您已完成此 Codelab。

本实验是“利用 Google Cloud 构建可用于生产用途的 AI”学习路线的组成部分。

  • 探索完整课程,弥合从原型设计到生产落地的差距。
  • 使用 ##ProductionReadyAI 分享您的进度。

摘要

您学习了如何:

尝试使用 ScaNN 索引(而非 HNSW)完成 AlloyDB AI 向量嵌入 Codelab。