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 コレクションと、使用するエンベディング モデルを指定する必要があります。さらに、次の 2 つの省略可能なパラメータがあります。

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

インデクサーと取得ツールに関する一般的な情報については、検索拡張生成のページをご覧ください。