Skip to Content
リファレンスRAGPineconeVector

Pinecone Vector Store

PineconeVector クラスは、Pinecone のベクターデータベースへのインターフェースを提供します。 ハイブリッド検索、メタデータフィルタリング、ネームスペース管理などの機能を備えたリアルタイムベクター検索を提供します。

コンストラクタオプション

apiKey:

string
Pinecone APIキー

environment:

string
Pinecone環境(例: "us-west1-gcp")

メソッド

createIndex()

indexName:

string
作成するインデックスの名前

dimension:

number
ベクトルの次元(埋め込みモデルに一致する必要があります)

metric?:

'cosine' | 'euclidean' | 'dotproduct'
= cosine
類似性検索のための距離メトリック。ハイブリッド検索を使用する予定の場合は 'dotproduct' を使用します。

upsert()

indexName:

string
Pinecone インデックスの名前

vectors:

number[][]
密な埋め込みベクトルの配列

sparseVectors?:

{ indices: number[], values: number[] }[]
ハイブリッド検索用のスパースベクトルの配列。各ベクトルは一致するインデックスと値の配列を持つ必要があります。

metadata?:

Record<string, any>[]
各ベクトルのメタデータ

ids?:

string[]
オプションのベクトルID(提供されない場合は自動生成されます)

namespace?:

string
ベクトルを保存するためのオプションの名前空間。異なる名前空間のベクトルは互いに分離されています。

query()

indexName:

string
クエリを実行するインデックスの名前

vector:

number[]
類似ベクトルを見つけるための密なクエリベクトル

sparseVector?:

{ indices: number[], values: number[] }
ハイブリッド検索用のオプションのスパースベクトル。インデックスと値の配列が一致している必要があります。

topK?:

number
= 10
返す結果の数

filter?:

Record<string, any>
クエリのメタデータフィルター

includeVector?:

boolean
= false
結果にベクトルを含めるかどうか

namespace?:

string
クエリを実行するベクトルのオプションの名前空間。指定された名前空間からのみ結果を返します。

listIndexes()

文字列としてインデックス名の配列を返します。

describeIndex()

indexName:

string
説明するインデックスの名前

返される内容:

interface IndexStats { dimension: number; count: number; metric: "cosine" | "euclidean" | "dotproduct"; }

deleteIndex()

indexName:

string
削除するインデックスの名前

updateIndexById()

indexName:

string
ベクトルを含むインデックスの名前

id:

string
更新するベクトルのID

update:

object
更新パラメータ

update.vector?:

number[]
更新する新しいベクトル値

update.metadata?:

Record<string, any>
更新する新しいメタデータ

deleteIndexById()

indexName:

string
ベクトルを含むインデックスの名前

id:

string
削除するベクトルのID

レスポンスタイプ

クエリ結果はこの形式で返されます:

interface QueryResult { id: string; score: number; metadata: Record<string, any>; vector?: number[]; // Only included if includeVector is true }

エラーハンドリング

ストアは型付きエラーをスローし、キャッチすることができます:

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); // 追加のエラーコンテキスト } }

環境変数

必要な環境変数:

  • PINECONE_API_KEY: あなたのPinecone APIキー
  • PINECONE_ENVIRONMENT: Pinecone環境(例: ‘us-west1-gcp’)

ハイブリッド検索

Pineconeは、密ベクトルとスパースベクトルを組み合わせることでハイブリッド検索をサポートします。ハイブリッド検索を使用するには:

  1. metric: 'dotproduct'でインデックスを作成します
  2. アップサート時に、sparseVectorsパラメータを使用してスパースベクトルを提供します
  3. クエリ時に、sparseVectorパラメータを使用してスパースベクトルを提供します

関連