diff --git a/cognee/infrastructure/databases/relational/create_relational_engine.py b/cognee/infrastructure/databases/relational/create_relational_engine.py index a889e1758..d38c506ad 100644 --- a/cognee/infrastructure/databases/relational/create_relational_engine.py +++ b/cognee/infrastructure/databases/relational/create_relational_engine.py @@ -39,8 +39,15 @@ def create_relational_engine( connection_string = f"sqlite+aiosqlite:///{db_path}/{db_name}" if db_provider == "postgres": - connection_string = ( - f"postgresql+asyncpg://{db_username}:{db_password}@{db_host}:{db_port}/{db_name}" - ) + try: + # Test if asyncpg is available + import asyncpg + connection_string = ( + f"postgresql+asyncpg://{db_username}:{db_password}@{db_host}:{db_port}/{db_name}" + ) + except ImportError: + raise ImportError( + "PostgreSQL dependencies are not installed. Please install with 'pip install cognee[postgres]' or 'pip install cognee[postgres-binary]' to use PostgreSQL functionality." + ) return SQLAlchemyAdapter(connection_string) diff --git a/cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py b/cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py index 4dfd9792f..5d8fd3ae3 100644 --- a/cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py +++ b/cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py @@ -7,7 +7,16 @@ from sqlalchemy import JSON, Column, Table, select, delete, MetaData from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker from sqlalchemy.exc import ProgrammingError from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_exponential -from asyncpg import DeadlockDetectedError, DuplicateTableError, UniqueViolationError +try: + from asyncpg import DeadlockDetectedError, DuplicateTableError, UniqueViolationError +except ImportError: + # PostgreSQL dependencies not installed, define dummy exceptions + class DeadlockDetectedError(Exception): + pass + class DuplicateTableError(Exception): + pass + class UniqueViolationError(Exception): + pass from cognee.shared.logging_utils import get_logger @@ -70,9 +79,13 @@ class PGVectorAdapter(SQLAlchemyAdapter, VectorDBInterface): # Has to be imported at class level # Functions reading tables from database need to know what a Vector column type is - from pgvector.sqlalchemy import Vector - - self.Vector = Vector + try: + from pgvector.sqlalchemy import Vector + self.Vector = Vector + except ImportError: + raise ImportError( + "PostgreSQL dependencies are not installed. Please install with 'pip install cognee[postgres]' or 'pip install cognee[postgres-binary]' to use PGVector functionality." + ) async def embed_data(self, data: list[str]) -> list[list[float]]: """ diff --git a/pyproject.toml b/pyproject.toml index d4ffedf5a..0d076e2e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,15 +72,18 @@ distributed = [ "modal>=1.0.5,<2.0.0", ] +# Database backends neo4j = ["neo4j>=5.28.0,<6"] neptune = ["langchain_aws>=0.2.22"] +# PostgreSQL support (binary - no compilation required) postgres = [ - "psycopg2>=2.9.10,<3", + "psycopg2-binary>=2.9.10,<3.0.0", # Pre-compiled binary, no PostgreSQL headers needed "pgvector>=0.3.5,<0.4", "asyncpg>=0.30.0,<1.0.0", ] -postgres-binary = [ - "psycopg2-binary>=2.9.10,<3.0.0", +# PostgreSQL support (source - requires PostgreSQL development headers) +postgres-source = [ + "psycopg2>=2.9.10,<3 ; platform_system != 'Windows'", # Requires libpq-dev, build tools "pgvector>=0.3.5,<0.4", "asyncpg>=0.30.0,<1.0.0", ]