From ae51a00d31cfc1e46a21597a26d9efbb062aa266 Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Tue, 30 Sep 2025 00:23:23 +0100 Subject: [PATCH] Always test for collections --- .../trustgraph/query/doc_embeddings/qdrant/service.py | 3 ++- .../trustgraph/query/graph_embeddings/qdrant/service.py | 3 ++- .../trustgraph/storage/doc_embeddings/qdrant/write.py | 7 ++++++- .../trustgraph/storage/graph_embeddings/qdrant/write.py | 7 ++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/trustgraph-flow/trustgraph/query/doc_embeddings/qdrant/service.py b/trustgraph-flow/trustgraph/query/doc_embeddings/qdrant/service.py index f94f3b93..fdf99d19 100755 --- a/trustgraph-flow/trustgraph/query/doc_embeddings/qdrant/service.py +++ b/trustgraph-flow/trustgraph/query/doc_embeddings/qdrant/service.py @@ -42,7 +42,8 @@ class Processor(DocumentEmbeddingsQueryService): def ensure_collection_exists(self, collection, dim): """Ensure collection exists, create if it doesn't""" - if collection != self.last_collection: + # Always check if collection exists, even if cached + if collection != self.last_collection or not self.qdrant.collection_exists(collection): if not self.qdrant.collection_exists(collection): try: self.qdrant.create_collection( diff --git a/trustgraph-flow/trustgraph/query/graph_embeddings/qdrant/service.py b/trustgraph-flow/trustgraph/query/graph_embeddings/qdrant/service.py index 0b792566..1f13961d 100755 --- a/trustgraph-flow/trustgraph/query/graph_embeddings/qdrant/service.py +++ b/trustgraph-flow/trustgraph/query/graph_embeddings/qdrant/service.py @@ -42,7 +42,8 @@ class Processor(GraphEmbeddingsQueryService): def ensure_collection_exists(self, collection, dim): """Ensure collection exists, create if it doesn't""" - if collection != self.last_collection: + # Always check if collection exists, even if cached + if collection != self.last_collection or not self.qdrant.collection_exists(collection): if not self.qdrant.collection_exists(collection): try: self.qdrant.create_collection( diff --git a/trustgraph-flow/trustgraph/storage/doc_embeddings/qdrant/write.py b/trustgraph-flow/trustgraph/storage/doc_embeddings/qdrant/write.py index 3a2f8f56..c88a995a 100644 --- a/trustgraph-flow/trustgraph/storage/doc_embeddings/qdrant/write.py +++ b/trustgraph-flow/trustgraph/storage/doc_embeddings/qdrant/write.py @@ -94,7 +94,8 @@ class Processor(DocumentEmbeddingsStoreService): message.metadata.collection ) - if collection != self.last_collection: + # Always check if collection exists, even if cached + if collection != self.last_collection or not self.qdrant.collection_exists(collection): if not self.qdrant.collection_exists(collection): @@ -176,6 +177,10 @@ class Processor(DocumentEmbeddingsStoreService): if self.qdrant.collection_exists(collection_name): self.qdrant.delete_collection(collection_name) logger.info(f"Deleted Qdrant collection: {collection_name}") + + # Clear cache if we just deleted the cached collection + if self.last_collection == collection_name: + self.last_collection = None else: logger.info(f"Collection {collection_name} does not exist, nothing to delete") diff --git a/trustgraph-flow/trustgraph/storage/graph_embeddings/qdrant/write.py b/trustgraph-flow/trustgraph/storage/graph_embeddings/qdrant/write.py index c7144871..e117fa48 100755 --- a/trustgraph-flow/trustgraph/storage/graph_embeddings/qdrant/write.py +++ b/trustgraph-flow/trustgraph/storage/graph_embeddings/qdrant/write.py @@ -77,7 +77,8 @@ class Processor(GraphEmbeddingsStoreService): "t_" + user + "_" + collection ) - if cname != self.last_collection: + # Always check if collection exists, even if cached + if cname != self.last_collection or not self.qdrant.collection_exists(cname): if not self.qdrant.collection_exists(cname): @@ -183,6 +184,10 @@ class Processor(GraphEmbeddingsStoreService): if self.qdrant.collection_exists(collection_name): self.qdrant.delete_collection(collection_name) logger.info(f"Deleted Qdrant collection: {collection_name}") + + # Clear cache if we just deleted the cached collection + if self.last_collection == collection_name: + self.last_collection = None else: logger.info(f"Collection {collection_name} does not exist, nothing to delete")