{"record":{"id":"022dfabc09bf5a50","repo":"MemPalace/mempalace","slug":"pgvector-backend-requires-the-optional-psycopg-d","errorCode":null,"errorMessage":"pgvector backend requires the optional 'psycopg' dependency; install mempalace[pgvector]","messagePattern":"pgvector backend requires the optional 'psycopg' dependency; install mempalace\\[pgvector\\]","errorType":"exception","errorClass":"BackendError","httpStatus":null,"severity":"error","filePath":"mempalace/backends/pgvector.py","lineNumber":513,"sourceCode":"            dsn=str(dsn).strip() or _DEFAULT_DSN,\n            namespace=str(namespace).strip() or None if namespace else None,\n        )\n\n\nclass _PgVectorClient:\n    \"\"\"Thin psycopg wrapper. ``psycopg`` is imported lazily on first connect.\"\"\"\n\n    def __init__(self, config: _PgVectorConfig):\n        self._config = config\n        self._conn = None\n        self._closed = False\n        self._lock = threading.RLock()\n\n    def _connect(self):\n        try:\n            import psycopg\n        except ImportError as exc:  # pragma: no cover - exercised only without the extra\n            raise BackendError(\n                \"pgvector backend requires the optional 'psycopg' dependency; \"\n                \"install mempalace[pgvector]\"\n            ) from exc\n        # One client is shared across threads (PgVectorBackend caches a\n        # single instance per config), so the read-create-store on self._conn\n        # must hold the same lock _execute serializes on; unlocked, two\n        # first-connect threads each opened a connection and the loser leaked\n        # unclosed. The RLock makes the _execute -> _connect nesting safe. A\n        # stalled connect blocks peers under the lock the same way any\n        # in-flight query on this single shared connection already does.\n        with self._lock:\n            if self._closed:\n                raise BackendError(\"pgvector client has been closed\")\n            if self._conn is not None and not getattr(self._conn, \"closed\", False):\n                return self._conn\n            try:\n                self._conn = psycopg.connect(self._config.dsn)\n            except Exception as exc:  # noqa: BLE001 - surface any driver failure uniformly","sourceCodeStart":495,"sourceCodeEnd":531,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/backends/pgvector.py#L495-L531","documentation":"Error \"pgvector backend requires the optional 'psycopg' dependency; install mempalace[pgvector]\" thrown in MemPalace/mempalace.","triggerScenarios":"Thrown at mempalace/backends/pgvector.py:513 when the library encounters an invalid state.","commonSituations":"pgvector backend selected without the psycopg driver installed.","solutions":["Install the optional dependency: pip install 'mempalace[pgvector]' (provides psycopg)"],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}