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

YouTube ट्रांसक्रिप्ट्स अपसर्ट करना

आने वाले अभ्यासों में, आप एक चैटबॉट बनाएँगे जो YouTube वीडियो के बारे में सवालों के जवाब दे सकेगा. इसके लिए आप वीडियो ट्रांसक्रिप्ट्स और अतिरिक्त मेटाडेटा को अपने 'pinecone-datacamp' इंडेक्स में इनजेस्ट करेंगे.

शुरू करने के लिए, आप youtube_rag_data.csv फ़ाइल से डेटा तैयार करेंगे और सभी मेटाडेटा के साथ वेक्टर्स को 'pinecone-datacamp' इंडेक्स में अपसर्ट करेंगे. डेटा DataFrame youtube_df में दिया गया है.

यहाँ youtube_df DataFrame से एक उदाहरण ट्रांसक्रिप्ट दिया गया है:

id: 
35Pdoyi6ZoQ-t0.0

title:
Training and Testing an Italian BERT - Transformers From Scratch #4

text: 
Hi, welcome to the video. So this is the fourth video in a Transformers from Scratch 
mini series. So if you haven't been following along, we've essentially covered what 
you can see on the screen. So we got some data. We built a tokenizer with it...

url: 
https://youtu.be/35Pdoyi6ZoQ

published: 
01-01-2024

यह अभ्यास पाठ्यक्रम का हिस्सा है

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

पाठ्यक्रम देखें

अभ्यास निर्देश

  • अपने API key के साथ Pinecone क्लाइंट इनिशियलाइज़ करें (OpenAI क्लाइंट client के रूप में उपलब्ध है).
  • प्रत्येक row से 'id', 'text', 'title', 'url', और 'published' मेटाडेटा निकालें.
  • OpenAI के 'text-embedding-3-small' का उपयोग करके texts को एन्कोड करें.
  • वेक्टर्स और मेटाडेटा को 'youtube_rag_dataset' नाम के namespace में अपसर्ट करें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Initialize the Pinecone client
pc = Pinecone(api_key="____")
index = pc.Index('pinecone-datacamp')

batch_limit = 100

for batch in np.array_split(youtube_df, len(youtube_df) / batch_limit):
    # Extract the metadata from each row
    metadatas = [{
      "text_id": row['____'],
      "text": row['____'],
      "title": row['____'],
      "url": row['____'],
      "published": row['____']} for _, row in batch.iterrows()]
    texts = batch['text'].tolist()
    
    ids = [str(uuid4()) for _ in range(len(texts))]
    
    # Encode texts using OpenAI
    response = ____(input=____, model="text-embedding-3-small")
    embeds = [np.array(x.embedding) for x in response.data]
    
    # Upsert vectors to the correct namespace
    ____(vectors=____(ids, embeds, metadatas), namespace='____')
    
print(index.describe_index_stats())
कोड संपादित करें और चलाएँ