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

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. (Example: gs://your-bucket/folder1/).
  • gcsOutputFilePrefix : The filename prefix for writing output files. (Example: vector-embeddings).

Optional parameters

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 region 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 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:

  • 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