업서트를 병렬로 배치 처리하기
이 연습 문제에서는 'datacamp-index' 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 애플리케이션 구축하기
연습 안내
- 동시에 20개의 요청을 허용하도록 Pinecone 클라이언트를 초기화하세요.
vectors의 벡터를 한 요청당 200개씩 배치로, 비동기적으로 업서트하고 동시에20개의 요청이 이루어지도록 구성하세요.'datacamp-index'Pinecone 인덱스의 업데이트된 메트릭을 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Initialize the client
pc = Pinecone(api_key="____", ____)
index = pc.Index('datacamp-index')
# Upsert vectors in batches of 200 vectors
with pc.Index('datacamp-index', ____) as index:
async_results = [____(vectors=chunk, ____) for chunk in chunks(vectors, batch_size=____)]
[async_result.get() for async_result in async_results]
# Retrieve statistics of the connected Pinecone index
print(____)