本页面详细介绍了如何设置 AlloyDB for PostgreSQL 与 Vertex AI 之间的集成,以便您将查询应用于云端存储的大语言模型 (LLM),从而查询数据。
这些说明专门针对 AlloyDB,不适用于 AlloyDB Omni。如需改用 Vertex AI 集成本地安装的 AlloyDB Omni,请参阅安装具有 AlloyDB AI 的 AlloyDB Omni。
如需详细了解如何将机器学习模型与 AlloyDB 搭配使用,请参阅使用 AlloyDB AI 构建生成式 AI 应用。
如需详细了解 Vertex AI,请参阅 Vertex AI 简介。
准备工作
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
-
Install the Google Cloud CLI.
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
-
Install the Google Cloud CLI.
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init
前往 Google Cloud 控制台中的欢迎页面,然后复制包含 AlloyDB 集群或实例的项目的项目编号。您将在后续步骤中使用此项目编号。
在 Google Cloud 控制台中,前往 IAM 页面。
选择包含 Vertex AI 端点的项目。
启用包括 Google 提供的角色授权。
点击
授予访问权限。在新的主账号字段中,输入以下内容:
service-PROJECT_NUMBER@gcp-sa-alloydb.iam.gserviceaccount.com
将 PROJECT_NUMBER 替换为项目编号。
在角色字段中,输入 Vertex AI User。
点击保存。
- PROJECT_ID:具有 Vertex AI 端点的项目的 ID。
- PROJECT_NUMBER:包含 AlloyDB 集群或实例的项目的项目编号。
在 Google Cloud 控制台中,前往集群页面。
如需显示集群的概览页面,请点击资源名称列中的 AlloyDB 集群名称。
在导航菜单中,点击 AlloyDB Studio。
在 登录 AlloyDB Studio页面上,使用数据库名称、用户名和密码进行身份验证。
在编辑器 1 标签页中,完成以下操作:
验证是否已安装
google_ml_integration
扩展程序 1.4.2 版或更高版本:SELECT extversion FROM pg_extension WHERE extname = 'google_ml_integration';
点击运行。等待结果窗格中显示扩展程序版本。
按照将
psql
客户端连接到实例中所述,将psql
客户端连接到集群的主实例。在
psql
命令提示符下,连接到数据库:\c DB_NAME
将
DB_NAME
替换为您要在其中安装扩展程序的数据库的名称。验证是否已安装
google_ml_integration
扩展程序 1.4.2 或更高版本:SELECT extversion FROM pg_extension WHERE extname = 'google_ml_integration';
向 AlloyDB 服务代理授予 Vertex AI 用户权限
如需启用数据库与 Vertex AI 的集成,请按以下步骤操作,以授予 AlloyDB 服务代理访问 Vertex AI 的 Identity and Access Management (IAM) 权限:
为 AlloyDB 数据库的集群所在的项目向 AlloyDB 服务代理添加 Vertex AI 权限:
控制台
gcloud
如需使用 gcloud CLI,您可以安装并初始化 Google Cloud CLI,也可以使用 Cloud Shell。
gcloud projects add-iam-policy-binding PROJECT_ID
--member="serviceAccount:service-PROJECT_NUMBER@gcp-sa-alloydb.iam.gserviceaccount.com"
--role="roles/aiplatform.user"
替换以下内容:
验证已安装的扩展程序
验证包含您要根据其运行预测的数据的数据库中是否已安装 google_ml_integration
: