チャンクに分けてアップサートをバッチ処理する
この演習では、'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 件ずつのバッチで'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(____)