चंकिंग के लिए एक फंक्शन परिभाषित करना
Upserts को दोहराने योग्य तरीके से batch करने के लिए, आपको अपने वेक्टरों की सूची को chunks में बाँटने वाला एक फंक्शन परिभाषित करना होगा.
बिल्ट-इन itertools मॉड्यूल पहले से आपके लिए इम्पोर्ट किया गया है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Pinecone के साथ AI Applications बनाना
अभ्यास निर्देश
iterableइनपुट को एक iterator में बदलें.itertoolsमॉड्यूल का उपयोग करकेitकोbatch_sizeआकार के chunks में slice करें.- वर्तमान chunk को yield करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
def chunks(iterable, batch_size=100):
"""A helper function to break an iterable into chunks of size batch_size."""
# Convert the iterable into an iterator
it = ____
# Slice the iterator into chunks of size batch_size
chunk = tuple(itertools.____(it, ____))
while chunk:
# Yield the chunk
____
chunk = tuple(itertools.islice(it, batch_size))