LoginSignup
0
0

Azure AI Search のベクトル最適化を Cohere-embed-v3-multilingual モデルで検証する

Last updated at Posted at 2024-05-19

前回は Azure Machine Learning/Azure AI Studio のモデルカタログを使用して Cohere-embed-v3-multilingual をデプロイして Azure AI Search でベクトル検索を実施しました。ところで Azure AI Search は 4月4日、ベクトルストレージを最適化する以下のような新しいベクトル検索機能を追加しています。

  1. より小さいプリミティブデータ型の追加(float16, int16, int8)
  2. stored パラメータの追加によりクエリ応答に不要なベクトル領域を削減
  3. 組み込みのスカラー量子化機能を追加

今回はこれらの機能を検証します。

1. より小さいプリミティブデータ型の追加(float16, int16, int8)

Cohere-embed-v3-multilingual モデルには embedding_types パラメータで float, int8, uint8, binary, ubinary が指定できるため、通常使用する float 以外のプリミティブデータ型を使用して Embeddings を生成・格納します。

Cohere SDK

1 つ以上の embedding_types を配列で指定できます。

response = co.embed(
    texts=[text], 
    input_type=input_type,
    embedding_types=["int8"]
)
response.embeddings.int8[0] 
[
    -3,
    20,
    -25,
    ...
]

インデックス定義

int8 プリミティブデータ型を格納するためには、インデックスフィールドの型を Collection(Edm.SByte) に設定します。

{
    "name": "cohere_v3",
    "type": "Collection(Edm.SByte)",
    ...
}

参考までに、Azure AI Search に新たに追加された型は以下となります。

EDM データ型 説明 サイズ
Collection(Edm.Single) 32 ビット浮動小数点 4 byte
Collection(Edm.Half) 16 ビット浮動小数点 2 byte
Collection(Edm.Int16) 16 ビット符号付き整数 2 byte
Collection(Edm.SByte) 8 ビット符号付き整数 1 byte

2. stored パラメータの追加

ベクトルインデックス作成時にベクトルフィールドに新たに追加された stored パラメータを false に設定すると、クエリ時にベクトルデータを返却するために用意されているストレージ領域が削減されます。フィールドごとの全体的なストレージを最大 1/2 削減できます。

{
  "name": "cohere_v3",
  "type": "Collection(Edm.Single)",
  "retrievable": false,
  "stored": false,
  ...
}

後段処理などでベクトルデータ実体を使用せず、ベクトル検索処理のみが実行できればよいというユースケースにおいては、この機能が有効です。

3. 組み込みのスカラー量子化機能

自動的に float32int8 に圧縮します。これによりベクトルデータストレージを圧縮および最適化します。検索インデックス定義に vectorSearch.compressions を追加します。Pubic Preview でサポートされている圧縮アルゴリズムは int8 へのスカラー量子化です。

"compressions": [
    {
        "name": "vector-1716124629799-compressor",
        "kind": "scalarQuantization",
        "rerankWithOriginalVectors": true,
        "defaultOversampling": 4,
        "scalarQuantizationParameters": {
            "quantizedDataType": "int8"
        }
    }
]

インデックスサイズ比較

インデックス数 ベクトルインデックス ストレージ
float32 8,066 31.93 MB 139.09 MB
float32(no-stored) 8,066 31.93 MB 73.73 MB (≈1/2)
int8 8,066 8.3 MB (≈1/4) 45.88 MB
int8(compressions) 8,066 8.3 MB (≈1/4) 114.18 MB

ベクトル最適化の図解

image.png

パフォーマンス比較

精度比較

比較方法は以前と同様。

float32 int8 uint8 compressions(float32->int8)
#1 Recall@3 avg 0.652 0.668 0.663 0.652
#1 Recall@5 avg 0.786 0.786 0.790 0.781
#2 Recall@3 avg 0.686 0.696 0.696 0.686
#2 Recall@5 avg 0.817 0.813 0.819 0.817

Cohere-embed-v3-multilingual モデルの場合、compressionsfloat32->int8 にスカラー量子化するよりも、直接 embedding_types=["int8"] で生成したほうが精度が高くなっています。ただし、ここでは rerankWithOriginalVectors 機能も併用しています。

データセットで精度比較を実施して float32int8 であまり変わらないようであれば、int8 にすることでベクトルインデックスサイズを約 1/4 に削減できます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0