ปลั๊กอิน Chroma ให้บริการตัวจัดทำดัชนีและการติดตั้งใช้งานรีทรีฟเวอร์ที่ใช้ฐานข้อมูลเวกเตอร์ Chroma ในโหมดไคลเอ็นต์/เซิร์ฟเวอร์
การติดตั้ง
npm i --save genkitx-chromadb
การกำหนดค่า
หากต้องการใช้ปลั๊กอินนี้ ให้ระบุปลั๊กอินเมื่อเรียกใช้ configureGenkit()
:
import { chroma } from 'genkitx-chromadb';
export default configureGenkit({
plugins: [
chroma([
{
collectionName: 'bob_collection',
embedder: textEmbeddingGecko,
},
]),
],
// ...
});
คุณต้องระบุคอลเล็กชัน Chrome และโมเดลการฝังที่ต้องการใช้ นอกจากนี้ มีพารามิเตอร์ที่ไม่บังคับ 2 แบบ ได้แก่
clientParams
: หากไม่ได้เรียกใช้เซิร์ฟเวอร์ Chroma ในเครื่องเดียวกันกับโฟลว์ Genkit คุณจะต้องระบุตัวเลือกการตรวจสอบสิทธิ์ มิเช่นนั้น ไม่ได้เรียกใช้การกำหนดค่าเซิร์ฟเวอร์ 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 });
ดูการพูดคุยทั่วไปเกี่ยวกับเครื่องมือจัดทำดัชนีและรีทรีฟเวอร์ในหน้า Retrieval-augmented Generation