การ upsert เป็น batch ด้วย chunk
ในแบบฝึกหัดนี้ จะได้ฝึกนำเข้าเวกเตอร์ลงใน Pinecone index ชื่อ 'datacamp-index' ทีละ batch ตามลำดับ
ฟังก์ชันช่วยเหลือ chunks() ที่สร้างไว้ในแบบฝึกหัดก่อนหน้านี้พร้อมใช้งานแล้ว:
def chunks(iterable, batch_size=100):
"""A helper function to break an iterable into chunks of size batch_size."""
it = iter(iterable)
chunk = tuple(itertools.islice(it, batch_size))
while chunk:
yield chunk
chunk = tuple(itertools.islice(it, batch_size))
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Vector Databases สำหรับ Embeddings ด้วย Pinecone
คำแนะนำการฝึกหัด
- เชื่อมต่อ Pinecone ด้วย API key ของคุณ
- Upsert เวกเตอร์ใน
vectorsครั้งละ 100 ตัวลงใน'datacamp-index' - แสดงสถิติเชิงพรรณนาจาก index นี้
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Initialize the Pinecone client with your API key
pc = Pinecone(api_key="____")
index = pc.Index('datacamp-index')
# Upsert vectors in batches of 100
for chunk in ____:
____
# Retrieve statistics of the connected Pinecone index
print(____)