Memory Conflict Resolution

Category: Data Integrity

Problem

Users change their minds. A user who preferred dark mode six months ago may now prefer light mode. An agent that stored "User is vegetarian" might later hear "I started eating fish again." Without a conflict resolution strategy, the agent presents outdated or contradictory information, eroding trust.

Architecture

This pattern uses timestamp-based recency combined with importance scoring to detect and resolve conflicting memories. When a new memory contradicts an existing one, the system decays the older memory's importance and elevates the newer statement. Semantic similarity detection identifies potential conflicts before they cause problems.

Flow

  • Before storing a new memory, recall semantically similar existing memories
  • Detect contradictions by comparing content against recalled results
  • Decay the importance of outdated contradictory memories
  • Store the new memory with a fresh timestamp and elevated importance

Implementation

from dakera import Dakera
from datetime import datetime

client = Dakera(base_url="http://localhost:3300", api_key="dk-...")

def store_with_conflict_resolution(user_id: str, content: str, category: str):
    """Store a memory while resolving conflicts with existing entries."""
    namespace = f"user-{user_id}-prefs"

    # Step 1: Check for existing memories on the same topic
    existing = client.memory.recall(
        query=content,
        namespace=namespace,
        top_k=5
    )

    # Step 2: Detect contradictions (high similarity + different content)
    for mem in existing["results"]:
        if mem["score"] > 0.75 and mem["content"] != content:
            # Decay the old conflicting memory
            client.memory.store(
                content=mem["content"],
                namespace=namespace,
                metadata={
                    "type": "preference",
                    "category": category,
                    "importance": 0.2,
                    "superseded_by": content,
                    "superseded_at": datetime.utcnow().isoformat()
                }
            )

    # Step 3: Store the new authoritative memory
    client.memory.store(
        content=content,
        namespace=namespace,
        metadata={
            "type": "preference",
            "category": category,
            "importance": 0.95,
            "stored_at": datetime.utcnow().isoformat(),
            "version": "latest"
        }
    )

# Usage: user changed their diet
store_with_conflict_resolution(
    "alice",
    "User now eats pescatarian — fish is acceptable",
    "dietary"
)
# Old "User is vegetarian" memory decayed to importance 0.2

When to Use This Pattern

  • Any system that stores user preferences that can change over time
  • Long-running agents where facts become stale
  • Multi-source systems where different agents may record conflicting information
  • Applications where accuracy of recalled context is critical

Key Considerations

  • Set a similarity threshold (0.7-0.8) to avoid false conflict detection
  • Never delete old memories outright — decay them so audit trails remain intact
  • Use metadata fields like superseded_by to maintain a clear revision history
  • Consider asking the user to confirm when a potential conflict is detected