ปลั๊กอิน Pinecone

ปลั๊กอิน Pinecone จะมีการติดตั้งใช้งานตัวจัดทำดัชนีและรีทรีฟเวอร์ที่ใช้ฐานข้อมูลเวกเตอร์ระบบคลาวด์ของ Pinecone

การติดตั้ง

npm i --save genkitx-pinecone

การกำหนดค่า

หากต้องการใช้ปลั๊กอินนี้ ให้ระบุเมื่อเรียกใช้ configureGenkit():

import { pinecone } from 'genkitx-pinecone';

export default configureGenkit({
  plugins: [
    pinecone([
      {
        indexId: 'bob-facts',
        embedder: textEmbeddingGecko,
      },
    ]),
  ],
  // ...
});

คุณต้องระบุรหัสดัชนีของ Pinecone และโมเดลการฝังที่ต้องการใช้

นอกจากนี้ คุณต้องกำหนดค่า Genkit ด้วยคีย์ Pinecone API ทำได้ 2 วิธีดังนี้

  • ตั้งค่าตัวแปรสภาพแวดล้อม PINECONE_API_KEY

  • ให้ระบุในพารามิเตอร์ที่ไม่บังคับ clientParams ดังนี้

    clientParams: {
      apiKey: ...,
    }
    

    ค่าของพารามิเตอร์นี้คือออบเจ็กต์ PineconeConfiguration ซึ่งส่งต่อไปยังไคลเอ็นต์ Pinecone ซึ่งคุณจะใช้ค่าดังกล่าวเพื่อส่งพารามิเตอร์ใดก็ได้ที่ไคลเอ็นต์รองรับ

การใช้งาน

นำเข้าการอ้างอิงรีทรีฟเวอร์และตัวจัดทำดัชนีดังนี้

import { pineconeRetrieverRef } from 'genkitx-pinecone';
import { pineconeIndexerRef } from 'genkitx-pinecone';

จากนั้น ส่งการอ้างอิงไปยัง retrieve() และ index():

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

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

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

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