1. Learn
  2. /
  3. 课程
  4. /
  5. 使用 OpenAI API 的 Embeddings 入门

Connected

道练习

向集合添加数据

现在把这些 Netflix 电影和剧集添加到您的集合中吧!我们已经为您准备好了一份文档 ID 列表和文本列表,分别保存在 ids 和 documents 中。它们是通过以下代码从 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 个条目。