> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # Cloudflare vector store CloudflareVector クラスは、Cloudflare のエッジネットワークと統合されたベクトルデータベースサービス [Cloudflare Vectorize](https://developers.cloudflare.com/vectorize/) を使用したベクトル検索を提供します。 ## コンストラクターオプション **accountId** (`string`): Cloudflare アカウント ID **apiToken** (`string`): Vectorize 権限を持つ Cloudflare API トークン ## メソッド ### `createIndex()` **indexName** (`string`): 作成するインデックスの名前 **dimension** (`number`): ベクトルの次元数(埋め込みモデルと一致させる必要があります) **metric** (`'cosine' | 'euclidean' | 'dotproduct'`): 類似度検索の距離指標(dotproduct は dot-product に対応します) (Default: `cosine`) ### `upsert()` **indexName** (`string`): upsert 先のインデックス名 **vectors** (`number[][]`): 埋め込みベクトルの配列 **metadata** (`Record[]`): 各ベクトルのメタデータ **ids** (`string[]`): 省略可能なベクトル ID(未指定の場合は自動生成されます) ### `query()` **indexName** (`string`): クエリ対象のインデックス名 **queryVector** (`number[]`): 類似ベクトルを検索するためのクエリベクトル **topK** (`number`): 返す結果の数 (Default: `10`) **filter** (`Record`): クエリのメタデータフィルター **includeVector** (`boolean`): 結果にベクトルを含めるかどうか (Default: `false`) ### `listIndexes()` インデックス名を文字列の配列として返します。 ### `describeIndex()` **indexName** (`string`): 詳細を取得するインデックスの名前 戻り値: ```typescript interface IndexStats { dimension: number count: number metric: 'cosine' | 'euclidean' | 'dotproduct' } ``` ### `deleteIndex()` **indexName** (`string`): 削除するインデックスの名前 ### `createMetadataIndex()` フィルターを有効にするため、メタデータフィールドにインデックスを作成します。 **indexName** (`string`): メタデータフィールドを含むインデックスの名前 **propertyName** (`string`): インデックスを作成するメタデータフィールドの名前 **indexType** (`'string' | 'number' | 'boolean'`): メタデータフィールドの型 ### `deleteMetadataIndex()` メタデータフィールドからインデックスを削除します。 **indexName** (`string`): メタデータフィールドを含むインデックスの名前 **propertyName** (`string`): インデックスを削除するメタデータフィールドの名前 ### `listMetadataIndexes()` インデックスに含まれるすべてのメタデータフィールドインデックスを一覧表示します。 **indexName** (`string`): メタデータインデックスを一覧表示するインデックスの名前 ### `updateVector()` インデックス内の特定の ID に対応するベクトルまたはメタデータを更新します。 **indexName** (`string`): 更新する ID を含むインデックスの名前 **id** (`string`): 更新するベクトルまたはメタデータの一意な識別子 **update** (`{ vector?: number[]; metadata?: Record; }`): 更新するベクトルやメタデータを含むオブジェクト ### `deleteVector()` インデックス内の特定の ID に対応するベクトルと関連メタデータを削除します。 **indexName** (`string`): 削除する ID を含むインデックスの名前 **id** (`string`): 削除するベクトルとメタデータの一意な識別子 ## レスポンス型 クエリ結果は次の形式で返されます。 ```typescript interface QueryResult { id: string score: number metadata: Record vector?: number[] } ``` ## エラー処理 store は捕捉可能な型付きエラーをスローします。 ```typescript 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 アカウント ID - `CLOUDFLARE_API_TOKEN`: Vectorize 権限を持つ Cloudflare API トークン ## 関連情報 - [メタデータフィルター](https://mastra.zisheng.pro/ja/reference/rag/metadata-filters)