시작하기무료로 시작하기

컬렉션에 데이터 추가하기

이제 Netflix 영화와 TV 프로그램을 컬렉션에 추가해 볼까요? idsdocuments에 각각 문서 ID와 텍스트 목록이 준비되어 있어요. 이는 다음 코드를 사용해 netflix_titles.csv에서 추출한 것입니다:

ids = []
documents = []

with open('netflix_titles.csv') as csvfile:
  reader = csv.DictReader(csvfile)
  for i, row in enumerate(reader):
    ids.append(row['show_id'])
    text = f"Title: {row['title']} ({row['type']})\nDescription: {row['description']}\nCategories: {row['listed_in']}"
    documents.append(text)

어떤 정보가 임베딩될지 예로 보여 드리면, documents의 첫 번째 문서는 다음과 같습니다:

Title: Dick Johnson Is Dead (Movie)
Description: As her father nears the end of his life, filmmaker Kirsten Johnson stages his death in inventive and comical ways to help them both face the inevitable.
Categories: Documentaries

필요한 함수와 패키지는 모두 임포트되어 있고, 지속형 클라이언트가 생성되어 client에 할당되어 있어요.

이 연습은 강의의 일부입니다

OpenAI API로 시작하는 임베딩 Introduction

강의 보기

연습 안내

  • netflix_titles 컬렉션을 다시 생성하세요.
  • 문서와 해당 ID를 컬렉션에 추가하세요.
  • collection에 있는 문서 수와 처음 10개 항목을 출력하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Recreate the netflix_titles collection
collection = client.____(
  name="netflix_titles",
  embedding_function=OpenAIEmbeddingFunction(model_name="text-embedding-3-small", api_key="")
)

# Add the documents and IDs to the collection
____

# Print the collection size and first ten items
print(f"No. of documents: {____}")
print(f"First ten documents: {____}")
코드 편집 및 실행