Pinecone 外掛程式

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。有兩種方式可以協助您測試:

  • 設定 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 });

如需索引器和擷取器的一般討論,請參閱「擷取增強產生作業」頁面。