Memory → Conflict resolution (supersede, don't accumulate)
What it is
A user says in January "I work on the German entity", and in June "I've moved to the UK entity". A naive memory store now contains both. Retrieval returns both. The model picks one — and which one depends on retrieval order, embedding scores, and luck.
Supersession makes the change explicit:
memory: {field: "default_entity", value: "Acme GmbH", valid_from: 2024-01-15, superseded_by: "m_842"}
memory: {id: "m_842", field: "default_entity", value: "Acme UK Ltd", valid_from: 2024-06-03, superseded_by: null}
retrieval filter: superseded_by IS NULL → only "Acme UK Ltd" is ever injected
audit trail: the January fact is still there, marked, for "what did we believe then"
Conflicts arise from four sources, each needing different handling:
| Source | Example | Resolution |
|---|---|---|
| Temporal change | Entity changed in June | Newest wins; supersede |
| Contradiction with evidence | Memory says "user prefers EUR"; the retrieved policy says the account is USD-only | Retrieved document wins; flag the memory |
| Inference vs statement | Inferred "role: analyst"; user later says "I'm a manager" | User statement wins regardless of recency ordering |
| Genuine ambiguity | User works across two entities | Not a conflict — the field is multi-valued or scope-dependent; fix the schema |
How to implement
- Upsert semantics on write: look up the same
(user, field); if the value matches, refreshlast_seen; if it differs, mark the old recordsuperseded_bythe new one and insert. valid_fromon every fact, and never mutate a stored value — supersession creates a new row, preserving history.- Precedence rules, in order: explicit user statement > profile sync from a system of record > inference; then, within the same source, newest wins.
- Retrieval filters superseded records in the shared filter (how to forget) so old values can never reach a prompt.
- Evidence beats memory: instruct the model that retrieved documents override memories, and detect the contradiction so the memory can be flagged.
- Detect contradictions among injected memories before generation (cheap NLI or a rule per field) — if two active memories for the same field survive, that's a bug; alert.
- Ask the user when it matters: for high-impact fields, confirm the change rather than silently superseding ("You mentioned the UK entity — should I use that from now on?").
Small example
SOURCE_PRECEDENCE = {"user_stated": 3, "profile_sync": 2, "inferred": 1}
def upsert_semantic_fact(conn, user, field, value, source, confidence, valid_from=None):
valid_from = valid_from or datetime.now(timezone.utc)
cur = conn.execute("""SELECT id, value, source, valid_from FROM memories
WHERE user_id=%s AND field=%s AND superseded_by IS NULL AND deleted_at IS NULL""",
(user.id, field)).fetchone()
if cur:
cur_id, cur_value, cur_source, cur_from = cur
if normalise(cur_value) == normalise(value):
conn.execute("UPDATE memories SET last_seen=now(), retrieval_count=retrieval_count "
"WHERE id=%s", (cur_id,))
return {"action": "refreshed", "id": cur_id}
# precedence: a weaker source may not overwrite a stronger, more recent one
if (SOURCE_PRECEDENCE[source] < SOURCE_PRECEDENCE[cur_source]) and cur_from > valid_from - timedelta(days=90):
log_memory_conflict(user.id, field, cur_value, value, resolution="kept_stronger_source")
return {"action": "rejected", "reason": "weaker source than existing fact"}
new_id = insert_memory(conn, user, field, value, source, confidence, valid_from)
conn.execute("UPDATE memories SET superseded_by=%s WHERE id=%s", (new_id, cur_id))
log_memory_conflict(user.id, field, cur_value, value, resolution="superseded")
return {"action": "superseded", "id": new_id, "previous": cur_id,
"confirm_with_user": field in HIGH_IMPACT_FIELDS}
return {"action": "inserted", "id": insert_memory(conn, user, field, value, source, confidence, valid_from)}
HIGH_IMPACT_FIELDS = {"default_entity", "region", "reporting_currency", "role"}
# --- retrieval-time safety net: two active facts for one field is a bug ---
def assert_no_active_conflicts(memories):
by_field = {}
for m in memories:
if m["kind"] != "semantic":
continue
if m["field"] in by_field and by_field[m["field"]] != m["value"]:
alert_memory_conflict(m["field"], by_field[m["field"]], m["value"])
# keep the newer one only
by_field[m["field"]] = m["value"]
return by_field
# --- evidence overrides memory ---
MEMORY_PRECEDENCE_INSTRUCTION = """<memory_block> contains background about the user, not facts about the domain.
If a memory contradicts a passage in <context>, the passage is authoritative. Note the contradiction in your answer."""
def detect_memory_evidence_conflict(memories, chunks):
conflicts = []
for m in memories:
for c in chunks[:4]:
r = nli(f"{c['text'][:900]} [SEP] {m['text']}", truncation=True)[0]
if "contradict" in r["label"].lower() and r["score"] > 0.85:
conflicts.append({"memory": m["text"], "chunk_id": c["chunk_id"], "score": float(r["score"])})
flag_memory_for_review(m) # queue for correction (feedback capture & triage)
return conflicts
Pros
- Deterministic answers: one active value per field means no coin flips.
- Audit trail preserved — you can answer "what did the system believe in March".
- Precedence rules prevent regressions, like a weak inference overwriting something the user explicitly stated.
- Contradiction detection surfaces stale memories for correction (feedback capture & triage).
- Confirming high-impact changes with the user is cheap and builds trust.
Cons
- Storage grows with superseded history (mitigated by the eviction and retention policy, how to forget).
- Multi-valued facts get forced into single values if the schema is wrong — "works across two entities" is not a conflict, it's a modelling error.
- Precedence rules can be wrong: a stale profile-sync value beating a fresh user statement, if the rules are ordered badly.
- NLI contradiction detection is noisy and costs latency if run on every request.
- Asking the user to confirm every change becomes nagging; reserve it for high-impact fields.
When to use
Any system storing durable facts about users or entities. Supersession should be the default write path, not a special case.
When NOT to use
- Append-only event logs (episodic memory) — episodes don't supersede each other, they accumulate and decay (when to retrieve memory).
- Genuinely multi-valued attributes — model them as sets with their own add/remove semantics rather than forcing supersession.
Production at scale
Never mutate a memory value in place. Insert a new row and mark the old one superseded. In-place updates destroy the audit trail and make "why did it think that" unanswerable.
Precedence must handle the stale-system case. A nightly profile sync that keeps re-asserting an outdated entity will fight a user's explicit correction forever. Rule: a user_stated fact suppresses profile_sync for that field until the sync value changes to something new. Implement it, or your users will correct the same thing every week.
Two active facts for one field is an invariant violation, not a runtime condition to handle gracefully. Assert it at retrieval, alert, and fix the write path.
Evidence over memory, stated in the prompt and detected in code. The instruction handles most cases; the detector catches the ones where a stale memory silently shaped an answer. Run the detector on high-stakes paths, not every request.
Confirm high-impact changes and record the confirmation. "You mentioned the UK entity — use that from now on?" costs one sentence and prevents a class of wrong answers, and the answer is a user_stated fact with confidence 1.0.
Conflict telemetry is a quality signal: frequent supersessions for a field mean either the user's situation genuinely changes often (fine) or your extraction is unstable (a bug in what to write to memory).
Cross-source reconciliation: when memory conflicts with the HR system, the CRM, or another system of record, the system of record generally wins for its owned fields — encode which system owns which field.
Retention for superseded records: keep them for the audit window, then purge with the same erasure discipline as active memories (how to forget).
Prod checklist
- Upsert-with-supersession as the only semantic write path; values never mutated in place
-
valid_from,source,superseded_byon every record - Explicit source precedence, with user statements suppressing repeated weaker syncs
- Retrieval excludes superseded records via the shared filter
- Invariant assertion: one active value per (user, field); alert on violation
- Prompt states retrieved evidence overrides memory; contradiction detector on high-stakes paths
- Confirmation flow for high-impact field changes; confirmations stored as user-stated facts
- Multi-valued attributes modelled as sets, not forced through supersession
- System-of-record ownership map per field
- Superseded records retained for the audit window, then purged
Metrics to watch
| Metric | Why |
|---|---|
| Supersession rate per field | Extraction stability vs real change |
| Active-conflict violations (must be 0) | Write-path bugs |
| Memory–evidence contradictions detected | Stale memories reaching prompts |
| User corrections after a supersession | Wrong resolution rules |
| Rejected writes by precedence rule | Whether precedence is helping or blocking |
Related
- What to write — where supersession is applied
- When to retrieve — only active facts are injected
- How to forget — superseded record retention
- Conflict handling — the document-side analogue
- Context poisoning — what unresolved conflicts cause