Skip to content

feat: orphan detection — find disconnected memories in the graph #351

Closed

Description

@ajianaz

Motivation

GBrain's dream cycle includes runPhaseOrphans — detecting pages with no connections to anything else in the brain. Orphaned memories are low-value: they can't be reached via graph traversal, don't connect to related memories, and dilute recall quality.

Uteke has no concept of orphan detection. As memories accumulate, disconnected nodes reduce graph density and make recall noisier.

Proposal

Detect and report memories that have no edges (no relationships, no backlinks, no shared tags with other memories).

Depends on: #346 (edge table)

Orphan Criteria

A memory is considered "orphaned" if ALL of the following are true:

  1. No outgoing edges (no references, supersedes, etc.)
  2. No incoming edges (no referenced_by)
  3. access_count == 0 (never recalled)
  4. Not pinned
  5. Below importance threshold (configurable, default: 0.3)

CLI Commands

# Find orphans
uteke orphans                        # list orphaned memories
uteke orphans --namespace work       # scoped to namespace
uteke orphans --threshold 0.2        # custom importance threshold

# Interactive cleanup (prompts per orphan)
uteke orphans --cleanup              # ask: forget / keep / tag / link

# Non-interactive bulk forget
uteke orphans --forget               # forget all orphans (dangerous, --yes to confirm)

Orphan Score

Each memory gets an orphan_score (0.0 - 1.0):

orphan_score = (1 - edge_density) * 0.4
             + (1 - access_frequency_normalized) * 0.3
             + (1 - importance) * 0.3

Score > 0.8 = strong orphan candidate. Score < 0.3 = well-connected.

Output Format

Found 12 orphaned memories (out of 847 total, 1.4%)

Score  ID       Type        Created    Content (truncated)
─────────────────────────────────────────────────────────────
0.94   a3f2...  note        2026-03-01  "random thought about..."
0.91   b7e1...  reference   2026-02-15  "https://example.com/..."
0.87   c9d4...  fact        2026-01-30  "SQLite WAL mode..."

Scope

  • Implement find_orphans() function (SQL query using edge table + memory fields)
  • Calculate orphan_score per memory
  • Add uteke orphans CLI subcommand
  • Add --cleanup interactive mode (prompt per orphan)
  • Add --forget bulk mode (with safety confirmation)
  • Add orphan check to uteke doctor
  • Tests: orphan detection, scoring, namespace scoping, cleanup safety

Non-Goals

  • Auto-forgetting orphans without user confirmation (safety)
  • LLM-based relevance assessment (pure heuristics)
  • Orphan prevention at write time (just detection + cleanup)

Dependencies

References

  • GBrain: cycle.ts runPhaseOrphans — nightly orphan detection
  • GBrain: find_orphans operation

Activity

  1. added this to the milestone on Jun 14, 2026
  2. added
    enhancement
    scope:core
    scope:cli
    type:feature
    priority:low
    epic:memory-engine
    on Jun 14, 2026
  3. modified the milestones: , v0.2.1 — DX & Ecosystem on Jun 14, 2026
  4. added 5 commits that reference this issue on Jun 18, 2026
  5. added 3 commits that reference this issue on Jun 19, 2026
  6. added 2 commits that reference this issue on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementepic:memory-enginepriority:lowscope:cliscope:coretype:feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions