Upserts को बैच करना

Pinecone के साथ AI Applications बनाना

James Chapman

Curriculum Manager, DataCamp

Upserting की सीमाएँ

 

  1. रिक्वेस्ट की Rate
  2. रिक्वेस्ट का Size

 

  • Batching: रिक्वेस्ट्स को छोटे chunks में तोड़ना

 

Pinecone rate limits

1 https://docs.pinecone.io/reference/quotas-and-limits#rate-limits
Pinecone के साथ AI Applications बनाना

Chunking फंक्शन परिभाषित करना

def chunks(iterable, batch_size=100):

it = iter(iterable)
chunk = tuple(itertools.islice(it, batch_size))
while chunk:
yield chunk
chunk = tuple(itertools.islice(it, batch_size))
Pinecone के साथ AI Applications बनाना

Sequential batching

  • रिक्वेस्ट्स को बाँटना और उन्हें one-by-one क्रम से भेजना
pc.Pinecone(api_key="YOUR API KEY")
index = pc.Index('datacamp-index')


for chunk in chunks(vectors): index.upsert(vectors=chunk)

Pros:

  • Rate और size limits हल हो जाते हैं

Cons:

  • बहुत धीमा!
Pinecone के साथ AI Applications बनाना

Parallel batching

  • रिक्वेस्ट्स को बाँटना और उन्हें parallel में भेजना
pc = Pinecone(api_key="YOUR_API_KEY", pool_threads=30)


with pc.Index('datacamp-index', pool_threads=30) as index:
async_results = [index.upsert(vectors=chunk, async_req=True) for chunk in chunks(vectors, batch_size=100)]
[async_result.get() for async_result in async_results]
Pinecone के साथ AI Applications बनाना

अभ्यास करते हैं!

Pinecone के साथ AI Applications बनाना

Preparing Video For Download...