在ChromaDB中选择从集合中返回哪些数据 本教程将指导您如何在ChromaDB中选择从集合中返回哪些数据。 创建集合 我们首先初始化ChromaDB客户端,并创建一个名为 的集合。 添加原始文档 我们使用 方法向集合中添加了三个原始文档。每个文档都与一个唯一的ID相关联。 根据文本查询集合并选择要返回的数据 我们可以使用 method. In this example, we search for the phrase "make a choice" and ask for one result.
本教程将指导您如何在ChromaDB中选择从集合中返回哪些数据。
client = chromadb.Client() morpheus_collection = client.create_collection(name="morpheus", metadata={"hnsw:space": "cosine"})
我们首先初始化ChromaDB客户端,并创建一个名为morpheus的集合。
morpheus_collection.add( documents=[ "This is your last chance. After this, there is no turning back.", "You take the blue pill, the story ends, you wake up in your bed and believe whatever you want to believe.", "You take the red pill, you stay in Wonderland, and I show you how deep the rabbit hole goes.", ], ids=["quote_1", "quote_2", "quote_3"], )
我们使用add方法向集合中添加了三个原始文档。每个文档都与一个唯一的ID相关联。
results = morpheus_collection.query( query_texts=["make a choice"], n_results=1, include=["distances", "embeddings"] )
我们可以使用query method. In this example, we search for the phrase "make a choice" and ask for one result. Additionally, we specify that we only want the distances and embeddings to be returned by including them in the include parameter.
The query method will return a dictionary with the selected data (distances and embeddings) for the closest match to the query text.
Selective Data Retrieval:
Data Privacy and Security:
Efficiency and Resource Optimization:
Custom Application Needs:
Debugging and Monitoring:
Remember to adjust the include参数来根据文本查询集合,以满足您的具体用例需求。
免责声明:
本文档采用基于机器的 AI 翻译服务进行翻译。尽管我们力求准确,但请注意,自动翻译可能存在错误或不准确之处。应以原文语言版本的文档作为权威依据。如需获取关键信息,建议使用专业的人工翻译。对于因使用本翻译而产生的任何误解或误读,我们概不负责。