ปลั๊กอิน 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 });
ดูหน้าการสร้างและดึงข้อมูลสำหรับข้อมูลทั่วไป เรื่องโปรแกรมจัดทำดัชนีและรีทรีฟเวอร์