在集合中更新数据:更新集合中项目的任意属性 本教程将指导您如何在ChromaDB中更新集合中项目的任意属性。 创建集合 我们首先初始化ChromaDB客户端,并创建一个名为 的集合。 添加原始文档 我们使用 方法向集合中添加了三个原始文档。每个文档都关联有一个唯一ID,并包含元数据,包括类别和演讲者。 更新集合中的项目 ChromaDB允许我们使用 方法更新集合中项目的任意属性。在本示例中,我们更新ID为“quote2”的项目的元数据和文档内容。我们将演讲者保持为“Morpheus”,并更新文档文本。 从集合中检索已更新的项目 我们可以使用 method.
本教程将指导您如何在ChromaDB中更新集合中项目的任意属性。
client = chromadb.Client() matrix_collection = client.create_collection(name="matrix")
我们首先初始化ChromaDB客户端,并创建一个名为matrix的集合。
matrix_collection.add( documents=[ "The Matrix is everywhere, it is all around us.", "You can see it when you look out your window or when you turn on your television.", "You can feel it when you go to work, when you go to church, when you pay your taxes.", ], metadatas=[ {"category": "quote", "speaker": "Morpheus"}, {"category": "quote", "speaker": "Morpheus"}, {"category": "quote", "speaker": "Morpheus"}, ], ids=["quote_1", "quote_2", "quote_3"], )
我们使用add方法向集合中添加了三个原始文档。每个文档都关联有一个唯一ID,并包含元数据,包括类别和演讲者。
matrix_collection.update( ids=["quote_2"], metadatas=[{"category": "quote", "speaker": "Morpheus"}], documents=["The Matrix is a system, Neo. That system is our enemy."], )
ChromaDB允许我们使用update方法更新集合中项目的任意属性。在本示例中,我们更新ID为“quote_2”的项目的元数据和文档内容。我们将演讲者保持为“Morpheus”,并更新文档文本。
items = matrix_collection.get(ids=["quote_2"]) print(items)
我们可以使用get method. In this case, we retrieve the item with the ID "quote_2" to see the changes.
Tip: Feel free to modify the update parameters in the
update方法从集合中检索已更新的项目,以尝试更新集合中不同项目的属性。
免责声明:
本文档采用基于机器的 AI 翻译服务进行翻译。尽管我们力求准确,但请注意,自动翻译可能存在错误或不准确之处。应以原文语言版本的文档作为权威依据。如需获取关键信息,建议使用专业的人工翻译。对于因使用本翻译而产生的任何误解或误读,我们概不负责。