在ChromaDB中通过一组查询嵌入向量查询集合 本教程将引导您了解如何在ChromaDB中通过一组查询嵌入向量查询集合。 创建集合 我们首先初始化ChromaDB客户端,并创建一个名为 的集合。 添加嵌入向量和元数据 我们使用 方法向集合中添加两个假设的嵌入向量以及相关的元数据(来自《黑客帝国》的著名语录)。每个嵌入向量和元数据都与一个唯一的ID相关联。 通过一组查询嵌入向量进行查询 我们可以使用 method. This will return the closest matches to each query embedding.
本教程将引导您了解如何在ChromaDB中通过一组查询嵌入向量查询集合。
client = chromadb.Client() neo_collection = client.create_collection(name="neo")
我们首先初始化ChromaDB客户端,并创建一个名为neo的集合。
neo_collection.add( embeddings=[[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]], metadatas=[{"quote": "I know kung fu."}, {"quote": "There is no spoon."}], ids=["quote_1", "quote_2"] )
我们使用add方法向集合中添加两个假设的嵌入向量以及相关的元数据(来自《黑客帝国》的著名语录)。每个嵌入向量和元数据都与一个唯一的ID相关联。
results = neo_collection.query( query_embeddings=[[0.1, 0.2, 0.3]], n_results=1 ) print(results)
我们可以使用query method. This will return the closest matches to each query embedding. In this example, we query the collection with one of the embeddings we added earlier and ask for one result.
You will notice that the distance returned in the results is 0. This is because the query embedding is exactly the same as one of the embeddings in the collection. The distance is a measure of how similar the query embedding is to the embeddings in the collection:
0 means the embeddings are identicalNote: Feel free to experiment with the numbers in the query embedding to see how the distance changes. Remember, the closer the distance is to
0方法,通过一组查询嵌入向量对集合进行查询。查询嵌入向量与集合中嵌入向量的相似度越高,匹配结果越准确。
免责声明:
本文档采用基于机器的 AI 翻译服务进行翻译。尽管我们力求准确,但请注意,自动翻译可能存在错误或不准确之处。应以原文语言版本的文档作为权威依据。如需获取关键信息,建议使用专业的人工翻译。对于因使用本翻译而产生的任何误解或误读,我们概不负责。