將 AlloyDB for PostgreSQL 與 Gemini Enterprise Agent Platform 整合後,您就能執行 SQL 查詢,將資料庫資料直接傳遞至 Agent Platform 模型,用於生成嵌入和線上預測。
這些操作說明僅適用於 AlloyDB,不適用於 AlloyDB Omni。如要改用 Agent Platform 整合本機安裝的 AlloyDB Omni,請參閱「安裝 AlloyDB Omni 與 AlloyDB AI」。
如要進一步瞭解如何搭配 AlloyDB 使用機器學習模型,請參閱「使用 AlloyDB AI 建構生成式 AI 應用程式」。
如要進一步瞭解 Agent Platform,請參閱「Agent Platform 總覽」。
事前準備
- 登入 Google Cloud 帳戶。如果您未曾使用過 Google Cloud,歡迎 建立帳戶,親自體驗實際使用我們產品的成效。新客戶還能獲得價值 $300 美元的免費抵免額,用於執行、測試及部署工作負載。
-
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 Agent Platform API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
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 Agent Platform API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
關於 AlloyDB 服務代理
將 AlloyDB 與其他 Google Cloud 服務搭配使用時,AlloyDB 會透過 Identity and Access Management (IAM) 服務代理向這些服務進行驗證。這個服務代理是由 AlloyDB 控制的 IAM 主體。您可以將 IAM 角色授予這個服務代理,讓其代表您存取其他 Google Cloud 服務。
將 Vertex AI User 角色授予 AlloyDB 服務代理
如要啟用資料庫與 Agent Platform 整合功能,請將 Vertex AI User 角色授予 AlloyDB 服務代理。這樣一來,AlloyDB 服務代理就能代表您存取 Agent Platform。
請按照下列步驟,將 Vertex AI User 角色授予 AlloyDB 服務代理:
在 AlloyDB 資料庫叢集所在的專案中,將 Agent Platform 權限新增至 AlloyDB 服務代理:
控制台
前往 Google Cloud 控制台的「Welcome」(歡迎) 頁面,複製含有 AlloyDB 叢集或執行個體的專案編號。您將在後續步驟中使用這個專案編號。
前往 Google Cloud 控制台的「IAM」頁面。
選取需要呼叫 Agent Platform 端點的專案。
啟用「包含 Google 提供的角色授予項目」。
按一下 「Grant Access」(授予存取權)。
在「New principals」(新增主體) 欄位中輸入下列內容:
service-PROJECT_NUMBER@gcp-sa-alloydb.iam.gserviceaccount.com將
PROJECT_NUMBER替換為專案編號。在「角色」欄位中,輸入「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"
更改下列內容:
PROJECT_ID:具備 Agent Platform 端點的專案 ID。PROJECT_NUMBER:含有 AlloyDB 叢集或執行個體的專案編號。
驗證已安裝的擴充功能
確認 google_ml_integration 是否已安裝在資料庫中,且該資料庫包含要執行預測的資料:
控制台
前往 Google Cloud 控制台的「Clusters」(叢集) 頁面。
在「Resource name」(資源名稱) 欄中,點選 AlloyDB 叢集名稱,顯示叢集的「Overview」(總覽) 頁面。
在導覽選單中,點選「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用戶端連線至叢集的主要執行個體。在
psql命令提示字元中,連線至資料庫:\c DB_NAME
將
DB_NAME替換為要安裝擴充功能的資料庫名稱。確認已安裝
google_ml_integration擴充功能 1.4.2 以上版本:SELECT extversion FROM pg_extension WHERE extname = 'google_ml_integration';