本頁詳細說明如何設定 PostgreSQL 適用的 AlloyDB 與 Vertex AI 之間的整合,讓您發出查詢,將資料傳遞至 Vertex AI 模型。
以下操作說明適用於 AlloyDB,而非 AlloyDB Omni。如要改用 Vertex AI 整合本機安裝的 AlloyDB Omni,請參閱「安裝 AlloyDB Omni 和 AlloyDB AI」。
如要進一步瞭解如何搭配使用 ML 模型與 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.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. -
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.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. -
Install the Google Cloud CLI.
-
若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。
-
執行下列指令,初始化 gcloud CLI:
gcloud init 前往 Google Cloud 控制台的「Welcome」(歡迎使用) 頁面,然後複製含有 AlloyDB 叢集或執行個體的專案編號。您將在後續步驟中使用這個專案編號。
前往 Google Cloud 控制台的「IAM」頁面。
選取需要呼叫 Vertex AI 端點的專案。
啟用「包含 Google 提供的角色授權」。
按一下「 授予存取權」。
在「New principals」(新增主體) 欄位中輸入下列內容:
service-PROJECT_NUMBER@gcp-sa-alloydb.iam.gserviceaccount.com將 PROJECT_NUMBER 替換為專案編號。
在「角色」欄位中,輸入「Vertex AI 使用者」。
按一下 [儲存]。
- PROJECT_ID:具有 Vertex AI 端點的專案 ID。
- PROJECT_NUMBER:具有 AlloyDB 叢集或執行個體的專案編號。
前往 Google Cloud 控制台的「Clusters」(叢集) 頁面。
如要顯示叢集「總覽」頁面,請按一下「資源名稱」欄中的 AlloyDB 叢集名稱。
在導覽選單中,按一下「AlloyDB Studio」。
在「登入 AlloyDB Studio」頁面,使用資料庫名稱、使用者名稱和密碼進行驗證。
在「Editor 1」(編輯器 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 服務代理 Identity and Access Management (IAM) 權限,以便存取 Vertex AI:
為 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 是否已安裝在包含要執行預測的資料的資料庫中: