1. 学ぶ
  2. /
  3. コース
  4. /
  5. OpenAI API ではじめる Embeddings 入門

Connected

演習

コレクションにデータを追加する

Netflix の映画とTV番組をコレクションに追加していきましょう。すでに ids と documents に、ドキュメント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 に割り当てられています。

指示

100 XP
  • netflix_titles コレクションを再作成します。
  • ドキュメントとそのIDをコレクションに追加します。
  • collection に含まれるドキュメント数と、先頭10件を出力します。