mem0ai/mem0 · error · ImportError

Neither 'psycopg' nor 'psycopg2' library is available. Pleas

Error message

Neither 'psycopg' nor 'psycopg2' library is available. Please install one of them using 'pip install psycopg[pool]' or 'pip install psycopg2'

What it means

Error "Neither 'psycopg' nor 'psycopg2' library is available. Please install one of them using 'pip install psycopg[pool]' or 'pip install psycopg2'" thrown in mem0ai/mem0.

Source

Thrown at mem0/vector_stores/pgvector.py:27

# Try to import psycopg (psycopg3) first, then fall back to psycopg2
try:
    from psycopg import sql
    from psycopg.types.json import Json
    from psycopg_pool import ConnectionPool
    PSYCOPG_VERSION = 3
    logger = logging.getLogger(__name__)
    logger.info("Using psycopg (psycopg3) with ConnectionPool for PostgreSQL connections")
except ImportError:
    try:
        from psycopg2 import sql
        from psycopg2.extras import Json, execute_values
        from psycopg2.pool import ThreadedConnectionPool as ConnectionPool
        PSYCOPG_VERSION = 2
        logger = logging.getLogger(__name__)
        logger.info("Using psycopg2 with ThreadedConnectionPool for PostgreSQL connections")
    except ImportError:
        raise ImportError(
            "Neither 'psycopg' nor 'psycopg2' library is available. "
            "Please install one of them using 'pip install psycopg[pool]' or 'pip install psycopg2'"
        )

from mem0.vector_stores.base import VectorStoreBase

logger = logging.getLogger(__name__)

OPERATOR_SQL_MAP = {
    "eq": ("payload->>%s = %s", False),
    "ne": ("payload->>%s != %s", False),
    "gt": ("(payload->>%s)::numeric > %s", True),
    "gte": ("(payload->>%s)::numeric >= %s", True),
    "lt": ("(payload->>%s)::numeric < %s", True),
    "lte": ("(payload->>%s)::numeric <= %s", True),
    "in": ("payload->>%s = ANY(%s)", False),
    "nin": ("NOT (payload->>%s = ANY(%s))", False),
    "contains": ("payload->>%s LIKE %s", False),

View on GitHub (pinned to 001c235229)

Solutions

  1. Install the driver: pip install 'psycopg[pool]' or pip install psycopg2.

When it happens

Trigger: Thrown at mem0/vector_stores/pgvector.py:27 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/c269924a739cc79f. Report an issue: GitHub.