通过ID从ChromaDB集合中删除条目


文档摘要

通过ID从ChromaDB集合中删除条目 本教程将指导您如何通过ID从ChromaDB集合中删除条目。 创建集合 我们首先初始化ChromaDB客户端,并创建一个名为 的集合。 添加原始文档 我们使用 方法向集合中添加了三个原始文档。每个文档都关联有一个唯一的ID。 通过ID从集合中删除条目 我们可以使用 method. In this example, we delete the item with the ID "quote3". The method removes the specified items from the collection permanently.

通过ID从ChromaDB集合中删除条目

本教程将指导您如何通过ID从ChromaDB集合中删除条目。

1. 创建集合

client = chromadb.Client() trinity_collection = client.create_collection(name="trinity")

我们首先初始化ChromaDB客户端,并创建一个名为trinity的集合。

2. 添加原始文档

trinity_collection.add( documents=[ "I know why you're here, Neo.", "The answer is out there, Neo. It's looking for you. And it will find you if you want it to.", "Neo, no one has ever done this before.", ], ids=["quote_1", "quote_2", "quote_3"], )

我们使用add方法向集合中添加了三个原始文档。每个文档都关联有一个唯一的ID。

3. 通过ID从集合中删除条目

trinity_collection.delete(ids=["quote_3"])

我们可以使用delete method. In this example, we delete the item with the ID "quote_3".

The delete method removes the specified items from the collection permanently.

Use cases for deleting items by ID include:

  • Data Management: You can remove specific items from the collection to manage and maintain the data in ChromaDB.
  • Data Cleanup: Deleting items by ID allows you to clean up the collection and remove unwanted or outdated data.

Feel free to modify the IDs in the delete方法,通过ID从集合中删除特定条目,以删除集合中的不同条目。

items = trinity_collection.get() print(items)

删除条目后,我们使用get method to verify the deletion.

Please refer to the delete_by_id.py文件从集合中检索剩余的条目。完整的Python代码请参阅本教程。

免责声明
本文档采用基于机器的 AI 翻译服务进行翻译。尽管我们力求准确,但请注意,自动翻译可能存在错误或不准确之处。应以原文语言版本的文档作为权威依据。如需获取关键信息,建议使用专业的人工翻译。对于因使用本翻译而产生的任何误解或误读,我们概不负责。


发布者: 作者: 转发
评论区 (0)
U