Stay organized with collections
Save and categorize content based on your preferences.
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.
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.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[[["\u003cp\u003eThis page outlines the process of integrating AlloyDB for PostgreSQL with Vertex AI, enabling the application of queries to cloud-stored large language models (LLMs) against your data.\u003c/p\u003e\n"],["\u003cp\u003eTo enable this integration, the AlloyDB service agent needs to be granted Vertex AI user permissions within the appropriate project using the Google Cloud console or the \u003ccode\u003egcloud\u003c/code\u003e CLI.\u003c/p\u003e\n"],["\u003cp\u003eVerify that the \u003ccode\u003egoogle_ml_integration\u003c/code\u003e extension, version 1.4.2 or later, is installed within the relevant database where you want to run predictions, and if necessary you may install or update it.\u003c/p\u003e\n"],["\u003cp\u003eThis content is specific for AlloyDB and not AlloyDB Omni, for which separate instructions are provided.\u003c/p\u003e\n"]]],[],null,["# Integrate with Vertex AI\n\nThis page details how to set up the integration between AlloyDB for PostgreSQL\nand Vertex AI, letting you apply queries to cloud-stored large language\nmodels (LLMs) to your data.\n\nThese instructions are specific to using AlloyDB, and not\nAlloyDB Omni. To instead integrate a local installation of\nAlloyDB Omni using Vertex AI, see [Install\nAlloyDB Omni with AlloyDB AI](/alloydb/omni/docs/install-with-alloydb-ai).\n\nFor more information about using ML models with AlloyDB, see\n[Build generative AI applications using AlloyDB AI](/alloydb/docs/ai).\n\nFor more information about Vertex AI, see [Introduction to\nVertex AI](/vertex-ai/docs/start/introduction-unified-platform).\n\nBefore you begin\n----------------\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Vertex AI API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com&redirect=https://console.cloud.google.com)\n-\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n- If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n-\n To [initialize](/sdk/docs/initializing) the gcloud CLI, run the following command:\n\n ```bash\n gcloud init\n ```\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Vertex AI API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com&redirect=https://console.cloud.google.com)\n-\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n- If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n-\n To [initialize](/sdk/docs/initializing) the gcloud CLI, run the following command:\n\n ```bash\n gcloud init\n ```\n\n\u003cbr /\u003e\n\nGrant Vertex AI user permission to AlloyDB service agent\n--------------------------------------------------------\n\nTo enable database integration with Vertex AI, follow these steps to grant the\nAlloyDB service agent [Identity and Access Management (IAM)\npermissions](/iam/docs/manage-access-service-accounts) to\naccess Vertex AI:\n\nAdd Vertex AI permissions to the AlloyDB service\nagent for the project where the AlloyDB database's cluster is\nlocated: \n\n### Console\n\n1. 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.\n\n [Go to Welcome](https://console.cloud.google.com/welcome)\n\n \u003cbr /\u003e\n\n2. In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector2/iam-admin/iam)\n\n \u003cbr /\u003e\n\n3. Select the project that has Vertex AI endpoints.\n\n4. Enable **Include Google-provided role grants**.\n\n5. Click person_add **Grant Access**.\n\n6. In the **New principals** field, enter the following:\n\n \u003cbr /\u003e\n\n ```\n service-PROJECT_NUMBER@gcp-sa-alloydb.iam.gserviceaccount.com\n \n ```\n\n \u003cbr /\u003e\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e with the project number.\n7. In the **Role** field, enter **Vertex AI User**.\n\n8. Click **Save**.\n\n### gcloud\n\n\nTo use the gcloud CLI, you can\n[install and initialize](/sdk/docs/install) the Google Cloud CLI, or you\ncan use [Cloud Shell](/shell/docs/using-cloud-shell).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n```\n gcloud projects add-iam-policy-binding PROJECT_ID \n\n --member=\"serviceAccount:service-PROJECT_NUMBER@gcp-sa-alloydb.iam.gserviceaccount.com\" \n\n --role=\"roles/aiplatform.user\"\n \n```\n\n\u003cbr /\u003e\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: The ID of the project that has the Vertex AI endpoint.\n- \u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e: The project number of the project that has AlloyDB clusters or instances.\n\n| **Note:** The policy change takes effect within 60 seconds to 7 minutes.\n\nVerify installed extension\n--------------------------\n\nVerify if the `google_ml_integration` is installed in the database\nthat contains the data that you want to run predictions on: \n\n### Console\n\n1. In the Google Cloud console, go to the **Clusters** page.\n\n [Go to Clusters](https://console.cloud.google.com/alloydb/clusters)\n2. To display the cluster **Overview** page, click the name of the AlloyDB cluster in the **Resource name** column.\n\n3. In the navigation menu, click **AlloyDB Studio**.\n\n4. On the **Sign in to AlloyDB Studio** page, authenticate using the name of your database, username, and password.\n\n | **Note:** AlloyDB Studio connects to the primary instance of your cluster, which is where extension management and initial predictions are handled, even if you intend to invoke predictions from read pool instances later.\n5. In the **Editor 1** tab, complete the following:\n\n 1. Verify the `google_ml_integration` extension version 1.4.2 or later is installed:\n\n ```sql\n SELECT extversion FROM pg_extension WHERE extname = 'google_ml_integration';\n ```\n 2. Click **Run** . Wait for the extension version to display in the **Results** pane.\n\n### psql\n\n1. Connect a `psql` client to the cluster's primary instance, as\n described in [Connect a `psql` client to an instance](/alloydb/docs/connect-psql).\n\n | **Note:** You must connect to the primary instance even if you intend to invoke predictions while connected to a read pool instance.\n2. At the `psql` command prompt, connect to the database:\n\n ```sql\n \\c DB_NAME\n ```\n\n Replace \u003cvar translate=\"no\"\u003eDB_NAME\u003c/var\u003e with the name of the database on which you want\n to install the extension.\n\n \u003cbr /\u003e\n\n3. Verify the `google_ml_integration` extension version 1.4.2 or later is installed:\n\n ```sql\n SELECT extversion FROM pg_extension WHERE extname = 'google_ml_integration';\n ```\n\n \u003cbr /\u003e\n\nWhat's next\n-----------\n\n- [Work with embeddings](/alloydb/docs/ai/work-with-embeddings)\n\n- [Invoke predictions](/alloydb/docs/ai/invoke-predictions)\n\n- [Vertex AI quotas and limits](/vertex-ai/docs/quotas)\n\n- [Call remote model endpoints](/alloydb/docs/ai/model-endpoint-overview)"]]