เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การอัปเซิร์ตสคริปต์ YouTube

ในแบบฝึกหัดต่อไปนี้ คุณจะสร้างแชทบอตที่สามารถตอบคำถามเกี่ยวกับวิดีโอ YouTube ได้ โดยการนำสคริปต์วิดีโอและ metadata เพิ่มเติมเข้าสู่ index 'pinecone-datacamp'

เริ่มต้นด้วยการเตรียมข้อมูลจากไฟล์ youtube_rag_data.csv แล้วอัปเซิร์ตเวกเตอร์พร้อม metadata ทั้งหมดเข้าสู่ index 'pinecone-datacamp' ข้อมูลถูกจัดเก็บไว้ใน DataFrame youtube_df

ตัวอย่างสคริปต์จาก DataFrame youtube_df:

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

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Vector Databases สำหรับ Embeddings ด้วย Pinecone

ดูคอร์ส

คำแนะนำการฝึกหัด

  • เริ่มต้น Pinecone client ด้วย API key ของคุณ (OpenAI client พร้อมใช้งานในชื่อตัวแปร client)
  • ดึง metadata ได้แก่ 'id', 'text', 'title', 'url' และ 'published' จากแต่ละ row
  • เข้ารหัส texts โดยใช้โมเดล 'text-embedding-3-small' จาก OpenAI
  • อัปเซิร์ตเวกเตอร์และ metadata เข้าสู่ namespace ชื่อ 'youtube_rag_dataset'

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# 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())
แก้ไขและรันโค้ด