按分块批量 upsert
在本练习中,您将练习将向量按批次顺序写入 Pinecone 的 'datacamp-index' 索引。
上一练习中您创建的 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(____)