在 Vector Search 2.0 中,集合用于存储相关的数据对象。它们提供了一个可供查询的真实来源,以确定其中包含的数据对象的准确状态。
集合架构
创建集合时,您必须提供以下 JSON 架构:
数据架构,用于提供用户定义的数据结构。
一种向量架构,用于定义和配置数据对象的向量字段。
这些属性统称为集合架构。
创建集合
以下示例演示了如何创建 ID 为 movies 的集合,同时指定数据架构和矢量架构。
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": {} \
} \
} \
}'
在此示例中,请求的 collection_id 设置为 movies,并且 JSON 请求正文包含以下内容:
data_schema- 指定数据对象结构。vector_schema- 配置并定义向量字段。
获取集合
以下示例演示了如何获取对 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'
列出集合
以下示例演示了如何检索现有集合的列表。
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'
删除集合
以下示例演示了如何删除 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'