整合 Vertex AI

本頁詳細說明如何設定 PostgreSQL 適用的 AlloyDB 與 Vertex AI 的整合,讓您對雲端儲存的大型語言模型 (LLM) 套用查詢,以存取資料。

以下操作說明適用於 AlloyDB,而非 AlloyDB Omni。如要改用 Vertex AI 整合本機安裝的 AlloyDB Omni,請參閱「使用 AlloyDB AI 安裝 AlloyDB Omni」。

如要進一步瞭解如何搭配使用 ML 模型與 AlloyDB,請參閱「使用 AlloyDB AI 建構生成式 AI 應用程式」。

如要進一步瞭解 Vertex AI,請參閱 Vertex AI 簡介

事前準備

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI API.

    Enable the API

  5. Install the Google Cloud CLI.

  6. 如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

  7. 如要初始化 gcloud CLI,請執行下列指令:

    gcloud init
  8. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  9. Verify that billing is enabled for your Google Cloud project.

  10. Enable the Vertex AI API.

    Enable the API

  11. Install the Google Cloud CLI.

  12. 如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

  13. 如要初始化 gcloud CLI,請執行下列指令:

    gcloud init
  14. 將 Vertex AI 使用者權限授予 AlloyDB 服務代理

    如要啟用資料庫與 Vertex AI 的整合功能,請按照下列步驟授予 AlloyDB 服務代理 Identity and Access Management (IAM) 權限,以便存取 Vertex AI:

    為 AlloyDB 資料庫叢集所在專案的 AlloyDB 服務代理程式新增 Vertex AI 權限:

    控制台

    1. 前往 Google Cloud 控制台的「Welcome」(歡迎) 頁面,然後複製含有 AlloyDB 叢集或執行個體的專案編號。您將在後續步驟中使用這個專案編號。

      前往「歡迎」

    2. 前往 Google Cloud 控制台的「IAM」(身分與存取權管理) 頁面。

      前往「IAM」頁面

    3. 選取含有 Vertex AI 端點的專案。

    4. 啟用「包含 Google 提供的角色授權」

    5. 按一下「授予存取權」

    6. 在「New principals」(新增主體) 欄位中輸入下列內容:

          service-PROJECT_NUMBER@gcp-sa-alloydb.iam.gserviceaccount.com
          

      PROJECT_NUMBER 替換為專案編號。

    7. 在「角色」欄位中,輸入「Vertex AI 使用者」

    8. 按一下「儲存」

    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:具有 Vertex AI 端點的專案 ID。
    • PROJECT_NUMBER:含有 AlloyDB 叢集或執行個體的專案編號。

    確認已安裝擴充功能

    確認 google_ml_integration 是否已安裝在包含要執行預測的資料的資料庫中:

    控制台

    1. 前往 Google Cloud 控制台的「Clusters」(叢集) 頁面。

      前往「Clusters」(叢集) 頁面

    2. 如要顯示叢集「總覽」頁面,請按一下「資源名稱」欄中的 AlloyDB 叢集名稱。

    3. 在導覽選單中,按一下「AlloyDB Studio」

    4. 在「登入 AlloyDB Studio」頁面,使用資料庫名稱、使用者名稱和密碼進行驗證。

    5. 在「Editor 1」(編輯器 1) 分頁中,完成下列步驟:

      1. 確認已安裝 google_ml_integration 擴充功能 1.4.2 以上版本:

        SELECT extversion FROM pg_extension WHERE extname = 'google_ml_integration';
      2. 按一下「執行」。等待「結果」窗格顯示擴充功能版本。

    psql

    1. 按照「psql 用戶端連線至執行個體」一文的說明,將 psql 用戶端連線至叢集的主要執行個體。

    2. psql 命令提示字元中,連線至資料庫:

      \c DB_NAME

      DB_NAME 替換為要安裝擴充功能的資料庫名稱。

    3. 確認已安裝 google_ml_integration 擴充功能 1.4.2 以上版本:

      SELECT extversion FROM pg_extension WHERE extname = 'google_ml_integration';

    後續步驟