Melakukan upsert bertumpuk dalam potongan (chunks)
Dalam latihan ini, Anda akan berlatih memasukkan vektor ke indeks Pinecone 'datacamp-index' secara berurutan, per batch.
Fungsi pembantu chunks() yang Anda buat pada latihan sebelumnya tersedia untuk digunakan:
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))
Latihan ini adalah bagian dari kursus
Database Vektor untuk Embeddings dengan Pinecone
Petunjuk latihan
- Inisialisasi koneksi Pinecone dengan kunci API Anda.
- Lakukan upsert vektor dalam
vectorssecara batch berisi 100 vektor ke'datacamp-index'. - Cetak statistik deskriptif dari indeks ini.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# 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(____)