コレクション

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_idmovies に設定し、次の内容を JSON リクエスト本文の一部としてリクエストします。

  1. data_schema - データ オブジェクトの構造を指定します。

  2. 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'

次のステップ