開始使用免費開始

ChromaDB 入門

在接下來的練習中,你會使用向量資料庫,將影片中介紹的 Netflix 資料集裡 1000 部電影與影集轉成嵌入向量(embedding),並進行查詢。目標是根據搜尋查詢來產生推薦結果。首先,你會建立資料庫與 collection 來儲存資料。

chromadb 已可直接使用,且已從 chromadb.utils.embedding_functions 匯入 OpenAIEmbeddingFunction()與前兩章相同,本章不需要提供 OpenAI API 金鑰。

本練習屬於課程

Introduction to Embeddings with the OpenAI API

檢視課程

練習說明

  • 建立一個持久化用戶端,將資料庫檔案儲存到磁碟;在這些練習中可以省略檔案路徑。
  • 建立一個名為 netflix_titles 的資料庫 collection,並使用 OpenAI 的嵌入函式。
  • 列出資料庫中的所有 collection。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Create a persistant client
client = chromadb.____()

# Create a netflix_title collection using the OpenAI Embedding function
collection = client.create_collection(
    name="____",
    ____=____(model_name="text-embedding-3-small", api_key="")
)

# List the collections
print(client.____())
編輯並執行程式碼