使用多段文字進行查詢
在許多情況下,你會想用多個查詢文字來查詢向量資料庫。記得這些查詢文字會使用與加入文件時相同的嵌入向量(embedding)函式進行轉換。
在這個練習中,你會使用 netflix_titles 集合中兩個 ID 對應的文件,去查詢整個集合,並回傳最相似的結果作為推薦。
netflix_titles 集合仍可使用,且已匯入 OpenAIEmbeddingFunction()。
本練習屬於課程
Introduction to Embeddings with the OpenAI API
練習說明
- 針對
reference_ids中的 ID,從集合中取回對應的 documents。 - 使用
reference_texts查詢集合,為每個查詢各回傳 3 個結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
collection = client.get_collection(
name="netflix_titles",
embedding_function=OpenAIEmbeddingFunction(model_name="text-embedding-3-small", api_key="")
)
reference_ids = ['s999', 's1000']
# Retrieve the documents for the reference_ids
reference_texts = ____
# Query using reference_texts
result = ____
print(result['documents'])