ปลั๊กอิน 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 });

ดูการพูดคุยทั่วไปเกี่ยวกับเครื่องมือจัดทำดัชนีและรีทรีฟเวอร์ในหน้า Retrieval-augmented Generation