fix(test): chrome db test fails due to reusing deleted collection

Signed-off-by: Mustafa Elbehery <melbeher@redhat.com>
This commit is contained in:
Mustafa Elbehery 2025-09-08 18:13:03 +02:00
parent 142bd248e7
commit 5a6c20313d

View file

@ -56,10 +56,11 @@ class ChromaIndex(EmbeddingIndex):
def __init__(self, client: ChromaClientType, collection, kvstore: KVStore | None = None): def __init__(self, client: ChromaClientType, collection, kvstore: KVStore | None = None):
self.client = client self.client = client
self.collection = collection self.collection = collection
self.collection_name = collection.name
self.kvstore = kvstore self.kvstore = kvstore
async def initialize(self): async def initialize(self):
pass self.collection = await maybe_await(self.client.get_or_create_collection(self.collection_name))
async def add_chunks(self, chunks: list[Chunk], embeddings: NDArray): async def add_chunks(self, chunks: list[Chunk], embeddings: NDArray):
assert len(chunks) == len(embeddings), ( assert len(chunks) == len(embeddings), (
@ -106,7 +107,13 @@ class ChromaIndex(EmbeddingIndex):
return QueryChunksResponse(chunks=chunks, scores=scores) return QueryChunksResponse(chunks=chunks, scores=scores)
async def delete(self): async def delete(self):
await maybe_await(self.client.delete_collection(self.collection.name)) try:
await maybe_await(self.client.delete_collection(self.collection.name))
except Exception as e:
if "does not exists" in str(e):
log.warning(f"Collection {self.collection.name} already deleted")
else:
raise
async def query_keyword( async def query_keyword(
self, self,