การดึงเวกเตอร์ด้วย Fetch
ในแบบฝึกหัดนี้ มีลิสต์ ids ที่เก็บ ID ของเรกคอร์ดต่างๆ ใน index 'datacamp-index' ให้แล้ว จะได้ใช้ ID เหล่านี้เพื่อดึงเรกคอร์ดที่เกี่ยวข้องและสำรวจ metadata ของแต่ละรายการ
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Vector Databases สำหรับ Embeddings ด้วย Pinecone
คำแนะนำการฝึกหัด
- เริ่มต้นการเชื่อมต่อกับ Pinecone ด้วย API key ของคุณ
- ดึงเวกเตอร์ที่มี ID ตามลิสต์
idsจาก index ที่เชื่อมต่อไว้ - สร้างลิสต์ของ dictionary ที่เก็บข้อมูล metadata จากแต่ละเรกคอร์ดใน
fetched_vectors
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Initialize the Pinecone client with your API key
pc = Pinecone(api_key="____")
index = pc.Index('datacamp-index')
ids = ['2', '5', '8']
# Fetch the vectors from the connected Pinecone index
fetched_vectors = ____
# Extract the metadata from each result in fetched_vectors
metadatas = [fetched_vectors['____'][____]['____'] for id in ids]
print(metadatas)