Collections

In Vector Search 2.0, Collections are used to store related Data Objects. They provide a source of truth that you can query to determine the exact state of the Data Objects they contain.

Collection Schema

When you create a Collection, you must provide the following JSON schemas:

  • A data schema, which provides the user-defined structure of your data.

  • A vector schema that defines and configures the vector fields for your Data Objects.

Together, these are referred to as the Collection Schema.

Creating a Collection

The following example demonstrates how to create a Collection with the ID movies, specifying both a data schema and a vector schema.

curl -X POST \
  'https://vectorsearch.googleapis.com/v1beta/projects/PROJECT_ID/locations/LOCATION/collections?collection_id=movies' \
  -H 'Bearer $(gcloud auth print-access-token)' \
  -H 'Content-Type: application/json' \
  -d '{  \
    "data_schema": { \
      "type": "object", \
      "properties": { \
        "year": { \
          "type": "number" \
        }, \
        "genre": { \
          "type": "string" \
        }, \
        "director": { \
          "type": "string" \
        }, \
        "title": { \
          "type": "string" \
        } \
      } \
    }, \
    "vector_schema": { \
      "plot_embedding": { \
        "dense_vector": { \
          "dimensions": 3 \
        } \
      }, \
      "soundtrack_embedding": { \
        "dense_vector": { \
          "dimensions": 5 \
        } \
      }, \
      "genre_embedding": { \
        "dense_vector": { \
          "dimensions": 4 \
        } \
      }, \
      "sparse_embedding": { \
        "sparse_vector": {} \
      } \
    } \
  }'

In the example, a request is made with collection_id set to movies and the following as part of the JSON request body:

  1. data_schema - Specifies the Data Object structure.

  2. vector_schema - Configures and defines the vector fields.

Getting a Collection

The following example demonstrates how to get a reference to an existing Collection with the ID movies.

curl -X GET \
'https://vectorsearch.googleapis.com/v1beta/projects/PROJECT_ID/locations/LOCATION/collections/movies' \
    -H 'Bearer $(gcloud auth print-access-token)' \
    -H 'Content-Type: application/json'

Listing Collections

The following example demonstrates how to retrieve a list of existing Collections.

curl -X GET \
'https://vectorsearch.googleapis.com/v1beta/projects/PROJECT_ID/locations/LOCATION/collections' \
    -H 'Bearer $(gcloud auth print-access-token)' \
    -H 'Content-Type: application/json'

Deleting a Collection

The following example demonstrates how to delete an existing Collection with the ID movies.

curl -X DELETE \
'https://vectorsearch.googleapis.com/v1beta/projects/PROJECT_ID/locations/us-central1/collections/movies' \
    -H 'Bearer $(gcloud auth print-access-token)' \
    -H 'Content-Type: application/json'

What's next?