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
Required parameters
- 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.
Optional parameters
- spannerHost: The Spanner endpoint to call in the template. The default value is https://batch-spanner.googleapis.com. For example, https://batch-spanner.googleapis.com.
- spannerVersionTime: 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 (https://cloud.google.com/spanner/docs/timestamp-bounds#maximum_timestamp_staleness) applies. If not set, a strong bound (https://cloud.google.com/spanner/docs/timestamp-bounds#strong) is used to read the latest data. Defaults toempty. For example,1990-12-31T23:59:60Z.
- spannerDataBoostEnabled: 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 (https://cloud.google.com/spanner/docs/databoost/databoost-overview). Defaults to:false.
- spannerPriority: The request priority for Spanner calls. The allowed values are HIGH,MEDIUM, andLOW. The default value isMEDIUM.
Run the template
Console
- Go to the Dataflow Create job from template page. Go to Create job from template
- In the Job name field, enter a unique job name.
- Optional: For Regional endpoint, select a value from the drop-down menu. The default
    region is us-central1.For a list of regions where you can run a Dataflow job, see Dataflow locations. 
- From the Dataflow template drop-down menu, select the Spanner to Vertex AI Vector Search files on Cloud Storage template.
- In the provided parameter fields, enter your parameter values.
- 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: - latestto use the latest version of the template, which is available in the non-dated parent folder in the bucket— gs://dataflow-templates-REGION_NAME/latest/
- the version name, like 2023-09-12-00_RC00, to use a specific version of the template, which can be found nested in the respective dated parent folder in the bucket— gs://dataflow-templates-REGION_NAME/
 
- REGION_NAME: the region 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: - latestto use the latest version of the template, which is available in the non-dated parent folder in the bucket— gs://dataflow-templates-REGION_NAME/latest/
- the version name, like 2023-09-12-00_RC00, to use a specific version of the template, which can be found nested in the respective dated parent folder in the bucket— gs://dataflow-templates-REGION_NAME/
 
- LOCATION: the region 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
- Learn about Dataflow templates.
- See the list of Google-provided templates.