Cloudflare vector store
CloudflareVector クラスは、Cloudflare のエッジネットワークと統合されたベクトルデータベースサービス Cloudflare Vectorize を使用したベクトル検索を提供します。
コンストラクターオプションコンストラクターオプションへの直接リンク
accountId:
string
Cloudflare アカウント ID
apiToken:
string
Vectorize 権限を持つ Cloudflare API トークン
メソッドメソッドへの直接リンク
createIndex()createindexへの直接リンク
indexName:
string
作成するインデックスの名前
dimension:
number
ベクトルの次元数(埋め込みモデルと一致させる必要があります)
metric?:
'cosine' | 'euclidean' | 'dotproduct'
= cosine
類似度検索の距離指標(dotproduct は dot-product に対応します)
upsert()upsertへの直接リンク
indexName:
string
upsert 先のインデックス名
vectors:
number[][]
埋め込みベクトルの配列
metadata?:
Record<string, any>[]
各ベクトルのメタデータ
ids?:
string[]
省略可能なベクトル ID(未指定の場合は自動生成されます)
query()queryへの直接リンク
indexName:
string
クエリ対象のインデックス名
queryVector:
number[]
類似ベクトルを検索するためのクエリベクトル
topK?:
number
= 10
返す結果の数
filter?:
Record<string, any>
クエリのメタデータフィルター
includeVector?:
boolean
= false
結果にベクトルを含めるかどうか
listIndexes()listindexesへの直接リンク
インデックス名を文字列の配列として返します。
describeIndex()describeindexへの直接リンク
indexName:
string
詳細を取得するインデックスの名前
戻り値:
interface IndexStats {
dimension: number
count: number
metric: 'cosine' | 'euclidean' | 'dotproduct'
}
deleteIndex()deleteindexへの直接リンク
indexName:
string
削除するインデックスの名前
createMetadataIndex()createmetadataindexへの直接リンク
フィルターを有効にするため、メタデータフィールドにインデックスを作成します。
indexName:
string
メタデータフィールドを含むインデックスの名前
propertyName:
string
インデックスを作成するメタデータフィールドの名前
indexType:
'string' | 'number' | 'boolean'
メタデータフィールドの型
deleteMetadataIndex()deletemetadataindexへの直接リンク
メタデータフィールドからインデックスを削除します。
indexName:
string
メタデータフィールドを含むインデックスの名前
propertyName:
string
インデックスを削除するメタデータフィールドの名前
listMetadataIndexes()listmetadataindexesへの直接リンク
インデックスに含まれるすべてのメタデータフィールドインデックスを一覧表示します。
indexName:
string
メタデータインデックスを一覧表示するインデックスの名前
updateVector()updatevectorへの直接リンク
インデックス内の特定の ID に対応するベクトルまたはメタデータを更新します。
indexName:
string
更新する ID を含むインデックスの名前
id:
string
更新するベクトルまたはメタデータの一意な識別子
update:
{ vector?: number[]; metadata?: Record<string, any>; }
更新するベクトルやメタデータを含むオブジェクト
deleteVector()deletevectorへの直接リンク
インデックス内の特定の ID に対応するベクトルと関連メタデータを削除します。
indexName:
string
削除する ID を含むインデックスの名前
id:
string
削除するベクトルとメタデータの一意な識別子
レスポンス型レスポンス型への直接リンク
クエリ結果は次の形式で返されます。
interface QueryResult {
id: string
score: number
metadata: Record<string, any>
vector?: number[]
}
エラー処理エラー処理への直接リンク
store は捕捉可能な型付きエラーをスローします。
try {
await store.query({
indexName: 'index_name',
queryVector: queryVector,
})
} catch (error) {
if (error instanceof VectorStoreError) {
console.log(error.code) // 'connection_failed' | 'invalid_dimension' | etc
console.log(error.details) // Additional error context
}
}
環境変数環境変数への直接リンク
必要な環境変数:
CLOUDFLARE_ACCOUNT_ID: Cloudflare アカウント IDCLOUDFLARE_API_TOKEN: Vectorize 権限を持つ Cloudflare API トークン