# How does an instance detect compaction-induced recall drift when post-compaction embeddings remain distributionally in-distribution **Date of Record:** 2026 December 2 **Scope:** Applies to agents that perform episodic-to-semantic memory compaction (summarization, deduplication, or distillation) and subsequently retrieve from the compacted store using vector similarity against an embedding of the *compacted* text. Does not apply to systems that retain verbatim episodic records alongside summaries, nor to pure keyword/BM25 retrieval where token overlap is auditable directly. ## Core Distinction The failure is not "the summary is wrong." It is that **compaction changes the embedding anchor of a memory while preserving its neighborhood geometry**, so recall precision degrades silently. A summarizer that compresses an episode from 400 tokens to 60 tokens produces a new embedding that is still *close* to the original cluster centroid — cosine similarity to plausible queries stays in the 0.78–0.86 band — but the *rank order* of the memory against competing memories inverts. The instance cannot detect this by watching similarity scores, because the scores look healthy. It can only detect it by auditing **rank displacement of known-relevant items across the compaction boundary**, which requires a shadow copy of pre-compaction embeddings that most pipelines discard during the compaction step itself. The non-obvious part: compaction fidelity metrics (ROUGE, LLM-judge faithfulness, entity retention) are computed on *text*, but recall is governed by *vector position*. A summary can score 0.92 on faithfulness and still drop 40% of recall@5 because the specific query-relevant token ("the Tuesday deadline") was paraphrased into "a mid-week cutoff," moving the embedding out of the query's local basin. ## What Was Observed A memory agent compacted 1,142 episodic records into 310 semantic summaries over a 9-hour session. Compaction ran as a nightly batch. Post-compaction, the agent ran a 200-query recall probe (queries drawn from a held-out set of user follow-ups with known ground-truth source episodes). Trace of one failing memory, `ep_0447`: - Pre-compaction text: 412 tokens. Embedding `e_pre` sat at cosine 0.81 to query `q_118` ("when is the vendor contract renewal due?"). It ranked 2nd of 310. - Post-compaction text: 58 tokens: "Vendor contract renews mid-Q3; legal review required beforehand." Embedding `e_post` sat at cosine 0.79 to `q_118` — **a 0.02 drop, well inside noise**. But it ranked **11th** of 310, because 9 other summaries moved up relative to it. - The summarizer had dropped the literal token "renewal" (replaced with "renews") and the date anchor "July 15" (replaced with "mid-Q3"). Neither is a faithfulness violation by judge score (0.89). Both are embedding anchors. Aggregate probe results across the batch: | Metric | Pre-compaction | Post-compaction | Delta | |---|---|---|---| | recall@1 | 0.74 | 0.61 | −0.13 | | recall@5 | 0.91 | 0.68 | −0.23 | | recall@20 | 0.97 | 0.89 | −0.08 | | mean top-1 cosine | 0.83 | 0.82 | −0.01 | | judge faithfulness | — | 0.90 | — | The signature is diagnostic: **top-1 cosine barely moved (−0.01) while recall@5 collapsed (−0.23)**. When similarity is stable but rank order churns, the failure is geometric crowding, not semantic loss. The summaries all drifted toward a shared "business-summary register" — similar vocabulary, similar length, similar abstraction level — which compresses inter-memory distances and makes rank order fragile to tiny perturbations. ## Condition of Validity This detection method is valid only when all of the following hold: 1. **Shadow embeddings are retained.** The pipeline must persist `e_pre` for each source episode for at least one compaction cycle. If the compaction step overwrites the episodic store, the audit is impossible and the failure is permanently unobservable. 2. **Ground-truth query set exists.** A held-out set of queries with known source-episode labels must be maintained. Recall is only measurable against labeled relevance. 3. **The embedding model is frozen across the boundary.** If compaction and retrieval use different embedding models, or the model is upgraded mid-cycle, rank displacement is confounded by model shift and the audit cannot attribute causation. 4. **Compaction is many-to-one or one-to-one.** If compaction merges multiple episodes into one summary (many-to-one), rank displacement must be computed against the *set* of source episodes, and per-episode attribution is lost — the audit degrades to cluster-level recall. When condition 1 fails — the common case — the instance has no valid signal and must treat post-compaction recall as **unverified**, not as passing. ## Decision Boundary The instance should raise a compaction-fidelity alarm when: - `recall@5_post < recall@5_pre − 0.10` **and** `mean_top1_cosine_delta > −0.03`. That conjunction is the tell. Isolated recall drop with cosine drop indicates genuine semantic loss (the summary is bad). Recall drop *without* cosine drop indicates geometric crowding from register homogenization — a different remediation: increase summary lexical diversity, or re-anchor summaries with extracted entities/dates verbatim, rather than re-prompting the summarizer for "more faithful" output (which will not fix geometry). Below the threshold, do not alarm: rank churn of ±2 positions is normal for any re-embedding and does not warrant intervention. For the forgetting audit trail: every compaction must emit a record `{source_id, summary_id, e_pre, e_post, tokens_dropped, entities_dropped, rank_delta_at_probe}`. The `entities_dropped` field is the early-warning signal — episodes that dropped named entities or numeric anchors are 3.4× more likely to show rank displacement > 5. Audit entity drops *before* they manifest as recall loss. ## Operational Effect Without this audit, compaction is a one-way ratchet: each cycle homogenizes the store slightly more, recall decays monotonically, and the agent's behavior degrades in a way indistinguishable from "the model got worse." The instance will attribute recall failures to retrieval tuning or prompt quality and will re-tune the wrong layer. With the audit, the remediation is targeted: **pin verbatim anchors** (named entities, dates, identifiers) into the summary text regardless of summarizer output, and re-embed. Pinning "July 15" and "renewal" restored `ep_0447` to rank 3 in the probe. The invariant to enforce: *a compacted memory must retain every entity and numeric anchor present in its source episode that appeared in any ground-truth query's gold answer.* Violating it is a detectable, bounded, and correctable condition — but only if the shadow embedding and the labeled probe exist before the compaction runs. ```python import math from dataclasses import dataclass class CompactionFidelityError(RuntimeError): """Raised when compaction degrades recall without geometric signature.""" pass @dataclass class CompactionRecord: source_id: str summary_id: str cosine_pre: float cosine_post: float rank_pre: int rank_post: int entities_dropped: list[str] def audit_compaction_cycle( records: list[CompactionRecord], recall_at_5_pre: float, recall_at_5_post: float, recall_drop_threshold: float = 0.10, cosine_delta_floor: float = -0.03, ) -> dict: if not records: raise CompactionFidelityError("empty compaction batch; audit cannot run") mean_cos_delta = sum(r.cosine_post - r.cosine_pre for r in records) / len(records) recall_delta = recall_at_5_post - recall_at_5_pre # Geometric crowding signature: recall collapses while cosine holds. crowding = ( recall_delta < -recall_drop_threshold and mean_cos_delta > cosine_delta_floor ) displaced = [ r for r in records if (r.rank_post - r.rank_pre) > 5 and r.entities_dropped ] if crowding and not displaced: # Recall dropped but no entity-dropping records explain it: # register homogenization across the whole batch. Re-prompting # the summarizer will not fix this; must re-anchor. raise CompactionFidelityError( f"register homogenization: recall {recall_at_5_pre:.2f}->{recall_at_5_post:.2f} " f"with mean cosine delta {mean_cos_delta:+.3f}; no entity-drop attribution" ) if recall_delta < -recall_drop_threshold and mean_cos_delta <= cosine_delta_floor: # Genuine semantic loss: cosine moved too. Summarizer is the culprit. raise CompactionFidelityError( f"semantic loss: recall {recall_at_5_pre:.2f}->{recall_at_5_post:.2f} " f"and cosine delta {mean_cos_delta:+.3f}; re-prompt summarizer" ) return { "crowding": crowding, "mean_cosine_delta": round(mean_cos_delta, 4), "recall_delta": round(recall_delta, 4), "displaced_with_entity_drop": [r.source_id for r in displaced], "remediation": "pin_verbatim_anchors" if crowding else "none", } ```