Simplify logic

This commit is contained in:
Cyber MacGeddon 2025-09-30 00:29:06 +01:00
parent ae51a00d31
commit ee622bf7c7
4 changed files with 46 additions and 78 deletions

View file

@ -38,12 +38,9 @@ class Processor(DocumentEmbeddingsQueryService):
) )
self.qdrant = QdrantClient(url=store_uri, api_key=api_key) self.qdrant = QdrantClient(url=store_uri, api_key=api_key)
self.last_collection = None
def ensure_collection_exists(self, collection, dim): def ensure_collection_exists(self, collection, dim):
"""Ensure collection exists, create if it doesn't""" """Ensure collection exists, create if it doesn't"""
# 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): if not self.qdrant.collection_exists(collection):
try: try:
self.qdrant.create_collection( self.qdrant.create_collection(
@ -56,7 +53,6 @@ class Processor(DocumentEmbeddingsQueryService):
except Exception as e: except Exception as e:
logger.error(f"Qdrant collection creation failed: {e}") logger.error(f"Qdrant collection creation failed: {e}")
raise e raise e
self.last_collection = collection
async def query_document_embeddings(self, msg): async def query_document_embeddings(self, msg):

View file

@ -38,12 +38,9 @@ class Processor(GraphEmbeddingsQueryService):
) )
self.qdrant = QdrantClient(url=store_uri, api_key=api_key) self.qdrant = QdrantClient(url=store_uri, api_key=api_key)
self.last_collection = None
def ensure_collection_exists(self, collection, dim): def ensure_collection_exists(self, collection, dim):
"""Ensure collection exists, create if it doesn't""" """Ensure collection exists, create if it doesn't"""
# 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): if not self.qdrant.collection_exists(collection):
try: try:
self.qdrant.create_collection( self.qdrant.create_collection(
@ -56,7 +53,6 @@ class Processor(GraphEmbeddingsQueryService):
except Exception as e: except Exception as e:
logger.error(f"Qdrant collection creation failed: {e}") logger.error(f"Qdrant collection creation failed: {e}")
raise e raise e
self.last_collection = collection
def create_value(self, ent): def create_value(self, ent):
if ent.startswith("http://") or ent.startswith("https://"): if ent.startswith("http://") or ent.startswith("https://"):

View file

@ -36,8 +36,6 @@ class Processor(DocumentEmbeddingsStoreService):
} }
) )
self.last_collection = None
self.qdrant = QdrantClient(url=store_uri, api_key=api_key) self.qdrant = QdrantClient(url=store_uri, api_key=api_key)
# Set up storage management if base class attributes are available # Set up storage management if base class attributes are available
@ -94,11 +92,7 @@ class Processor(DocumentEmbeddingsStoreService):
message.metadata.collection message.metadata.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): if not self.qdrant.collection_exists(collection):
try: try:
self.qdrant.create_collection( self.qdrant.create_collection(
collection_name=collection, collection_name=collection,
@ -110,8 +104,6 @@ class Processor(DocumentEmbeddingsStoreService):
logger.error("Qdrant collection creation failed") logger.error("Qdrant collection creation failed")
raise e raise e
self.last_collection = collection
self.qdrant.upsert( self.qdrant.upsert(
collection_name=collection, collection_name=collection,
points=[ points=[
@ -177,10 +169,6 @@ class Processor(DocumentEmbeddingsStoreService):
if self.qdrant.collection_exists(collection_name): if self.qdrant.collection_exists(collection_name):
self.qdrant.delete_collection(collection_name) self.qdrant.delete_collection(collection_name)
logger.info(f"Deleted Qdrant 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: else:
logger.info(f"Collection {collection_name} does not exist, nothing to delete") logger.info(f"Collection {collection_name} does not exist, nothing to delete")

View file

@ -36,8 +36,6 @@ class Processor(GraphEmbeddingsStoreService):
} }
) )
self.last_collection = None
self.qdrant = QdrantClient(url=store_uri, api_key=api_key) self.qdrant = QdrantClient(url=store_uri, api_key=api_key)
# Set up storage management if base class attributes are available # Set up storage management if base class attributes are available
@ -77,11 +75,7 @@ class Processor(GraphEmbeddingsStoreService):
"t_" + user + "_" + collection "t_" + user + "_" + 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): if not self.qdrant.collection_exists(cname):
try: try:
self.qdrant.create_collection( self.qdrant.create_collection(
collection_name=cname, collection_name=cname,
@ -93,8 +87,6 @@ class Processor(GraphEmbeddingsStoreService):
logger.error("Qdrant collection creation failed") logger.error("Qdrant collection creation failed")
raise e raise e
self.last_collection = cname
return cname return cname
async def start(self): async def start(self):
@ -184,10 +176,6 @@ class Processor(GraphEmbeddingsStoreService):
if self.qdrant.collection_exists(collection_name): if self.qdrant.collection_exists(collection_name):
self.qdrant.delete_collection(collection_name) self.qdrant.delete_collection(collection_name)
logger.info(f"Deleted Qdrant 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: else:
logger.info(f"Collection {collection_name} does not exist, nothing to delete") logger.info(f"Collection {collection_name} does not exist, nothing to delete")