Skip to content

Commit 87ce098

Browse files
author
Zhe Yu
committed
feat(db): Implement delete and drop methods for database connectors
1 parent 0e1c9a5 commit 87ce098

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/vectorcode/database/base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,14 @@ async def list(
8484
Otherwise, this method may populate only one of them to save waiting time.
8585
"""
8686
pass
87+
88+
@abstractmethod
89+
async def delete(self, collection_path: str, file_path: str | Sequence[str]):
90+
pass
91+
92+
@abstractmethod
93+
async def drop(self, collection_path: str):
94+
"""
95+
Delete a collection from the database.
96+
"""
97+
pass

src/vectorcode/database/chroma0.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import sys
99
from asyncio.subprocess import Process
1010
from dataclasses import dataclass
11-
from typing import Any, Optional, cast
11+
from typing import Any, Optional, Sequence, cast
1212
from urllib.parse import urlparse
1313

1414
import chromadb
@@ -437,3 +437,15 @@ async def list(self, collection_path, what=None) -> CollectionContent:
437437
)
438438

439439
return content
440+
441+
async def delete(self, collection_path: str, file_path: str | Sequence[str]):
442+
collection = await self._create_or_get_collection(collection_path, False)
443+
if isinstance(file_path, str):
444+
file_path = [file_path]
445+
await collection.delete(
446+
where={"path": {"$in": [str(expand_path(i, True)) for i in file_path]}}
447+
)
448+
449+
async def drop(self, collection_path: str):
450+
async with Chroma0ClientManager().get_client(self._configs) as client:
451+
await client.delete_collection(get_collection_id(collection_path))

0 commit comments

Comments
 (0)