Skip to content

Commit a0272a6

Browse files
committed
implemented clear method
1 parent a059333 commit a0272a6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

graphrag/storage/cosmosdb_pipeline_storage.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,18 @@ async def delete(self, key: str) -> None:
233233
)
234234
container_client.delete_item(item=key, partition_key=key)
235235

236+
# Function currently deletes all items within the current container, then deletes the container itself.
237+
# TODO: Decide the granularity of deletion (e.g. delete all items within the current container, delete the current container, delete the current database)
236238
async def clear(self) -> None:
237239
"""Clear the cosmosdb storage."""
240+
if self._current_container:
241+
container_client = self._database_client.get_container_client(
242+
self._current_container
243+
)
244+
for item in container_client.read_all_items():
245+
item_id = item["id"]
246+
container_client.delete_item(item=item_id, partition_key=item_id)
247+
self._delete_container()
238248

239249
def keys(self) -> list[str]:
240250
"""Return the keys in the storage."""

0 commit comments

Comments
 (0)