시작하기무료로 시작하기

YouTube 대본 업서트하기

다음 연습 문제에서는 비디오 대본과 추가 메타데이터를 'pinecone-datacamp' 인덱스에 적재해, YouTube 동영상에 대한 질문에 답할 수 있는 챗봇을 만들어 볼 거예요.

먼저, 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 애플리케이션 구축하기

강의 보기

연습 안내

  • Pinecone 클라이언트를 API 키로 초기화하세요(OpenAI 클라이언트는 client로 제공됩니다).
  • row에서 'id', 'text', 'title', 'url', 'published' 메타데이터를 추출하세요.
  • OpenAI의 'text-embedding-3-small'texts를 인코딩하세요.
  • 벡터와 메타데이터를 '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())
코드 편집 및 실행