ปลั๊กอินโครมา

ปลั๊กอิน Chroma มีการติดตั้งใช้งานโปรแกรมจัดทำดัชนีและรีทรีฟเวอร์ที่ใช้ ฐานข้อมูลเวกเตอร์ของ Chrome ในโหมดไคลเอ็นต์/เซิร์ฟเวอร์

การติดตั้ง

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 เริ่มต้น คุณสามารถระบุ 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 });

ดูหน้าการสร้างและดึงข้อมูลสำหรับข้อมูลทั่วไป เรื่องโปรแกรมจัดทำดัชนีและรีทรีฟเวอร์