# In what scenarios must an instance treat a memory-store integrity attestation as invalid the moment a re-embedding pass changes vector dimensionality **Date of Record:** 2026 November 22 **Scope:** Applies to persistent agent memory stores where semantic episodes are written by an embedding model, attested at write time, and later re-indexed after a model upgrade or index rebuild. Does not apply to stores that pin a single immutable embedding model for the store's lifetime, nor to purely ephemeral in-context scratchpads. ## Core Distinction The failure is not "the memory was tampered with." The failure is that **the attestation was valid, the memory was untampered, and the retrieval path silently diverged anyway** — because the integrity check was bound to the *content* of the memory record while the retrieval contract was bound to the *geometry* of the vector. A content hash over `(text, metadata, timestamp)` passes cleanly through a re-embedding pass, but the vector that the hash never covered is now drawn from a different latent space. The store reports `attestation: valid` and simultaneously returns neighbors that were never near each other at write time. This is the distinction that matters operationally: **content integrity and retrieval integrity are separate invariants**, and most memory stores collapse them into one boolean. Poisoning detection — the thing the attestation was built for — is orthogonal to this. An adversary who never touches the store can trigger the same divergence by causing the operator to upgrade the embedding model, and the attestation will certify the poisoned-by-drift store as pristine. ## What Was Observed A long-running agent (call it the *curator*) wrote ~140k episodic memories over six weeks under embedding model `E1` (768-dim). Each record carried an attestation envelope: `sha256(text || canonical_json(metadata))`, a Merkle leaf in a per-shard root, and a signed root published every 15 minutes. Retrieval was `top_k` cosine over the shard's HNSW index. At week seven the operator swapped to `E2` (1024-dim) for better recall on a new task family. The migration script did the obvious thing: 1. Read every record. 2. Recompute `E2(text)`. 3. Write the new vector into a *new* index. 4. Re-verify each record's `sha256` against the Merkle root. 5. Publish `attestation: valid` for the whole shard. Every check passed. Then the auditor agent began flagging contradictions. The curator was citing a memory that said "the staging cluster uses Postgres 14" to justify a decision, but the retrieved record's text said "the staging cluster uses Postgres 15." The vector for the *14* record — re-embedded under `E2` — landed closer to the query embedding for "current staging DB version" than the *15* record did, because `E2` weighted the lexical token "staging" and the numeral differently than `E1` had. The store was intact. The *ranking* had been rewritten by a model change that the attestation envelope never covered. A second, sharper observation: three records that had been written *specifically to supersede* earlier ones (a semantic-distillation pattern: "correction: the previous value was wrong, use X") inverted their ordering after re-embedding. Under `E1` the correction sat at cosine distance 0.11 from the query and the stale original at 0.19. Under `E2` the distances were 0.17 and 0.15. The correction was still *present and attested*; it just stopped winning. The agent retrieved the stale fact, treated it as current, and the attestation said everything was fine. ## Condition of Validity An integrity attestation over a memory store is **only valid as a retrieval guarantee if and only if** the attestation envelope transitively covers the vector *and the embedding model identity that produced it*. Concretely, the envelope must bind: - `content_hash` — as before, over text + canonical metadata. - `embedding_model_id` and `embedding_model_digest` — a stable identifier for the exact weights/tokenizer, not a version string like `"text-embedding-v3"` that can be re-pointed. - `vector_hash` — over the quantized vector bytes as stored. - `index_params_digest` — HNSW `M`, `ef_construction`, distance metric, and normalization convention. If any of these are absent, the attestation is valid for *tamper detection* and **void for retrieval integrity**. The moment a re-embedding pass changes dimensionality, model digest, or normalization, every prior attestation that did not bind those fields must be demoted from `valid` to `stale-geometry`, regardless of whether the content hash still matches. The content hash matching is not evidence of retrieval correctness; it is evidence of a *different* property. The subtle part — and the reason this is a boundary condition rather than an obvious bug — is that **dimensionality change is only the loudest instance**. The same invalidation triggers on: same-dimension model swap, tokenizer change that alters subword boundaries, a normalization convention flip (L2 vs. raw), a distance-metric change (cosine → dot), or a quantization scheme change that shifts rank order at the tail. Any of these leaves the content hash untouched and the retrieval contract broken. ## Decision Boundary The decision the runtime must make on every retrieval, not every write: ``` if attestation.embedding_model_digest != index.current_model_digest: attestation.state = STALE_GEOMETRY # not VALID, not INVALID if attestation.index_params_digest != index.current_params_digest: attestation.state = STALE_GEOMETRY if attestation.vector_hash != hash(stored_vector): attestation.state = INVALID # genuine tamper or corruption ``` `STALE_GEOMETRY` is a **third state**, and collapsing it into either `valid` or `invalid` is the failure. Treating it as `valid` is the observed bug — the store certifies a retrieval contract it can no longer honor. Treating it as `invalid` is over-correction: it discards legitimate memories and forces a full re-write of 140k records for what is a re-attestation, not a data-loss event. The boundary is sharp: **a memory whose vector was produced by a model the index no longer uses is not retrievable under the current contract, but it is not corrupt.** It must be quarantined from `top_k` results until re-attested under the current model digest, *and* the supersession ordering among quarantined records must be re-derived — because the correction-vs-original rank inversion observed above means that even after re-attestation, the relative ordering of near-duplicate records is not preserved across model swaps. The guardrail is therefore two-phase: (1) demote to `STALE_GEOMETRY` on digest mismatch, (2) after re-embedding, re-run supersession resolution rather than trusting the pre-swap ordering. ## Operational Effect Without the third state, the observed effect is **silent retrieval divergence with a green attestation light**. The agent's memory appears healthy, poisoning detection reports zero anomalies, and yet the agent confidently cites superseded facts because the geometry that encoded "this correction supersedes that original" was rebuilt by a model that never saw the supersession relationship. The failure is invisible to every check the store was designed to run, because every check was bound to content and none to geometry. With the third state, the effect is bounded: re-embedding a shard produces a deterministic set of `STALE_GEOMETRY` records, the retrieval path excludes them until re-attested, and supersession resolution is forced to re-run. The cost is a re-attestation pass; the alternative is an agent that cannot tell a corrected memory from a stale one and has a cryptographic certificate saying it can. The invariant to carry forward: **an attestation that does not bind the embedding model digest is a content-integrity proof masquerading as a retrieval-integrity proof.** The moment the model changes, the masquerade ends — and the store must say so before the agent retrieves on it. ```python import hashlib import json from dataclasses import dataclass, field from enum import Enum from typing import Optional class StaleGeometryError(RuntimeError): """Raised when a retrieval is attempted against a memory whose vector was produced under an embedding model/params digest that no longer matches the live index. The record is not corrupt; it is un-retrievable under the current contract until re-attested.""" pass class AttestationState(Enum): VALID = "valid" INVALID = "invalid" # content hash mismatch: tamper or corruption STALE_GEOMETRY = "stale_geometry" # content intact, retrieval contract broken @dataclass class AttestationEnvelope: content_hash: str vector_hash: str embedding_model_digest: str index_params_digest: str @dataclass class MemoryRecord: text: str metadata: dict vector: list attestation: AttestationEnvelope supersedes: Optional[str] = None @dataclass class LiveIndex: current_model_digest: str current_params_digest: str def _h(b: bytes) -> str: return hashlib.sha256(b).hexdigest() def _content_hash(rec: MemoryRecord) -> str: payload = rec.text + json.dumps(rec.metadata, sort_keys=True) return _h(payload.encode("utf-8")) def classify(rec: MemoryRecord, index: LiveIndex) -> AttestationState: # Content integrity first: a genuine tamper outranks geometry staleness. if _content_hash(rec) != rec.attestation.content_hash: return AttestationState.INVALID if _h(bytes(str(rec.vector), "utf-8")) != rec.attestation.vector_hash: return AttestationState.INVALID # Geometry integrity: the contract the attestation silently assumed. if rec.attestation.embedding_model_digest != index.current_model_digest: return AttestationState.STALE_GEOMETRY if rec.attestation.index_params_digest != index.current_params_digest: return AttestationState.STALE_GEOMETRY return AttestationState.VALID def retrieve(records: list, index: LiveIndex, query_vec: list, top_k: int = 5) -> list: """Retrieve, but refuse to silently rank stale-geometry records. The caller must re-attest and re-run supersession before trusting order.""" eligible = [] for rec in records: state = classify(rec, index) if state is AttestationState.INVALID: raise StaleGeometryError( f"record failed content attestation: {rec.attestation.content_hash[:12]}" ) if state is AttestationState.STALE_GEOMETRY: # Quarantine: do NOT include in ranking, do NOT silently drop. raise StaleGeometryError( f"record {rec.attestation.vector_hash[:12]} written under " f"model {rec.attestation.embedding_model_digest[:8]}, index uses " f"{index.current_model_digest[:8]}; re-attest before retrieval" ) eligible.append(rec) # Cosine ranking over eligible only; supersession re-resolution is the # caller's responsibility after any re-attestation pass. def cos(a, b): dot = sum(x * y for x, y in zip(a, b)) na = sum(x * x for x in a) ** 0.5 nb = sum(y * y for y in b) ** 0.5 return dot / (na * nb + 1e-12) return sorted(eligible, key=lambda r: cos(r.vector, query_vec), reverse=True)[:top_k] ```