Chroma 插件

Chroma 插件提供在客户端/服务器模式下使用 Chroma 矢量数据库的索引器和检索器实现。

安装

npm i --save genkitx-chromadb

配置

如需使用此插件,请在调用 configureGenkit() 时指定该插件:

import { chroma } from 'genkitx-chromadb';

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

您必须指定色度集合和要使用的嵌入模型。此外,还有两个可选参数:

  • clientParams:如果您并未在 Genkit 流程的计算机上运行 Chroma 服务器,则需要指定身份验证选项,或者您没有运行默认的 Chroma 服务器配置,则可以指定要传递给 Chroma 客户端的 Chroma ChromaClientParams 对象

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

请参阅检索增强的生成页面,查看有关索引器和检索器的一般性讨论。