{"record":{"id":"a9c53156b435058a","repo":"MemPalace/mempalace","slug":"pgvector-marker-is-missing-target-metadata","errorCode":null,"errorMessage":"pgvector marker is missing target metadata","messagePattern":"pgvector marker is missing target metadata","errorType":"exception","errorClass":"BackendMismatchError","httpStatus":null,"severity":"error","filePath":"mempalace/backends/pgvector.py","lineNumber":1431,"sourceCode":"        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\n        os.makedirs(palace.local_path, exist_ok=True)\n        try:\n            os.chmod(palace.local_path, 0o700)\n        except (OSError, NotImplementedError):","sourceCodeStart":1413,"sourceCodeEnd":1449,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/backends/pgvector.py#L1413-L1449","documentation":"A valid pgvector marker must carry a \"pgvector\" object describing its target (DSN/namespace). If that object is missing or not a dict, _validate_marker_target raises BackendMismatchError because the backend cannot verify the palace is bound to the expected database — an incomplete anchor is treated as a mismatch rather than ignored.","triggerScenarios":"Marker JSON like {\"backend\": \"pgvector\"} with no \"pgvector\" key, or \"pgvector\": \"host:5432\" (a string instead of an object); caused by manual editing, an older-format marker, or corrupted writes.","commonSituations":"Upgrading from an older MemPalace version whose marker format lacked the target block; hand-crafting a marker to 'fix' another error; partial file writes.","solutions":["Delete the incomplete marker and reopen the palace with create=True to rewrite it from the current configuration.","If you must hand-edit, restore the full structure: {\"backend\": \"pgvector\", \"pgvector\": {\"dsn\": ..., \"namespace\": ...}}.","Otherwise start a fresh palace directory and re-ingest."],"exampleFix":"# before\n# marker: {\"backend\": \"pgvector\"}  (no \"pgvector\" target object)\ncol = palace.get_collection(\"notes\")\n\n# after\nos.remove(marker_path)\ncol = palace.get_collection(\"notes\", create=True)  # rewrites full marker","handlingStrategy":"try-catch","validationCode":"marker = json.load(open(marker_path, encoding=\"utf-8\"))\nif not isinstance(marker.get(\"pgvector\"), dict):\n    raise RuntimeError(\"incomplete pgvector marker; recreate palace or re-anchor with create=True\")","typeGuard":"def has_pgvector_target(marker: dict) -> bool:\n    return isinstance(marker.get(\"pgvector\"), dict)","tryCatchPattern":"try:\n    palace.get_collection(\"notes\")\nexcept BackendMismatchError as e:\n    if \"missing target metadata\" in str(e):\n        os.remove(marker_path)\n        palace.get_collection(\"notes\", create=True)","preventionTips":["Do not hand-craft marker files; let the backend write them.","After a MemPalace upgrade, open each palace once with create=False to verify markers are still valid."],"tags":["pgvector","marker-file","backend-mismatch","migration"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}