Skip to Content
リファレンスRAGPineconeVector

Pinecone ベクターストア

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
削除するインデックスの名前

updateVector()

indexName:

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

id:

string
更新するベクトルのID

update:

object
更新パラメータ

update.vector?:

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

update.metadata?:

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

deleteVector()

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); // Additional error context } }

環境変数

必要な環境変数:

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

ハイブリッド検索

Pineconeは、密ベクトルと疎ベクトルを組み合わせることでハイブリッド検索をサポートしています。ハイブリッド検索を利用するには、以下の手順に従ってください。

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

関連