Gộp lô upsert theo từng chunk
Trong bài tập này, bạn sẽ luyện tập nạp vector vào chỉ mục Pinecone 'datacamp-index' theo tuần tự, từng lô một.
Hàm trợ giúp chunks() bạn đã tạo ở bài trước có sẵn để sử dụng:
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))
Bài tập này là một phần của khóa học
Cơ sở dữ liệu vector cho Embeddings với Pinecone
Hướng dẫn bài tập
- Khởi tạo kết nối Pinecone với API key của bạn.
- Upsert các vector trong
vectorstheo lô 100 vector vào'datacamp-index'. - In ra các thống kê mô tả từ chỉ mục này.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
# 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(____)