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 COLLECTION_ID , 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= COLLECTION_ID 
' \ 
 -H "Authorization: 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 COLLECTION_ID 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 COLLECTION_ID .

  curl -X GET \ 
 'https://vectorsearch.googleapis.com/v1beta/projects/ PROJECT_ID 
/locations/ LOCATION 
/collections/ COLLECTION_ID 
' \ 
 -H "Authorization: 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 "Authorization: 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 COLLECTION_ID .

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

What's next?

Create a Mobile Website
View Site in Mobile | Classic
Share by: