Repository navigation
Description
Motivation
GBrain enforces "Iron Law of Back-Linking": every mention of an entity creates a bidirectional link. If memory A references memory B, then B should know it's referenced by A. This makes the graph navigable in both directions.
Uteke currently has no automatic backlinking. When recall_related finds edges, it only follows outgoing relationships — incoming edges require an O(n) scan of all memories.
Proposal
When a memory A creates an edge to memory B, automatically ensure a backlink edge exists from B to A (type: referenced_by).
Depends on: #346 (typed auto-edges — edge table must exist first)
Backlink Edge Type
pub const REL_REFERENCED_BY: &str = "referenced_by";When remember() or explicit edge creation adds edge (A → B, type: references):
- Also insert edge
(B → A, type: referenced_by)if not exists - Idempotent — won't duplicate if backlink already present
Backlink Maintenance
# Rebuild all backlinks (one-time migration + maintenance)
uteke rebuild-backlinks
# Show backlinks for a memory
uteke edges <memory-id> --direction incomingIntegration with Auto-Edges (#346)
When the pattern parser in #346 detects [[some-memory]] in content:
- Create edge
(this → some-memory, references) - Auto-create backlink
(some-memory → this, referenced_by) - Both stored in
memory_edgestable — instant lookup, no scan
Deduplication
Backlinks are deduplicated by (source_id, target_id, edge_type) — inserting the same backlink twice is a no-op.
Scope
- Implement
ensure_backlink()function (idempotent) - Hook into edge creation path (both manual + auto-extracted)
- Add
uteke rebuild-backlinksCLI command (scan all memories, rebuild) - Update
get_related()to query both directions via edge table - Tests: bidirectional creation, deduplication, rebuild idempotency
- Benchmark: incoming edge lookup via SQL vs current O(n) scan
Non-Goals
- Transitive backlink computation (only direct backlinks)
- Backlink depth limits (all direct backlinks stored)
Dependencies
- Requires feat: typed auto-edges — self-wiring knowledge graph on every remember() #346 (typed auto-edges + edge table) to be merged first
References
- GBrain:
skills/conventions/quality.md— "Iron Law: Back-Linking (MANDATORY)" - GBrain:
skills/brain-ops/SKILL.md— "An unlinked mention is a broken brain" - Current:
graph.rsget_related()— O(n) scan for incoming edges
Activity
fix(#350): mark wire_edges e2e test #[ignore] + propagate rebuild errors
fix(#350): propagate backlink errors instead of silent warn
fix(#350): atomic forward + backlink insertion via SQLite transaction
fix(#350): wrap rebuild_backlinks in transaction for atomic repair
docs(#350): document backlink system in architecture + configuration
feat(#351): orphan detection — find disconnected memories (#389)
feat(#353): dream cycle — coordinated maintenance pipeline (#390)
feat(codecoradev#350): backlink auto-generation — bidirectional memor…
feat(#350): backlink auto-generation — bidirectional memory edges (#380)
feat(#351): orphan detection — find disconnected memories (#389)
feat(#353): dream cycle — coordinated maintenance pipeline (#390)