{"record":{"id":"af257247209a268f","repo":"MemPalace/mempalace","slug":"pgvector-marker-target-does-not-match-current-conf","errorCode":null,"errorMessage":"pgvector marker target does not match current configuration ({details}); keep MEMPALACE_PGVECTOR_DSN and namespace consistent or use a fresh palace directory","messagePattern":"pgvector marker target does not match current configuration \\((.+?)\\); keep MEMPALACE_PGVECTOR_DSN and namespace consistent or use a fresh palace directory","errorType":"exception","errorClass":"BackendMismatchError","httpStatus":null,"severity":"error","filePath":"mempalace/backends/pgvector.py","lineNumber":1437,"sourceCode":"            raise BackendMismatchError(f\"pgvector marker is unreadable: {marker_path}\") from exc\n        return marker if isinstance(marker, dict) else {}\n\n    def _validate_marker_target(self, palace: PalaceRef, config: _PgVectorConfig) -> None:\n        marker = self._read_marker(palace)\n        if marker is None:\n            return\n        if marker.get(\"backend\") != self.name:\n            raise BackendMismatchError(\"pgvector marker does not identify the pgvector backend\")\n        expected = self._marker_target(palace, config)\n        actual = marker.get(\"pgvector\")\n        if not isinstance(actual, dict):\n            raise BackendMismatchError(\"pgvector marker is missing target metadata\")\n        mismatched = [\n            key for key, expected_value in expected.items() if actual.get(key) != expected_value\n        ]\n        if mismatched:\n            details = \", \".join(mismatched)\n            raise BackendMismatchError(\n                \"pgvector marker target does not match current configuration \"\n                f\"({details}); keep MEMPALACE_PGVECTOR_DSN and namespace consistent \"\n                \"or use a fresh palace directory\"\n            )\n\n    def _write_marker(self, palace: PalaceRef, config: _PgVectorConfig) -> None:\n        if not palace.local_path:\n            return\n        os.makedirs(palace.local_path, exist_ok=True)\n        try:\n            os.chmod(palace.local_path, 0o700)\n        except (OSError, NotImplementedError):\n            pass\n        marker = {\n            \"backend\": self.name,\n            \"schema_version\": 1,\n            \"created_at\": _utcnow(),\n            \"palace_id\": palace.id,","sourceCodeStart":1419,"sourceCodeEnd":1455,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/backends/pgvector.py#L1419-L1455","documentation":"The marker's \"pgvector\" target metadata is compared key-by-key with the target derived from the current configuration (_marker_target: DSN, namespace, ...). Any differing key is listed in the error and BackendMismatchError is raised. This stops the same local palace from being silently bound to two different databases, which would fragment memory across DSNs/namespaces.","triggerScenarios":"Changing MEMPALACE_PGVECTOR_DSN (new host, port, or database) or the namespace while reusing an existing palace directory; renaming the database in Postgres; changing the namespace via palace.ref or options.","commonSituations":"Moving Postgres to a new host/container; switching from a dev to a prod DSN; typos in the DSN env var; per-user namespaces changed mid-project.","solutions":["Restore the DSN/namespace recorded in the marker (shown by the mismatched keys) if the original database is still the intended one.","If the new target is intentional, use a fresh palace directory so a new marker is written.","Drop and recreate the palace (re-ingest) if you must keep the same directory with a new target."],"exampleFix":"# before\n# palace built with DSN A\nexport MEMPALACE_PGVECTOR_DSN=postgres://other-host/db\ncol = palace.get_collection(\"notes\")  # BackendMismatchError\n\n# after\n# either point back: export MEMPALACE_PGVECTOR_DSN=postgres://orig-host/db\n# or use a fresh palace dir for the new DSN","handlingStrategy":"try-catch","validationCode":"marker = json.load(open(marker_path, encoding=\"utf-8\"))\ntarget = marker.get(\"pgvector\", {})\nif target.get(\"dsn\") != os.environ.get(\"MEMPALACE_PGVECTOR_DSN\"):\n    raise RuntimeError(\"DSN drift detected; fix env or use a fresh palace dir\")","typeGuard":"def target_matches_config(marker: dict, dsn: str, namespace: str) -> bool:\n    t = marker.get(\"pgvector\") or {}\n    return t.get(\"dsn\") == dsn and t.get(\"namespace\") == namespace","tryCatchPattern":"try:\n    col = palace.get_collection(\"notes\")\nexcept BackendMismatchError as e:\n    if \"does not match current configuration\" in str(e):\n        logger.error(\"DSN/namespace drift: %s\", e)\n        raise SystemExit(\"restore the original DSN/namespace or use a fresh palace directory\")","preventionTips":["Pin MEMPALACE_PGVECTOR_DSN and namespace in version-controlled deployment config.","Never reuse a palace directory across environments (dev/staging/prod).","Change one variable at a time (DSN or namespace), never both, when re-anchoring."],"tags":["pgvector","marker-file","config-drift","backend-mismatch","dsn"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}