Pinecone プラグインには、Pinecone クラウド ベクトル データベースを使用するインデクサとレトリーバーの実装が用意されています。
インストール
npm i --save genkitx-pinecone
設定
このプラグインを使用するには、configureGenkit()
を呼び出すときに指定します。
import { pinecone } from 'genkitx-pinecone';
export default configureGenkit({
plugins: [
pinecone([
{
indexId: 'bob-facts',
embedder: textEmbeddingGecko,
},
]),
],
// ...
});
Pinecone インデックス ID と、使用するエンベディング モデルを指定する必要があります。
また、Pinecone API キーを使用して Genkit を構成する必要があります。これには次の 2 つの方法があります。
PINECONE_API_KEY
環境変数を設定する。これは、
clientParams
オプション パラメータで指定します。clientParams: { apiKey: ..., }
このパラメータの値は
PineconeConfiguration
オブジェクトで、Pinecone クライアントに渡されます。これを使用して、クライアントがサポートする任意のパラメータを渡すことができます。
使用量
インポート レトリーバーとインデクサーの参照は次のようになります。
import { pineconeRetrieverRef } from 'genkitx-pinecone';
import { pineconeIndexerRef } from 'genkitx-pinecone';
次に、retrieve()
と index()
への参照を渡します。
// To use the index you configured when you loaded the plugin:
let docs = await retrieve({ retriever: pineconeRetrieverRef, query });
// To specify an index:
export const bobFactsRetriever = pineconeRetrieverRef({
indexId: 'bob-facts',
});
docs = await retrieve({ retriever: bobFactsRetriever, query });
// To use the index you configured when you loaded the plugin:
await index({ indexer: pineconeIndexerRef, documents });
// To specify an index:
export const bobFactsIndexer = pineconeIndexerRef({
indexId: 'bob-facts',
});
await index({ indexer: bobFactsIndexer, documents });
インデクサーと取得ツールに関する一般的な情報については、検索拡張生成のページをご覧ください。