1. Learn
  2. /
  3. कोर्स
  4. /
  5. OpenAI API के साथ Embeddings परिचय

Connected

अभ्यास

Enriching embeddings

पहले, जब आपने प्रोडक्ट जानकारी को embed किया था, तो आप केवल प्रोडक्ट की 'short_description' तक सीमित थे. इससे कुछ प्रासंगिक जानकारी तो मिली, लेकिन सारी नहीं. इस अभ्यास में, आप और अधिक जानकारी कैप्चर करने के लिए 'title', 'short_description', 'category', और 'features' को embed करेंगे.

यहाँ products नाम की dictionaries की list की याद दिलाई गई है:

products = [
    {
        "title": "Smartphone X1",
        "short_description": "The latest flagship smartphone with AI-powered features and 5G connectivity.",
        "price": 799.99,
        "category": "Electronics",
        "features": [
            "6.5-inch AMOLED display",
            "Quad-camera system with 48MP main sensor",
            "Face recognition and fingerprint sensor",
            "Fast wireless charging"
        ]
    },
    ...
]

जब features को एक single string में मिलाएँ, तो उसका स्ट्रक्चर इस प्रकार होना चाहिए:

Title: <product title>
Description: <product description>
Category: <product category>
Features: <feature 1>; <feature 2>; <feature 3>; ...

निर्देश

100 XP
  • create_product_text() नाम का एक फंक्शन परिभाषित करें, जो title, short_description, category, और features डेटा को वांछित स्ट्रक्चर में एक single string में जोड़ दे.
  • create_product_text() का उपयोग करके products में हर प्रोडक्ट के features को मिलाएँ और परिणामों को एक list में स्टोर करें.
  • product_texts में मौजूद टेक्स्ट को embed करें.