Repository: topoteretes/cognee
File: cognee/api/health.py (Python)

Code before:
        try:
            from cognee.infrastructure.databases.graph.get_graph_engine import get_graph_engine
            from cognee.infrastructure.databases.graph.config import get_graph_config

            config = get_graph_config()
            engine = await get_graph_engine()

            # Test basic operation with actual graph query
            if hasattr(engine, "execute"):
                # For SQL-like graph DBs (Neo4j, Memgraph)
                await engine.execute("MATCH () RETURN count(*) LIMIT 1")
            elif hasattr(engine, "get_nodes"):
                # For other graph engines - try to get nodes
                list(engine.get_nodes(limit=1))
            # If engine exists but no test method, consider it healthy

            response_time = int((time.time() - start_time) * 1000)
            return ComponentHealth(
                status=HealthStatus.HEALTHY,
                provider=config.graph_database_provider,
                response_time_ms=response_time,
                details="Schema validated",
            )
        except Exception as e:
            response_time = int((time.time() - start_time) * 1000)
            return ComponentHealth(
                status=HealthStatus.UNHEALTHY,
                provider="unknown",
                response_time_ms=response_time,
                details=f"Connection failed: {str(e)}",
            )

    async def check_file_storage(self) -> ComponentHealth:
        """Check file storage health."""
        start_time = time.time()
        try:
            import os
            from cognee.infrastructure.files.storage.get_file_storage import get_file_storage
            from cognee.base_config import get_base_config

            base_config = get_base_config()
            storage = get_file_storage(base_config.data_root_directory)

            # Determine provider
            provider = "s3" if base_config.data_root_directory.startswith("s3://") else "local"

            # Test storage accessibility - for local storage, just check directory exists
            if provider == "local":
                os.makedirs(base_config.data_root_directory, exist_ok=True)
                # Simple write/read test
                test_file = os.path.join(base_config.data_root_directory, "health_check_test")

Review comment (bug):
Let's add stacktrace logging here too
```suggestion
            response_time = int((time.time() - start_time) * 1000)
            logger.error(f"Graph DB health check failed: {str(e)}", exc_info=True)
            return ComponentHealth(
```

Code after:
        """Check graph database health."""
        start_time = time.time()
        try:
            from cognee.infrastructure.databases.graph.get_graph_engine import get_graph_engine
            from cognee.infrastructure.databases.graph.config import get_graph_config

            config = get_graph_config()
            engine = await get_graph_engine()

            # Test basic operation with actual graph query
            if hasattr(engine, "execute"):
                # For SQL-like graph DBs (Neo4j, Memgraph)
                await engine.execute("MATCH () RETURN count(*) LIMIT 1")
            elif hasattr(engine, "query"):
                # For other graph engines
                engine.query("MATCH () RETURN count(*) LIMIT 1", {})
            # If engine exists but no test method, consider it healthy

            response_time = int((time.time() - start_time) * 1000)
            return ComponentHealth(
                status=HealthStatus.HEALTHY,
                provider=config.graph_database_provider,
                response_time_ms=response_time,
                details="Schema validated",
            )
        except Exception as e:
            response_time = int((time.time() - start_time) * 1000)
            logger.error(f"Graph DB health check failed: {str(e)}", exc_info=True)
            return ComponentHealth(
                status=HealthStatus.UNHEALTHY,
                provider="unknown",
                response_time_ms=response_time,
                details=f"Connection failed: {str(e)}",
            )

    async def check_file_storage(self) -> ComponentHealth:
        """Check file storage health."""
        start_time = time.time()
        try:
            import os
            from cognee.infrastructure.files.storage.get_file_storage import get_file_storage
            from cognee.base_config import get_base_config

            base_config = get_base_config()
            storage = get_file_storage(base_config.data_root_directory)

            # Determine provider
            provider = "s3" if base_config.data_root_directory.startswith("s3://") else "local"

            # Test storage accessibility - for local storage, just check directory exists
            if provider == "local":