शुरू करेंमुफ़्त में शुरू करें

चंकिंग के लिए एक फंक्शन परिभाषित करना

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))
कोड संपादित करें और चलाएँ