Skip to content

feat: Auto-contradiction scan as Dream pipeline phase #720

Description

@ajianaz

Problem

Uteke has per-insert contradiction detection (consolidate.rs: check_contradiction), but no retroactive scan of existing memories. Contradictions can accumulate over time as new information supersedes old facts.

Hermes holographic memory runs an O(n^2) pair scan: high entity overlap + low content similarity = contradiction. Uteke already has the building blocks: ONNX cosine similarity for content divergence, memory_edges table with "contradicts" type, and the Dream maintenance pipeline.

Proposed Solution

Add Phase 7: Contradict to Dream pipeline

Insert after Dedup (position 4, before Orphans):

1. Lint
2. Backlinks
3. Dedup
4. Contradict  ← NEW
5. Orphans
6. Compact
7. Verify

Algorithm

  1. Load top 200 most recently updated memories (not full O(n^2))
  2. For each pair (i, j):
    • Compute content cosine similarity via ONNX embeddings (already stored)
    • If similarity <= 0.6 AND both memories have overlapping tags (|tags_i ∩ tags_j| >= 1): flag as potential contradiction
  3. For each contradiction pair:
    • Insert memory_edges row: source=older_id, target=newer_id, edge_type="contradicts"
    • Optionally: mark older as deprecated (configurable, default off)
  4. Report: count of contradictions found, edges created

Why tag overlap instead of entity overlap

Uteke does not have structured entity extraction (Hermes uses regex). Tags serve as the closest proxy for "shared topic/context". This avoids adding NLP dependencies while catching the most common contradiction pattern.

Configuration

  • dream.contradict.enabled: bool (default true)
  • dream.contradict.similarity_threshold: f32 (default 0.6)
  • dream.contradict.tag_overlap_min: usize (default 1)
  • dream.contradict.max_memories: usize (default 200)
  • dream.contradict.deprecate_older: bool (default false)

Files to Change

  • crates/uteke-core/src/dream.rs - Add DreamPhase::Contradict, phase_contradict()
  • crates/uteke-core/src/consolidate.rs - Extract reusable pair-scan logic
  • crates/uteke-core/src/lib.rs - Config struct additions

Acceptance Criteria

  • DreamPhase::Contradict added after Dedup in all_in_order()
  • phase_contradict scans top-N memories for contradiction pairs
  • Creates memory_edges with type "contradicts" for detected pairs
  • dry_run mode reports without creating edges
  • Configurable thresholds (similarity, tag overlap, max memories)
  • deprecate_older option works when enabled
  • Phase result reports count of contradictions and edges created
  • "uteke dream --phases contradict" runs only this phase
  • cargo test passes
  • cargo fmt --all passes

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestrustPull requests that update rust codescope:coreCore engine worktype:featureNew feature

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions