Integrate Cloud SQL with Vertex AI

This page describes how to integrate Cloud SQL with Vertex AI. This integration lets you apply large language models (LLMs), which are hosted in Vertex AI, to a Cloud SQL for MySQL database, version 8.0.36 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 to call a model using SQL within a transaction.
  • Generate embeddings 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.

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.

    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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

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

  4. In the Google Cloud console, on 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

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

  6. Enable the necessary Google Cloud APIs.

    Console

    1. Go to the APIs & Services page.
    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 Cloud SQL Admin API and Vertex AI API.

    5. After selecting each API, click Enable.

    gcloud

  1. Open Cloud Shell, 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 \
    enable aiplatform.googleapis.com
  3. This command enables the following APIs:
    • Cloud SQL Admin API
    • Vertex AI API