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

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

Key Considerations