This page details how to set up the integration between AlloyDB for PostgreSQL and Vertex AI, letting you issue queries that pass your data to Vertex AI models.
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
- 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, go to 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.
-
To initialize the gcloud CLI, run the following command:
gcloud init -
In the Google Cloud console, go to 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.
-
To initialize the gcloud CLI, run the following command:
gcloud init
About the AlloyDB service agent
When you use AlloyDB with other Google Cloud services, AlloyDB uses an Identity and Access Management (IAM) service agent to authenticate to those services. This service agent is an IAM principal that AlloyDB controls. You grant IAM roles to this service agent to let it access other Google Cloud services on your behalf.
Grant Vertex AI user role to the AlloyDB service agent
To enable database integration with Vertex AI, you grant the AlloyDB service agent the Vertex AI User role. This lets the AlloyDB service agent access Vertex AI on your behalf.
Follow these steps to grant the AlloyDB service agent the Vertex AI User role:
Add Vertex AI permissions to the AlloyDB service agent for the project where the AlloyDB database's cluster is located:
Console
Go to the Welcome page 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.
In the Google Cloud console, go to the IAM page.
Select the project that needs to call Vertex AI endpoints.
Enable Include Google-provided role grants.
Click Grant Access.
In the New principals field, enter the following:
service-PROJECT_NUMBER@gcp-sa-alloydb.iam.gserviceaccount.comReplace PROJECT_NUMBER with the project number.
In the Role field, enter Vertex AI User.
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
In the Google Cloud console, go to the Clusters page.
To display the cluster Overview page, click the name of the AlloyDB cluster in the Resource name column.
In the navigation menu, click AlloyDB Studio.
On the Sign in to AlloyDB Studio page, authenticate using the name of your database, username, and password.
In the Editor 1 tab, complete the following:
Verify the
google_ml_integrationextension version 1.4.2 or later is installed:SELECT extversion FROM pg_extension WHERE extname = 'google_ml_integration';
Click Run. Wait for the extension version to display in the Results pane.
psql
Connect a
psqlclient to the cluster's primary instance, as described in Connect apsqlclient to an instance.At the
psqlcommand prompt, connect to the database:\c DB_NAME
Replace
DB_NAMEwith the name of the database on which you want to install the extension.Verify the
google_ml_integrationextension version 1.4.2 or later is installed:SELECT extversion FROM pg_extension WHERE extname = 'google_ml_integration';