Integrate with Vertex AI

This page details how to set up the integration between AlloyDB for PostgreSQL and Vertex AI, letting you apply queries to cloud-stored large language models (LLMs) to your data.

These instructions are specific to using AlloyDB, and not AlloyDB Omni. To instead integrate a local installation of AlloyDB Omni using Vertex AI, see Install AlloyDB Omni with AlloyDB AI .

For more information about using ML models with AlloyDB, see Build generative AI applications using AlloyDB AI .

For more information about Vertex AI, see Introduction to Vertex AI .

Before you begin

  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. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity .

  7. To initialize the gcloud CLI, run the following command:

    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. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity .

  13. To initialize the gcloud CLI, run the following command:

    gcloud  
    init

Grant Vertex AI user permission to AlloyDB service agent

To enable database integration with Vertex AI, follow these steps to grant the AlloyDB service agent Identity and Access Management (IAM) permissions to access Vertex AI:

Add Vertex AI permissions to the AlloyDB service agent for the project where the AlloyDB database's cluster is located:

Console

  1. Go to the Welcomepage in the Google Cloud console, and copy the project number of the project that has AlloyDB clusters or instances. You will use this project number in the next steps.

    Go to Welcome

  2. In the Google Cloud console, go to the IAM page.

    Go to IAM

  3. Select the project that has Vertex AI endpoints.

  4. Enable Include Google-provided role grants.

  5. Click Grant Access.

  6. In the New principalsfield, enter the following:

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

    Replace PROJECT_NUMBER with the project number.

  7. In the Rolefield, enter Vertex AI User.

  8. Click Save.

gcloud

To use the gcloud CLI, you can install and initialize the Google Cloud CLI, or you can use 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"

Replace the following:

  • PROJECT_ID : The ID of the project that has the Vertex AI endpoint.
  • PROJECT_NUMBER : The project number of the project that has AlloyDB clusters or instances.

Verify installed extension

Verify if the google_ml_integration is installed in the database that contains the data that you want to run predictions on:

Console

  1. In the Google Cloud console, go to the Clusterspage.

    Go to Clusters

  2. To display the cluster Overviewpage, click the name of the AlloyDB cluster in the Resource namecolumn.

  3. In the navigation menu, click AlloyDB Studio.

  4. On the Sign in to AlloyDB Studiopage, authenticate using the name of your database, username, and password.

  5. In the Editor 1tab, complete the following:

    1. Verify the google_ml_integration extension version 1.4.2 or later is installed:

       SELECT 
        
       extversion 
        
       FROM 
        
       pg_extension 
        
       WHERE 
        
       extname 
        
       = 
        
       'google_ml_integration' 
       ; 
      
    2. Click Run. Wait for the extension version to display in the Resultspane.

psql

  1. Connect a psql client to the cluster's primary instance, as described in Connect a psql client to an instance .

  2. At the psql command prompt, connect to the database:

     \ 
     c 
      
      DB_NAME 
     
    

    Replace DB_NAME with the name of the database on which you want to install the extension.

  3. Verify the google_ml_integration extension version 1.4.2 or later is installed:

     SELECT 
      
     extversion 
      
     FROM 
      
     pg_extension 
      
     WHERE 
      
     extname 
      
     = 
      
     'google_ml_integration' 
     ; 
    

What's next

Create a Mobile Website
View Site in Mobile | Classic
Share by: