This page describes how to integrate Cloud SQL with
[Vertex AI](https://docs.cloud.google.com/vertex-ai/docs).

This integration lets you apply large language models (LLMs), which are hosted
in Vertex AI, to a Cloud SQL for PostgreSQL database, version 12 and later.

By integrating Cloud SQL with Vertex AI, you can apply
the semantic and predictive power of machine learning (ML) models to your data.
This integration extends the SQL syntax with two functions for querying models:

- [Invoke predictions](https://docs.cloud.google.com/sql/docs/postgres/invoke-online-predictions.md.txt) to call
  a model using SQL within a transaction.

- [Generate embeddings](https://docs.cloud.google.com/sql/docs/postgres/generate-manage-vector-embeddings.md.txt)
  to have an embedding model translate text prompts into numerical vectors.
  You can then apply these vector embeddings as inputs to `vector` functions.
  This includes methods to compare and sort samples of text according to their
  relative semantic distance.

As a result, you can make real-time predictions and gain valuable insights
directly within the database, streamlining your workflows and enhancing your
decision-making capabilities.

For more information about Vertex AI, see
[Introduction to Vertex AI](https://docs.cloud.google.com/vertex-ai/docs/start/introduction-unified-platform).

## Before you begin

> [!NOTE]
> **Note:** The name that you use for your project must be between 4 and 30 characters. When you type the name, the form suggests a project ID, which you can edit. The project ID must be between 6 and 30 characters, with a lowercase letter as the first character. You can use a dash, lowercase letter, or digit for the remaining characters, but the last character can't be a dash.

1. Enable the necessary Google Cloud APIs.

   ### Console

   <br />

   1. Go to the [**APIs \& Services** page](https://console.developers.google.com).
   2. From the projects list, select your project.
   3. If the **API Library** isn't open, then from the navigation menu, select **Library**.
   4. Click the APIs that you want to enable. For this procedure, enable the
      following:

      - Cloud SQL Admin API
      - Vertex AI API
      - Compute Engine API

      > [!NOTE]
      > **Note:** If you need help finding these APIs, then use the search field.

   5. After selecting each API, click **Enable**.

   <br />

   ### gcloud

   <br />

   <br />

   1. Open [Cloud Shell](https://docs.cloud.google.com/shell/docs/run-gcloud-commands.md.txt), which provides command-line access to your Google Cloud resources directly from the browser.
   2. To enable the required APIs, use the `gcloud services enable` command:

      ```
      gcloud services enable sqladmin.googleapis.com \
        aiplatform.googleapis.com \
        compute.googleapis.com
      ```
   This command enables the following APIs:
      - Cloud SQL Admin API
      - Vertex AI API
      - Compute Engine API

   <br />

   <br />

   <br />

   <br />

   <br />


- Grant the Cloud SQL service account Identity and Access Management (IAM) permissions to access Vertex AI.

### gcloud

> [!NOTE]
> **Note** : If you're creating an instance with Vertex AI enabled, then [create the instance](https://docs.cloud.google.com/sql/docs/postgres/integrate-cloud-sql-with-vertex-ai.md.txt#enable-database-integration-with-vertex-ai) before you complete this step.


To add the Vertex AI permissions to the Cloud SQL service
account for the project where the Cloud SQL instance is located,
create a custom IAM role with the minimum required permissions,
and then grant that role to the service account.

1. To create a custom role with the `aiplatform.endpoints.predict` permission, use the [`gcloud iam roles create`](https://docs.cloud.google.com/sdk/gcloud/reference/iam/roles/create.md.txt) command:

   ```
   gcloud iam roles create ROLE_NAME \
     --project=PROJECT_ID \
     --title="Cloud SQL Vertex AI Predictor" \
     --description="Allows Cloud SQL to invoke Vertex AI predictions" \
     --permissions="aiplatform.endpoints.predict"
   ```
2. To grant the custom role to the Cloud SQL service account, use the [`gcloud projects add-iam-policy-binding`](https://docs.cloud.google.com/sdk/gcloud/reference/projects/add-iam-policy-binding) command:

   ```
   gcloud projects add-iam-policy-binding PROJECT_ID \
     --member="serviceAccount:SERVICE_ACCOUNT_EMAIL" \
     --role="projects/PROJECT_ID/roles/ROLE_NAME"
   ```

Make the following replacements:

- <var translate="no">ROLE_NAME</var>: the name of the custom IAM role to create, for example `CloudSQLMLPredictor`.
- <var translate="no">PROJECT_ID</var>: the ID of the project that has the Vertex AI endpoint. Cloud SQL uses this endpoint to access the LLM that's hosted in Vertex AI.
- <var translate="no">SERVICE_ACCOUNT_EMAIL</var>: the email address of the Cloud SQL
  service account.

  To find this email address, use the `gcloud sql instances describe` command:

  ```
  gcloud sql instances describe INSTANCE_NAME | grep EmailAddress
  ```


  Replace <var translate="no">INSTANCE_NAME</var> with the name of the Cloud SQL instance.

> [!NOTE]
> **Note:** In general, the policy change takes effect within 2 minutes. However, under certain circumstances, it can take up to 7 minutes for such changes to propagate fully across the system. For more information, see [Access change propagation](https://docs.cloud.google.com/iam/docs/access-change-propagation.md.txt).

<br />

## Enable database integration with Vertex AI

To enable database integration with Vertex AI, complete the following steps:

1. Create or update a Cloud SQL instance so that the instance can integrate with Vertex AI.

   ### gcloud

   #### Create the instance

   To create the Cloud SQL instance, use the [`gcloud sql instances create`](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/create.md.txt) command.

   ```bash
   gcloud sql instances create INSTANCE_NAME \
   --database-version=DATABASE_VERSION \
   --tier=MACHINE_TYPE \
   --region=REGION_NAME \
   --enable-google-ml-integration \
   --database-flags cloudsql.enable_google_ml_integration=on
   ```

   Make the following replacements:
   - <var translate="no">INSTANCE_NAME</var>: the name of the instance
   - <var translate="no">DATABASE_VERSION</var>: the database version for the instance (for example, `POSTGRES_13`)
   - <var translate="no">MACHINE_TYPE</var>: the machine type for the instance
   - <var translate="no">REGION_NAME</var>: the region name for the instance

   > [!NOTE]
   > **Note:** For more information about these parameters, see [Create instances](https://docs.cloud.google.com/sql/docs/postgres/create-instance.md.txt).

   #### Update the instance

   To update the instance, use the [`gcloud sql instances patch`](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/patch.md.txt) command.

   ```bash
   gcloud sql instances patch INSTANCE_NAME \
   --enable-google-ml-integration \
   --database-flags cloudsql.enable_google_ml_integration=on
   ```

   If this update modifies a value that requires a restart, then you see a prompt
   to proceed with the change or cancel.

   > [!NOTE]
   > **Note:** For more information about updating an instance, see [Edit instances](https://docs.cloud.google.com/sql/docs/postgres/edit-instance.md.txt).

   ### REST v1

   #### Create the instance

   Use this example to create the instance. For a complete list of parameters for this call, see the
   [instances:insert](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1/instances/insert.md.txt)
   page. For information about instance settings, including valid values for a region, see
   [Instance settings](https://docs.cloud.google.com/sql/docs/postgres/instance-settings.md.txt#settings-2ndgen).


   Before using any of the request data,
   make the following replacements:
   - <var translate="no">PROJECT_ID</var>: the ID or [project number](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifying_projects) of the Google Cloud project that contains the instance.
   - <var translate="no">INSTANCE_NAME</var>: the name of the instance.
   - <var translate="no">REGION_NAME</var>: the region name for the instance.
   - <var translate="no">DATABASE_VERSION</var>: enum string of the database version, such as `POSTGRES_13`.
   - <var translate="no">PASSWORD</var>: the password for the `root` user.
   - <var translate="no">MACHINE_TYPE</var>: enum string of the machine (tier) type, such as `db-custom-[CPUS]-[MEMORY_MBS]`. For more information, see [Machine tiers](https://docs.cloud.google.com/sdk/gcloud/reference/sql/tiers/list).
   - <var translate="no">EDITION_TYPE</var>: your Cloud SQL edition, such as `ENTERPRISE`.

   > [!NOTE]
   > **Note:** For more information about these parameters, see [Create instances](https://docs.cloud.google.com/sql/docs/postgres/create-instance.md.txt).

   You must also include the [enableGoogleMlIntegration](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1/instances.md.txt) object in the request. Set the following parameters, as required:
   - `enableGoogleMlIntegration`: when this parameter is set to `true`, Cloud SQL instances can connect to Vertex AI to pass requests for [real-time predictions](https://docs.cloud.google.com/vertex-ai/docs/predictions/overview) and insights to the AI.
   - `cloudsql.enable_google_ml_integration`: when this parameter is set to `on`, Cloud SQL can integrate with Vertex AI.


   HTTP method and URL:

   ```
   POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances
   ```


   Request JSON body:

   ```
   {
     "name": "INSTANCE_NAME",
     "region": "REGION_NAME",
     "databaseVersion": "DATABASE_VERSION",
     "rootPassword": "PASSWORD",
     "settings": {
       "tier": "MACHINE_TYPE",
       "edition": "EDITION_TYPE",
       "enableGoogleMlIntegration": "true" | "false"
       
       "databaseFlags":
         {
           "name": "cloudsql.enable_google_ml_integration",
           "value": "on" | "off"
         }
       
     }
   }
   ```

   To send your request, expand one of these options:

   #### curl (Linux, macOS, or Cloud Shell)

   > [!NOTE]
   > **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


   Save the request body in a file named `request.json`,
   and execute the following command:

   ```
   curl -X POST \
        -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        -H "Content-Type: application/json; charset=utf-8" \
        -d @request.json \
        "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances"
   ```

   #### PowerShell (Windows)

   > [!NOTE]
   > **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


   Save the request body in a file named `request.json`,
   and execute the following command:

   ```
   $cred = gcloud auth print-access-token
   $headers = @{ "Authorization" = "Bearer $cred" }

   Invoke-WebRequest `
       -Method POST `
       -Headers $headers `
       -ContentType: "application/json; charset=utf-8" `
       -InFile request.json `
       -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances" | Select-Object -Expand Content
   ```

   You should receive a JSON response similar to the following:

   ```
   {
     "kind": "sql#operation",
     "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID",
     "status": "PENDING",
     "user": "user@example.com",
     "insertTime": "2019-09-25T22:19:33.735Z",
     "operationType": "CREATE",
     "name": "OPERATION_ID",
     "targetId": "INSTANCE_ID",
     "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
     "targetProject": "PROJECT_ID"
   }
   ```

   #### Update the instance

   Use this example to update the instance. For a complete list of parameters for this call, see the
   [instances.patch](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1/instances/patch.md.txt)
   page.

   If this update modifies a value that requires a restart, then you see a prompt
   to proceed with the change or cancel.


   Before using any of the request data,
   make the following replacements:
   - <var translate="no">PROJECT_ID</var>: the ID or [project number](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifying_projects) of the Google Cloud project that contains the instance
   - <var translate="no">INSTANCE_NAME</var>: the name of the instance


   HTTP method and URL:

   ```
   PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME
   ```


   Request JSON body:

   ```
   {
     "settings": {
       "enableGoogleMlIntegration": true,
       
       "databaseFlags":
         {
           "name": "cloudsql.enable_google_ml_integration",
           "value": "on"
         }
       
      }
   }
   ```

   To send your request, expand one of these options:

   #### curl (Linux, macOS, or Cloud Shell)

   > [!NOTE]
   > **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


   Save the request body in a file named `request.json`,
   and execute the following command:

   ```
   curl -X PATCH \
        -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        -H "Content-Type: application/json; charset=utf-8" \
        -d @request.json \
        "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME"
   ```

   #### PowerShell (Windows)

   > [!NOTE]
   > **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


   Save the request body in a file named `request.json`,
   and execute the following command:

   ```
   $cred = gcloud auth print-access-token
   $headers = @{ "Authorization" = "Bearer $cred" }

   Invoke-WebRequest `
       -Method PATCH `
       -Headers $headers `
       -ContentType: "application/json; charset=utf-8" `
       -InFile request.json `
       -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME" | Select-Object -Expand Content
   ```

   You should receive a JSON response similar to the following:

   ```
   {
     "kind": "sql#operation",
     "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME",
     "status": "PENDING",
     "user": "user@example.com",
     "insertTime": "2020-01-16T02:32:12.281Z",
     "operationType": "UPDATE",
     "name": "OPERATION_ID",
     "targetId": "INSTANCE_NAME",
     "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
     "targetProject": "PROJECT_ID"
   }
   ```

   > [!NOTE]
   > **Note:** For more information about updating an instance, see [Edit instances](https://docs.cloud.google.com/sql/docs/postgres/edit-instance.md.txt).

   ### REST v1beta4

   #### Create the instance

   Use this example to create the instance. For a complete list of parameters for this call, see the
   [instances:insert](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/insert.md.txt)
   page. For information about instance settings, including valid values for a region, see
   [Instance settings](https://docs.cloud.google.com/sql/docs/postgres/instance-settings.md.txt#settings-2ndgen).


   Before using any of the request data,
   make the following replacements:
   - <var translate="no">PROJECT_ID</var>: the ID or [project number](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifying_projects) of the Google Cloud project that contains the instance.
   - <var translate="no">INSTANCE_NAME</var>: the name of the instance.
   - <var translate="no">REGION_NAME</var>: the region name for the instance.
   - <var translate="no">DATABASE_VERSION</var>: enum string of the database version, such as `POSTGRES_13`.
   - <var translate="no">PASSWORD</var>: the password for the `root` user.
   - <var translate="no">MACHINE_TYPE</var>: enum string of the machine (tier) type, such as `db-custom-[CPUS]-[MEMORY_MBS]`. For more information, see [Machine tiers](https://docs.cloud.google.com/sdk/gcloud/reference/sql/tiers/list).
   - <var translate="no">EDITION_TYPE</var>: your Cloud SQL edition, such as `ENTERPRISE`.

   > [!NOTE]
   > **Note:** For more information about these parameters, see [Create instances](https://docs.cloud.google.com/sql/docs/postgres/create-instance.md.txt).

   You must also include the [enableGoogleMlIntegration](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances.md.txt) object in the request. Set the following parameters, as required:
   - `enableGoogleMlIntegration`: when this parameter is set to `true`, Cloud SQL instances can connect to Vertex AI to pass requests for [real-time predictions](https://docs.cloud.google.com/vertex-ai/docs/predictions/overview) and insights to the AI.
   - `cloudsql.enable_google_ml_integration`: when this parameter is set to `on`, Cloud SQL can integrate with Vertex AI.


   HTTP method and URL:

   ```
   POST https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/instances
   ```


   Request JSON body:

   ```
   {
     "name": "INSTANCE_NAME",
     "region": "REGION_NAME",
     "databaseVersion": "DATABASE_VERSION",
     "rootPassword": "PASSWORD",
     "settings": {
       "tier": "MACHINE_TYPE",
       "edition": "EDITION_TYPE",
       "enableGoogleMlIntegration": "true" | "false"
       
       "databaseFlags":
         {
           "name": "cloudsql.enable_google_ml_integration",
           "value": "on" | "off"
         }
       
     }
   }
   ```

   To send your request, expand one of these options:

   #### curl (Linux, macOS, or Cloud Shell)

   > [!NOTE]
   > **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


   Save the request body in a file named `request.json`,
   and execute the following command:

   ```
   curl -X POST \
        -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        -H "Content-Type: application/json; charset=utf-8" \
        -d @request.json \
        "https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/instances"
   ```

   #### PowerShell (Windows)

   > [!NOTE]
   > **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


   Save the request body in a file named `request.json`,
   and execute the following command:

   ```
   $cred = gcloud auth print-access-token
   $headers = @{ "Authorization" = "Bearer $cred" }

   Invoke-WebRequest `
       -Method POST `
       -Headers $headers `
       -ContentType: "application/json; charset=utf-8" `
       -InFile request.json `
       -Uri "https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/instances" | Select-Object -Expand Content
   ```

   You should receive a JSON response similar to the following:

   ```
   {
     "kind": "sql#operation",
     "targetLink": "https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID",
     "status": "PENDING",
     "user": "user@example.com",
     "insertTime": "2019-09-25T22:19:33.735Z",
     "operationType": "CREATE",
     "name": "OPERATION_ID",
     "targetId": "INSTANCE_ID",
     "selfLink": "https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
     "targetProject": "PROJECT_ID"
   }
   ```

   #### Update the instance

   Use this example to update the instance. For a complete list of parameters for this call, see the
   [instances.patch](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/patch.md.txt)
   page.

   If this update modifies a value that requires a restart, then you see a prompt
   to proceed with the change or cancel.


   Before using any of the request data,
   make the following replacements:
   - <var translate="no">PROJECT_ID</var>: the ID or [project number](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifying_projects) of the Google Cloud project that contains the instance
   - <var translate="no">INSTANCE_NAME</var>: the name of the instance


   HTTP method and URL:

   ```
   PATCH https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/instances/INSTANCE_NAME
   ```


   Request JSON body:

   ```
   {
     "settings": {
       "enableGoogleMlIntegration": true,
       
       "databaseFlags":
         {
           "name": "cloudsql.enable_google_ml_integration",
           "value": "on"
         }
       
      }
   }
   ```

   To send your request, expand one of these options:

   #### curl (Linux, macOS, or Cloud Shell)

   > [!NOTE]
   > **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


   Save the request body in a file named `request.json`,
   and execute the following command:

   ```
   curl -X PATCH \
        -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        -H "Content-Type: application/json; charset=utf-8" \
        -d @request.json \
        "https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/instances/INSTANCE_NAME"
   ```

   #### PowerShell (Windows)

   > [!NOTE]
   > **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


   Save the request body in a file named `request.json`,
   and execute the following command:

   ```
   $cred = gcloud auth print-access-token
   $headers = @{ "Authorization" = "Bearer $cred" }

   Invoke-WebRequest `
       -Method PATCH `
       -Headers $headers `
       -ContentType: "application/json; charset=utf-8" `
       -InFile request.json `
       -Uri "https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/instances/INSTANCE_NAME" | Select-Object -Expand Content
   ```

   You should receive a JSON response similar to the following:

   ```
   {
     "kind": "sql#operation",
     "targetLink": "https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/instances/INSTANCE_NAME",
     "status": "PENDING",
     "user": "user@example.com",
     "insertTime": "2020-01-16T02:32:12.281Z",
     "operationType": "UPDATE",
     "name": "OPERATION_ID",
     "targetId": "INSTANCE_NAME",
     "selfLink": "https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
     "targetProject": "PROJECT_ID"
   }
   ```

   > [!NOTE]
   > **Note:** For more information about updating an instance, see [Edit instances](https://docs.cloud.google.com/sql/docs/postgres/edit-instance.md.txt).

2. Install the `google_ml_integration` extension in a database of the primary Cloud SQL instance. This database contains data on which you want to run predictions.

   > [!NOTE]
   > **Note:** You must connect to the primary instance even if you intend to run predictions while connected to a [read replica](https://docs.cloud.google.com/sql/docs/postgres/replication.md.txt#read-replicas) of the instance.

   1. Connect a `psql` client to the primary instance, as described in [Connect using a psql client](https://docs.cloud.google.com/sql/docs/postgres/connect-admin-ip.md.txt).
   2. At the `psql` command prompt, connect to the database:

      ```sql
      \c DB_NAME
      ```

      Replace `DB_NAME` with the name of the database on which you want to install the extension.
   3. Install the extension:

      ```sql
      CREATE EXTENSION IF NOT EXISTS google_ml_integration CASCADE;
      ```

## Troubleshoot

This section contains information about issues associated with integrating Cloud SQL with Vertex AI along with steps for troubleshooting the issues.

| Issue | Troubleshooting |
|---|---|
| Error message: `Google ML integration API is supported only on Postgres version 12 or above.` | To enable the Vertex AI integration in Cloud SQL, you must have a Cloud SQL for PostgreSQL database, version 12 or later. To upgrade your database to this version, see [Upgrade the database major version in-place](https://docs.cloud.google.com/sql/docs/postgres/upgrade-major-db-version-inplace.md.txt). |
| Error message: `Google ML Integration API is not supported on shared core instance. Please upsize your machine type.` | If you selected a shared core for the machine type of your instance, then you can't enable the Vertex AI integration in Cloud SQL. Upgrade your machine type to dedicated core. For more information, see [Machine Type](https://docs.cloud.google.com/sql/docs/postgres/instance-settings.md.txt#machine-type-2ndgen). |
| Error message: `Google ML Integration is unsupported for this maintenance version. Please follow https://docs.cloud.google.com/sql/docs/postgres/self-service-maintenance to update the maintenance version of the instance.` | To enable the Vertex AI integration in Cloud SQL, the maintenance version of your instance must be `R20240130` or later. To upgrade your instance to this version, see [Self-service maintenance](https://docs.cloud.google.com/sql/docs/postgres/self-service-maintenance.md.txt). |
| Error message: `Cannot invoke ml_predict_row if 'cloudsql.enable_google_ml_integration' is off.` | The `cloudsql.enable_google_ml_integration `database flag is turned off. Cloud SQL can't integrate with Vertex AI. <br /> To turn this flag on, use the [`gcloud sql instances patch`](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/patch.md.txt) command: <br /> `gcloud sql instances patch INSTANCE_NAME --database-flags cloudsql.enable_google_ml_integration=on` <br /> Replace <var translate="no">INSTANCE_NAME</var> with the name of the primary Cloud SQL instance. |
| Error message: `Failed to connect to remote host: Connection refused.` | The integration between Cloud SQL and Vertex AI isn't enabled. To enable this integration, use the [`gcloud sql instances patch`](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/patch.md.txt) command: <br /> `gcloud sql instances patch INSTANCE_NAME --enable-google-ml-integration ` <br /> Replace <var translate="no">INSTANCE_NAME</var> with the name of the primary Cloud SQL instance. |
| Error message: `Vertex AI API has not been used in project PROJECT_ID before or it is disabled. Enable it by visiting /apis/api/aiplatform.googleapis.com/overview?project=PROJECT_ID then retry.` | The Vertex AI API isn't enabled. For more information on enabling this API, see [Enable database integration with Vertex AI](https://docs.cloud.google.com/sql/docs/postgres/integrate-cloud-sql-with-vertex-ai.md.txt#enable-database-integration-with-vertex-ai). |
| Error message: `Permission 'aiplatform.endpoints.predict' denied on resource.` | Vertex AI permissions aren't added to the Cloud SQL service account for the project where the Cloud SQL instance is located. For more information on adding these permissions to the service account, see [Grant the Cloud SQL service account Identity and Access Management (IAM) permissions to access Vertex AI](https://docs.cloud.google.com/sql/docs/postgres/integrate-cloud-sql-with-vertex-ai.md.txt#grant-service-account). |
| Error message: ``Publisher Model \`projects/PROJECT_ID/locations/REGION_NAME/publishers/google/models/MODEL_NAME\` not found.`` | The machine learning model or the LLM doesn't exist in Vertex AI. |
| Error message: `Resource exhausted: grpc: received message larger than max.` | The size of the request that Cloud SQL passes to Vertex AI exceeds the [gRPC](https://grpc.io/) limit of 4 MB per request. |
| Error message: `Cloud SQL attempts to send a request to Vertex AI. However, the instance is in the %s region, but the Vertex AI endpoint is in the %s region. Make sure the instance and endpoint are in the same region.` | Cloud SQL attempts to send a request to Vertex AI. However, the instance is in one region, but the Vertex AI endpoint is in a different region. To resolve this issue, both the instance and endpoint must be in the same region. |
| Error message: `The Vertex AI endpoint isn't formatted properly.` | The Vertex AI endpoint isn't formatted properly. For more information, see [Use private endpoints for online prediction](https://docs.cloud.google.com/vertex-ai/docs/predictions/using-private-endpoints). |
| Error message: `Quota exceeded for aiplatform.googleapis.com/online_prediction_requests_per_base_model with base model: textembedding-gecko.` | The number of requests that Cloud SQL passes to Vertex AI exceeds the limit of 1,500 requests per minute per region per model per project. |

## What's next

- [Work with vector embeddings](https://docs.cloud.google.com/sql/docs/postgres/generate-manage-vector-embeddings.md.txt)

<!-- -->

- [Invoke online predictions from Cloud SQL instances](https://docs.cloud.google.com/sql/docs/postgres/invoke-online-predictions.md.txt)

- [Understand an example of an embedding workflow](https://docs.cloud.google.com/sql/docs/postgres/understand-example-embedding-workflow.md.txt)

- [Build LLM-powered applications using LangChain](https://docs.cloud.google.com/sql/docs/postgres/langchain.md.txt)