开始使用免费开始使用

使用多个文本进行查询

在很多场景中,您会希望使用多个查询文本来查询向量数据库。回顾一下,这些查询文本会使用与添加文档时相同的嵌入函数进行嵌入。

在本练习中,您将使用 netflix_titles 集合中两个 ID 对应的文档去查询集合的其余部分,并返回最相似的结果作为推荐。

netflix_titles 集合仍可使用,且已导入 OpenAIEmbeddingFunction()

本练习是课程的一部分

使用 OpenAI API 的 Embeddings 入门

查看课程

练习说明

  • 从集合中检索 reference_ids 中各个 ID 对应的文档。
  • 使用 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'])
编辑并运行代码