MemPalace/mempalace · error · BackendMismatchError

pgvector marker target does not match current configuration

Error message

pgvector marker target does not match current configuration ({details}); keep MEMPALACE_PGVECTOR_DSN and namespace consistent or use a fresh palace directory

What it means

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.

Source

Thrown at mempalace/backends/pgvector.py:1437

            raise BackendMismatchError(f"pgvector marker is unreadable: {marker_path}") from exc
        return marker if isinstance(marker, dict) else {}

    def _validate_marker_target(self, palace: PalaceRef, config: _PgVectorConfig) -> None:
        marker = self._read_marker(palace)
        if marker is None:
            return
        if marker.get("backend") != self.name:
            raise BackendMismatchError("pgvector marker does not identify the pgvector backend")
        expected = self._marker_target(palace, config)
        actual = marker.get("pgvector")
        if not isinstance(actual, dict):
            raise BackendMismatchError("pgvector marker is missing target metadata")
        mismatched = [
            key for key, expected_value in expected.items() if actual.get(key) != expected_value
        ]
        if mismatched:
            details = ", ".join(mismatched)
            raise BackendMismatchError(
                "pgvector marker target does not match current configuration "
                f"({details}); keep MEMPALACE_PGVECTOR_DSN and namespace consistent "
                "or use a fresh palace directory"
            )

    def _write_marker(self, palace: PalaceRef, config: _PgVectorConfig) -> None:
        if not palace.local_path:
            return
        os.makedirs(palace.local_path, exist_ok=True)
        try:
            os.chmod(palace.local_path, 0o700)
        except (OSError, NotImplementedError):
            pass
        marker = {
            "backend": self.name,
            "schema_version": 1,
            "created_at": _utcnow(),
            "palace_id": palace.id,

View on GitHub (pinned to 06cb6987f0)

Solutions

  1. Restore the DSN/namespace recorded in the marker (shown by the mismatched keys) if the original database is still the intended one.
  2. If the new target is intentional, use a fresh palace directory so a new marker is written.
  3. Drop and recreate the palace (re-ingest) if you must keep the same directory with a new target.

Example fix

# before
# palace built with DSN A
export MEMPALACE_PGVECTOR_DSN=postgres://other-host/db
col = palace.get_collection("notes")  # BackendMismatchError

# after
# either point back: export MEMPALACE_PGVECTOR_DSN=postgres://orig-host/db
# or use a fresh palace dir for the new DSN
Defensive patterns

Strategy: try-catch

Validate before calling

marker = json.load(open(marker_path, encoding="utf-8"))
target = marker.get("pgvector", {})
if target.get("dsn") != os.environ.get("MEMPALACE_PGVECTOR_DSN"):
    raise RuntimeError("DSN drift detected; fix env or use a fresh palace dir")

Type guard

def target_matches_config(marker: dict, dsn: str, namespace: str) -> bool:
    t = marker.get("pgvector") or {}
    return t.get("dsn") == dsn and t.get("namespace") == namespace

Try / catch

try:
    col = palace.get_collection("notes")
except BackendMismatchError as e:
    if "does not match current configuration" in str(e):
        logger.error("DSN/namespace drift: %s", e)
        raise SystemExit("restore the original DSN/namespace or use a fresh palace directory")

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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