在ChromaDB中按ID检索集合中的项目 本教程将引导您了解如何在ChromaDB中按ID检索集合中的项目。 创建集合 我们首先初始化ChromaDB客户端,并创建一个名为 的集合。 添加原始文档 我们使用 方法向集合中添加了三个原始文档。每个文档都与一个唯一的ID相关联。 按ID从集合中检索项目 我们可以使用 method. In this example, we retrieve items with the IDs "quote1" and "quote3". The method returns a dictionary with the IDs, embeddings, metadatas, and documents of the retrieved items.
本教程将引导您了解如何在ChromaDB中按ID检索集合中的项目。
client = chromadb.Client() trinity_collection = client.create_collection(name="trinity")
我们首先初始化ChromaDB客户端,并创建一个名为trinity的集合。
trinity_collection.add( documents=[ "Dodge this.", "I think they're trying to tell us something.", "Neo, no one has ever done this before.", ], ids=["quote_1", "quote_2", "quote_3"], )
我们使用add方法向集合中添加了三个原始文档。每个文档都与一个唯一的ID相关联。
items = trinity_collection.get(ids=["quote_1", "quote_3"]) print(items)
我们可以使用get method. In this example, we retrieve items with the IDs "quote_1" and "quote_3".
The get method returns a dictionary with the IDs, embeddings, metadatas, and documents of the retrieved items.
get method to fetch those documents from the collection.get method to validate the existence and retrieve specific items based on their IDs, ensuring the integrity of your data.Tip: Feel free to modify the IDs in the
get方法,通过项目的ID从集合中检索特定的项目。尝试使用不同的ID,探索ChromaDB如何根据唯一标识符检索特定项目。
免责声明:
本文档采用基于机器的 AI 翻译服务进行翻译。尽管我们力求准确,但请注意,自动翻译可能存在错误或不准确之处。应以原文语言版本的文档作为权威依据。如需获取关键信息,建议使用专业的人工翻译。对于因使用本翻译而产生的任何误解或误读,我们概不负责。