diff --git a/cognee/exceptions/exceptions.py b/cognee/exceptions/exceptions.py index 614cb29ac..429f9019b 100644 --- a/cognee/exceptions/exceptions.py +++ b/cognee/exceptions/exceptions.py @@ -12,13 +12,22 @@ class CogneeApiError(Exception): message: str = "Service is unavailable.", name: str = "Cognee", status_code=status.HTTP_418_IM_A_TEAPOT, + log=True, + log_level="ERROR", ): self.message = message self.name = name self.status_code = status_code # Automatically log the exception details - logger.error(f"{self.name}: {self.message} (Status code: {self.status_code})") + if log and (log_level == "ERROR"): + logger.error(f"{self.name}: {self.message} (Status code: {self.status_code})") + elif log and (log_level == "WARNING"): + logger.warning(f"{self.name}: {self.message} (Status code: {self.status_code})") + elif log and (log_level == "INFO"): + logger.info(f"{self.name}: {self.message} (Status code: {self.status_code})") + elif log and (log_level == "DEBUG"): + logger.debug(f"{self.name}: {self.message} (Status code: {self.status_code})") super().__init__(self.message, self.name) diff --git a/cognee/infrastructure/databases/graph/graph_db_interface.py b/cognee/infrastructure/databases/graph/graph_db_interface.py index 9aec187fc..8c582107f 100644 --- a/cognee/infrastructure/databases/graph/graph_db_interface.py +++ b/cognee/infrastructure/databases/graph/graph_db_interface.py @@ -58,7 +58,7 @@ def record_graph_changes(func): session.add(relationship) await session.flush() except Exception as e: - logger.error(f"Error adding relationship: {e}") + logger.debug(f"Error adding relationship: {e}") await session.rollback() continue @@ -78,14 +78,14 @@ def record_graph_changes(func): session.add(relationship) await session.flush() except Exception as e: - logger.error(f"Error adding relationship: {e}") + logger.debug(f"Error adding relationship: {e}") await session.rollback() continue try: await session.commit() except Exception as e: - logger.error(f"Error committing session: {e}") + logger.debug(f"Error committing session: {e}") return result diff --git a/cognee/infrastructure/databases/vector/exceptions/exceptions.py b/cognee/infrastructure/databases/vector/exceptions/exceptions.py index 4ad14f716..5ec466e35 100644 --- a/cognee/infrastructure/databases/vector/exceptions/exceptions.py +++ b/cognee/infrastructure/databases/vector/exceptions/exceptions.py @@ -8,5 +8,7 @@ class CollectionNotFoundError(CriticalError): message, name: str = "CollectionNotFoundError", status_code: int = status.HTTP_422_UNPROCESSABLE_ENTITY, + log=True, + log_level="ERROR", ): - super().__init__(message, name, status_code) + super().__init__(message, name, status_code, log, log_level) diff --git a/cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py b/cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py index 07745ac77..ae4739184 100644 --- a/cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py +++ b/cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py @@ -184,7 +184,9 @@ class PGVectorAdapter(SQLAlchemyAdapter, VectorDBInterface): if collection_name in metadata.tables: return metadata.tables[collection_name] else: - raise CollectionNotFoundError(f"Collection '{collection_name}' not found!") + raise CollectionNotFoundError( + f"Collection '{collection_name}' not found!", log_level="DEBUG" + ) async def retrieve(self, collection_name: str, data_point_ids: List[str]): # Get PGVectorDataPoint Table from database @@ -266,6 +268,7 @@ class PGVectorAdapter(SQLAlchemyAdapter, VectorDBInterface): # Get PGVectorDataPoint Table from database PGVectorDataPoint = await self.get_table(collection_name) + # NOTE: This needs to be initialized in case search doesn't return a value closest_items = [] # Use async session to connect to the database