पैरलल में बैच अपसर्ट्स
इस अभ्यास में, आप '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 Applications बनाना
अभ्यास निर्देश
- Pinecone क्लाइंट को इस प्रकार इनिशियलाइज़ करें कि 20 समकालिक (simultaneous) अनुरोध संभव हों.
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(____)