mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-24 04:31:02 +02:00
Simplify logic
This commit is contained in:
parent
ae51a00d31
commit
ee622bf7c7
4 changed files with 46 additions and 78 deletions
|
|
@ -38,25 +38,21 @@ 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 not self.qdrant.collection_exists(collection):
|
||||||
if collection != self.last_collection or not self.qdrant.collection_exists(collection):
|
try:
|
||||||
if not self.qdrant.collection_exists(collection):
|
self.qdrant.create_collection(
|
||||||
try:
|
collection_name=collection,
|
||||||
self.qdrant.create_collection(
|
vectors_config=VectorParams(
|
||||||
collection_name=collection,
|
size=dim, distance=Distance.COSINE
|
||||||
vectors_config=VectorParams(
|
),
|
||||||
size=dim, distance=Distance.COSINE
|
)
|
||||||
),
|
logger.info(f"Created collection: {collection}")
|
||||||
)
|
except Exception as e:
|
||||||
logger.info(f"Created collection: {collection}")
|
logger.error(f"Qdrant collection creation failed: {e}")
|
||||||
except Exception as e:
|
raise e
|
||||||
logger.error(f"Qdrant collection creation failed: {e}")
|
|
||||||
raise e
|
|
||||||
self.last_collection = collection
|
|
||||||
|
|
||||||
async def query_document_embeddings(self, msg):
|
async def query_document_embeddings(self, msg):
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,25 +38,21 @@ 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 not self.qdrant.collection_exists(collection):
|
||||||
if collection != self.last_collection or not self.qdrant.collection_exists(collection):
|
try:
|
||||||
if not self.qdrant.collection_exists(collection):
|
self.qdrant.create_collection(
|
||||||
try:
|
collection_name=collection,
|
||||||
self.qdrant.create_collection(
|
vectors_config=VectorParams(
|
||||||
collection_name=collection,
|
size=dim, distance=Distance.COSINE
|
||||||
vectors_config=VectorParams(
|
),
|
||||||
size=dim, distance=Distance.COSINE
|
)
|
||||||
),
|
logger.info(f"Created collection: {collection}")
|
||||||
)
|
except Exception as e:
|
||||||
logger.info(f"Created collection: {collection}")
|
logger.error(f"Qdrant collection creation failed: {e}")
|
||||||
except Exception as e:
|
raise e
|
||||||
logger.error(f"Qdrant collection creation failed: {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://"):
|
||||||
|
|
|
||||||
|
|
@ -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,23 +92,17 @@ class Processor(DocumentEmbeddingsStoreService):
|
||||||
message.metadata.collection
|
message.metadata.collection
|
||||||
)
|
)
|
||||||
|
|
||||||
# Always check if collection exists, even if cached
|
if not self.qdrant.collection_exists(collection):
|
||||||
if collection != self.last_collection or not self.qdrant.collection_exists(collection):
|
try:
|
||||||
|
self.qdrant.create_collection(
|
||||||
if not self.qdrant.collection_exists(collection):
|
collection_name=collection,
|
||||||
|
vectors_config=VectorParams(
|
||||||
try:
|
size=dim, distance=Distance.COSINE
|
||||||
self.qdrant.create_collection(
|
),
|
||||||
collection_name=collection,
|
)
|
||||||
vectors_config=VectorParams(
|
except Exception as e:
|
||||||
size=dim, distance=Distance.COSINE
|
logger.error("Qdrant collection creation failed")
|
||||||
),
|
raise e
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error("Qdrant collection creation failed")
|
|
||||||
raise e
|
|
||||||
|
|
||||||
self.last_collection = collection
|
|
||||||
|
|
||||||
self.qdrant.upsert(
|
self.qdrant.upsert(
|
||||||
collection_name=collection,
|
collection_name=collection,
|
||||||
|
|
@ -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")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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,23 +75,17 @@ class Processor(GraphEmbeddingsStoreService):
|
||||||
"t_" + user + "_" + collection
|
"t_" + user + "_" + collection
|
||||||
)
|
)
|
||||||
|
|
||||||
# Always check if collection exists, even if cached
|
if not self.qdrant.collection_exists(cname):
|
||||||
if cname != self.last_collection or not self.qdrant.collection_exists(cname):
|
try:
|
||||||
|
self.qdrant.create_collection(
|
||||||
if not self.qdrant.collection_exists(cname):
|
collection_name=cname,
|
||||||
|
vectors_config=VectorParams(
|
||||||
try:
|
size=dim, distance=Distance.COSINE
|
||||||
self.qdrant.create_collection(
|
),
|
||||||
collection_name=cname,
|
)
|
||||||
vectors_config=VectorParams(
|
except Exception as e:
|
||||||
size=dim, distance=Distance.COSINE
|
logger.error("Qdrant collection creation failed")
|
||||||
),
|
raise e
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error("Qdrant collection creation failed")
|
|
||||||
raise e
|
|
||||||
|
|
||||||
self.last_collection = cname
|
|
||||||
|
|
||||||
return cname
|
return cname
|
||||||
|
|
||||||
|
|
@ -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")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue