以區塊批次 upsert
在這個練習中,你會練習將向量分批寫入 'datacamp-index' 這個 Pinecone 索引中。
你在前一個練習建立的 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))
本練習屬於課程
使用 Pinecone 構建 AI 應用
練習說明
- 使用你的 API 金鑰初始化 Pinecone 連線。
- 將
vectors中的向量以每批 100 筆的方式 upsert 到'datacamp-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(____)