MemPalace/mempalace · error · BackendError

pgvector backend requires the optional 'psycopg' dependency;

Error message

pgvector backend requires the optional 'psycopg' dependency; install mempalace[pgvector]

What it means

Error "pgvector backend requires the optional 'psycopg' dependency; install mempalace[pgvector]" thrown in MemPalace/mempalace.

Source

Thrown at mempalace/backends/pgvector.py:513

            dsn=str(dsn).strip() or _DEFAULT_DSN,
            namespace=str(namespace).strip() or None if namespace else None,
        )


class _PgVectorClient:
    """Thin psycopg wrapper. ``psycopg`` is imported lazily on first connect."""

    def __init__(self, config: _PgVectorConfig):
        self._config = config
        self._conn = None
        self._closed = False
        self._lock = threading.RLock()

    def _connect(self):
        try:
            import psycopg
        except ImportError as exc:  # pragma: no cover - exercised only without the extra
            raise BackendError(
                "pgvector backend requires the optional 'psycopg' dependency; "
                "install mempalace[pgvector]"
            ) from exc
        # One client is shared across threads (PgVectorBackend caches a
        # single instance per config), so the read-create-store on self._conn
        # must hold the same lock _execute serializes on; unlocked, two
        # first-connect threads each opened a connection and the loser leaked
        # unclosed. The RLock makes the _execute -> _connect nesting safe. A
        # stalled connect blocks peers under the lock the same way any
        # in-flight query on this single shared connection already does.
        with self._lock:
            if self._closed:
                raise BackendError("pgvector client has been closed")
            if self._conn is not None and not getattr(self._conn, "closed", False):
                return self._conn
            try:
                self._conn = psycopg.connect(self._config.dsn)
            except Exception as exc:  # noqa: BLE001 - surface any driver failure uniformly

View on GitHub (pinned to 06cb6987f0)

Solutions

  1. Install the optional dependency: pip install 'mempalace[pgvector]' (provides psycopg)

When it happens

Trigger: Thrown at mempalace/backends/pgvector.py:513 when the library encounters an invalid state.

Common situations: pgvector backend selected without the psycopg driver installed.


AI-assisted analysis of MemPalace/mempalace@06cb6987f0 (2026-08-15). Data as JSON: /api/errors/022dfabc09bf5a50. Report an issue: GitHub.