> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # Pinecone ベクターストア PineconeVector クラスは、[Pinecone](https://www.pinecone.io/) のベクトルデータベースへのインターフェースを提供します。 ハイブリッド検索、メタデータフィルタリング、名前空間管理などの機能を備えたリアルタイムのベクトル検索を提供します。 ## コンストラクターオプション コンストラクターは、すべての [Pinecone 設定オプション](https://docs.pinecone.io/reference/typescript-sdk) に加え、Mastra 固有のフィールドを受け取ります。 **id** (`string`): このベクターストアインスタンスの一意な識別子 **apiKey** (`string`): Pinecone API キー **controllerHostUrl** (`string`): カスタム Pinecone コントローラーホスト URL **additionalHeaders** (`Record`): リクエストに含める追加の HTTP ヘッダー **sourceTag** (`string`): リクエスト追跡用のソースタグ **cloud** (`'aws' | 'gcp' | 'azure'`): 新しいインデックスを作成するクラウドプロバイダー (Default: `aws`) **region** (`string`): 新しいインデックスを作成するリージョン (Default: `us-east-1`) ## メソッド ### `createIndex()` **indexName** (`string`): 作成するインデックスの名前 **dimension** (`number`): ベクトルの次元数(埋め込みモデルと一致させる必要があります) **metric** (`'cosine' | 'euclidean' | 'dotproduct'`): 類似検索の距離メトリクス。ハイブリッド検索を使用する場合は 'dotproduct' を指定します。 (Default: `cosine`) ### `upsert()` **indexName** (`string`): Pinecone インデックスの名前 **vectors** (`number[][]`): 密な埋め込みベクトルの配列 **sparseVectors** (`{ indices: number[], values: number[] }[]`): ハイブリッド検索用の疎ベクトルの配列。各ベクトルの indices 配列と values 配列の要素数は一致している必要があります。 **metadata** (`Record[]`): 各ベクトルのメタデータ **ids** (`string[]`): 任意のベクトル ID(指定しない場合は自動生成されます) **namespace** (`string`): ベクトルを保存する任意の名前空間。異なる名前空間のベクトルは互いに分離されます。 ### `query()` **indexName** (`string`): 検索するインデックスの名前 **queryVector** (`number[]`): 類似ベクトルを検索するための密なクエリベクトル **sparseVector** (`{ indices: number[], values: number[] }`): ハイブリッド検索用の任意の疎ベクトル。indices 配列と values 配列の要素数は一致している必要があります。 **topK** (`number`): 返す結果の数 (Default: `10`) **filter** (`Record`): クエリに適用するメタデータフィルター **includeVector** (`boolean`): 結果にベクトルを含めるかどうか (Default: `false`) **namespace** (`string`): ベクトルを検索する任意の名前空間。指定した名前空間の結果のみを返します。 ### `listIndexes()` インデックス名を文字列の配列として返します。 ### `describeIndex()` **indexName** (`string`): 詳細を取得するインデックスの名前 戻り値: ```typescript interface IndexStats { dimension: number count: number metric: 'cosine' | 'euclidean' | 'dotproduct' } ``` ### `deleteIndex()` **indexName** (`string`): 削除するインデックスの名前 ### `updateVector()` ID またはメタデータフィルターで単一のベクトルを更新します。`id` と `filter` のどちらか一方だけを指定する必要があります。 **indexName** (`string`): ベクトルを含むインデックスの名前 **id** (`string`): 更新するベクトルの ID(filter と同時に指定できません) **filter** (`Record`): 更新するベクトルを特定するメタデータフィルター(id と同時に指定できません) **namespace** (`string`): 更新操作に使用する任意の名前空間 **update** (`object`): 更新パラメーター **update.vector** (`number[]`): 更新後の新しいベクトル値 **update.metadata** (`Record`): 更新後の新しいメタデータ ### `deleteVector()` **indexName** (`string`): ベクトルを含むインデックスの名前 **id** (`string`): 削除するベクトルの ID ### `deleteVectors()` ID またはメタデータフィルターで複数のベクトルを削除します。`ids` と `filter` のどちらか一方だけを指定する必要があります。 **indexName** (`string`): 削除するベクトルを含むインデックスの名前 **ids** (`string[]`): 削除するベクトル ID の配列(filter と同時に指定できません) **filter** (`Record`): 削除するベクトルを特定するメタデータフィルター(ids と同時に指定できません) **namespace** (`string`): 削除操作に使用する任意の名前空間 ## レスポンス型 クエリ結果は次の形式で返されます。 ```typescript interface QueryResult { id: string score: number metadata: Record vector?: number[] // Only included if includeVector is true } ``` ## エラー処理 ストアはキャッチ可能な型付きエラーをスローします。 ```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 } } ``` ### 環境変数 必須の環境変数: - `PINECONE_API_KEY`: Pinecone API キー ## ハイブリッド検索 Pinecone は、密ベクトルと疎ベクトルを組み合わせたハイブリッド検索をサポートしています。ハイブリッド検索を使用する手順は次のとおりです。 1. `metric: 'dotproduct'` を指定してインデックスを作成します 2. upsert 時に `sparseVectors` パラメーターで疎ベクトルを指定します 3. クエリ時に `sparseVector` パラメーターで疎ベクトルを指定します ## 関連情報 - [メタデータフィルター](https://mastra.zisheng.pro/ja/reference/rag/metadata-filters)