Chroma 外掛程式

Chroma 外掛程式提供的索引工具和擷取工具實作會在用戶端/伺服器模式下使用 Chroma 向量資料庫。

安裝項目

npm i --save genkitx-chromadb

設定

如要使用這個外掛程式,請在呼叫 configureGenkit() 時指定外掛程式:

import { chroma } from 'genkitx-chromadb';

export default configureGenkit({
  plugins: [
    chroma([
      {
        collectionName: 'bob_collection',
        embedder: textEmbeddingGecko,
      },
    ]),
  ],
  // ...
});

您必須指定 Chroma 集合和要使用的嵌入模型。此外,還有兩個選用參數:

  • clientParams:如果您未在 Genkit 流程所在的機器上執行 Chroma 伺服器,就必須指定驗證選項,或是指定驗證選項,或是指定不執行預設的 Chroma 伺服器設定,可以指定 Chroma ChromaClientParams 物件以傳遞至 Chroma 用戶端:

    clientParams: {
      path: "http://192.168.10.42:8000",
    }
    
  • embedderOptions:請使用這個參數將選項傳遞至嵌入程式:

    embedderOptions: { taskType: 'RETRIEVAL_DOCUMENT' },
    

用量

匯入擷取器和索引工具參照,如下所示:

import { chromaRetrieverRef } from 'genkitx-chromadb';
import { chromaIndexerRef } from 'genkitx-chromadb';

接著,請將參照傳遞至 retrieve()index()

// To use the index you configured when you loaded the plugin:
let docs = await retrieve({ retriever: chromaRetrieverRef, query });

// To specify an index:
export const bobFactsRetriever = chromaRetrieverRef({
  collectionName: 'bob-facts',
});
docs = await retrieve({ retriever: bobFactsRetriever, query });
// To use the index you configured when you loaded the plugin:
await index({ indexer: chromaIndexerRef, documents });

// To specify an index:
export const bobFactsIndexer = chromaIndexerRef({
  collectionName: 'bob-facts',
});
await index({ indexer: bobFactsIndexer, documents });

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