{"record":{"id":"3991a74cc25f1405","repo":"MemPalace/mempalace","slug":"pgvector-marker-does-not-identify-the-pgvector-bac","errorCode":null,"errorMessage":"pgvector marker does not identify the pgvector backend","messagePattern":"pgvector marker does not identify the pgvector backend","errorType":"exception","errorClass":"BackendMismatchError","httpStatus":null,"severity":"error","filePath":"mempalace/backends/pgvector.py","lineNumber":1427,"sourceCode":"    def _read_marker(self, palace: PalaceRef) -> Optional[dict]:\n        if not palace.local_path:\n            return None\n        marker_path = self._marker_path(palace.local_path)\n        if not os.path.isfile(marker_path):\n            return None\n        try:\n            with open(marker_path, encoding=\"utf-8\") as f:\n                marker = json.load(f)\n        except (OSError, json.JSONDecodeError) as exc:\n            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","sourceCodeStart":1409,"sourceCodeEnd":1445,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/backends/pgvector.py#L1409-L1445","documentation":"The palace marker JSON must contain \"backend\": \"pgvector\" to prove it was created by this backend. If the backend field is absent or names a different backend (e.g. \"chroma\"), PgVectorBackend refuses to open the palace with BackendMismatchError — opening a ChromaDB palace against pgvector would silently strand the existing data.","triggerScenarios":"Pointing the pgvector backend (MEMPALACE_PGVECTOR_DSN set / backend=\"pgvector\") at a palace directory whose marker was written by the ChromaDB or qdrant backend; a hand-edited marker with a renamed backend field.","commonSituations":"Migrating between backends without a fresh palace directory; switching MEMPALACE_BACKEND env var while reusing the same local palace path.","solutions":["Use a fresh palace directory when switching to the pgvector backend, then re-ingest.","Or migrate properly via the exporter/migrate tooling rather than re-pointing the same directory.","Set the backend configuration consistently (env/config) with the palace you are opening."],"exampleFix":"# before\n# same palace dir previously used with chroma\nMEMPALACE_BACKEND=pgvector palace.get_collection(\"notes\")\n\n# after\n# fresh dir for the new backend\nMEMPALACE_BACKEND=pgvector MEMPALACE_PALACE=~/palaces/pg-new palace.get_collection(\"notes\", create=True)","handlingStrategy":"validation","validationCode":"marker = json.load(open(marker_path, encoding=\"utf-8\"))\nassert marker.get(\"backend\") == \"pgvector\", f\"palace belongs to {marker.get('backend')}\"","typeGuard":"def marker_matches_backend(marker: dict, name: str) -> bool:\n    return isinstance(marker, dict) and marker.get(\"backend\") == name","tryCatchPattern":"try:\n    col = palace.get_collection(\"notes\")\nexcept BackendMismatchError as e:\n    if \"does not identify\" in str(e):\n        raise RuntimeError(\"palace directory was created by another backend; use a fresh directory\")","preventionTips":["One palace directory per backend; never share directories across backends.","Set backend config via environment once, at deployment time, not per-command.","When migrating backends, always create a new palace directory and re-ingest."],"tags":["pgvector","marker-file","backend-mismatch","migration"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}