Spanner to Vertex AI Vector Search template

The template for Spanner to Vertex AI Vector Search files on Cloud Storage creates a batch pipeline that exports vector embeddings data from a Spanner table to Cloud Storage in JSON format. Use template parameters to specify the Cloud Storage folder to export the vector embeddings to. The Cloud Storage folder contains the list of exported .json files, which represent the vector embeddings in a format supported by the Vertex AI Vector Search index.

For more information, see Input data format and structure.

Pipeline requirements

  • The Spanner database must exist.
  • The Cloud Storage bucket for outputting data must exist.
  • In addition to the Identity and Access Management (IAM) roles necessary to run Dataflow jobs, you need the required IAM roles for reading your Spanner data and writing to your Cloud Storage bucket.

Template parameters

Parameter Description
spannerProjectId The project ID of the Spanner instance.
spannerInstanceId The ID of the Spanner instance to export the vector embeddings from.
spannerDatabaseId The ID of the Spanner database to export the vector embeddings from.
spannerTable The Spanner table to read from.
spannerColumnsToExport A comma-separated list of required columns for the Vertex AI Vector Search index. The id and embedding columns are required by Vector Search. If your column names don't match the Vertex AI Vector Search index input structure, create column mappings by using aliases. If the column names don't match the format expected by Vertex AI, use the notation from:to. For example, if you have columns named id and my_embedding, specify id, my_embedding:embedding.
gcsOutputFolder The Cloud Storage folder to write output files to. The path must end with a slash. For example: gs://your-bucket/folder1/.
gcsOutputFilePrefix The filename prefix for writing output files. For example: vector-embeddings.
spannerHost Optional: The Spanner endpoint to call in the template. The default value is https://batch-spanner.googleapis.com.
spannerVersionTime Optional: If set, specifies the time when the database version must be taken. The value is a string in the RFC-3339 date format in Unix epoch time. For example: 1990-12-31T23:59:60Z. The timestamp must be in the past, and maximum timestamp staleness applies. If not set, a strong bound is used to read the latest data. Defaults to empty.
spannerDataBoostEnabled Optional: When set to true, the template uses Spanner on-demand compute. The export job runs on independent compute resources that don't impact current Spanner workloads. Using this option incurs additional charges in Spanner. For more information, see Spanner Data Boost overview. Defaults to: false.
spannerPriority Optional: The request priority for Spanner calls. The allowed values are HIGH, MEDIUM, and LOW. The default value is MEDIUM.

Run the template

Console

  1. Go to the Dataflow Create job from template page.
  2. Go to Create job from template
  3. In the Job name field, enter a unique job name.
  4. Optional: For Regional endpoint, select a value from the drop-down menu. The default regional endpoint is us-central1.

    For a list of regions where you can run a Dataflow job, see Dataflow locations.

  5. From the Dataflow template drop-down menu, select the Spanner to Vertex AI Vector Search files on Cloud Storage template.
  6. In the provided parameter fields, enter your parameter values.
  7. Click Run job.

gcloud

In your shell or terminal, run the template:

gcloud dataflow jobs run JOB_NAME \
    --gcs-location=gs://dataflow-templates-REGION_NAME/VERSION/Cloud_Spanner_vectors_to_Cloud_Storage \
    --project=PROJECT_ID \
    --region=REGION_NAME \
    --parameters \
       spannerProjectId=SPANNER_PROJECT_ID,\
       spannerInstanceId=SPANNER_INSTANCE_ID,\
       spannerDatabaseId=SPANNER_DATABASE_ID,\
       spannerTable=SPANNER_TABLE,\
       spannerColumnsToExport=SPANNER_COLUMNS_TO_EXPORT,\
       gcsOutputFolder=GCS_OUTPUT_FOLDER,\
       gcsOutputFilePrefix=GCS_OUTPUT_FILE_PREFIX,\

Replace the following:

  • JOB_NAME: a unique job name of your choice
  • VERSION: the version of the template that you want to use

    You can use the following values:

  • REGION_NAME: the regional endpoint where you want to deploy your Dataflow job—for example, us-central1
  • SPANNER_PROJECT_ID: the Spanner project ID
  • SPANNER_INSTANCE_ID: the Spanner instance ID
  • SPANNER_DATABASE_ID: the Spanner database ID
  • SPANNER_TABLE: the Spanner table
  • SPANNER_COLUMNS_TO_EXPORT: the columns to export from the Spanner table
  • GCS_OUTPUT_FOLDER: the Cloud Storage folder to output files to
  • GCS_OUTPUT_FILE_PREFIX: the output files prefix in Cloud Storage

API

To run the template using the REST API, send an HTTP POST request. For more information on the API and its authorization scopes, see projects.templates.launch.

POST https://dataflow.googleapis.com/v1b3/projects/PROJECT_ID/locations/LOCATION/templates:launch?gcsPath=gs://dataflow-templates-LOCATION/VERSION/Cloud_Spanner_vectors_to_Cloud_Storage
{
   "jobName": "JOB_NAME",
   "parameters": {
     "spannerProjectId": "SPANNER_PROJECT_ID",
     "spannerInstanceId": "SPANNER_INSTANCE_ID",
     "spannerDatabaseId": "SPANNER_DATABASE_ID",
     "spannerTable": "SPANNER_TABLE",
     "spannerColumnsToExport": "SPANNER_COLUMNS_TO_EXPORT",
     "gcsOutputFolder": "GCS_OUTPUT_FOLDER",
     "gcsOutputFilePrefix": "GCS_OUTPUT_FILE_PREFIX",
   },
   "environment": { "maxWorkers": "10" }
}

Replace the following:

  • PROJECT_ID: the Google Cloud project ID where you want to run the Dataflow job
  • JOB_NAME: a unique job name of your choice
  • VERSION: the version of the template that you want to use

    You can use the following values:

  • LOCATION: the regional endpoint where you want to deploy your Dataflow job—for example, us-central1
  • SPANNER_PROJECT_ID: the Spanner project ID
  • SPANNER_INSTANCE_ID: the Spanner instance ID
  • SPANNER_DATABASE_ID: the Spanner database ID
  • SPANNER_TABLE: the Spanner table
  • SPANNER_COLUMNS_TO_EXPORT: the columns to export from the Spanner table
  • GCS_OUTPUT_FOLDER: the Cloud Storage folder to output files to
  • GCS_OUTPUT_FILE_PREFIX: the output files prefix in Cloud Storage

What's next