1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Embeddings with the OpenAI API

Connected

Exercise

Adding data to the collection

Time to add those Netflix films and TV shows to your collection! You've been provided with a list of document IDs and texts, stored in ids and documents, respectively, which have been extracted from netflix_titles.csv using the following code:

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)

As an example of what information will be embedded, here's the first document from 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

All of the necessary functions and packages have been imported, and a persistent client has been created and assigned to client.

Instructions

100 XP
  • Recreate your netflix_titles collection.
  • Add the documents and their IDs to the collection.
  • Print the number of documents in collection and the first ten items.