Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:0xK3vin MegaMemory Knowledge Graph Recording

From Leeroopedia
Knowledge Sources
Domains Knowledge_Graph, Data_Modeling, Information_Management
Last Updated 2026-10-27 12:00 GMT

Overview

A data modeling technique that persists learned concepts as nodes with typed edges in a graph, enabling structured retrieval and relationship reasoning across sessions.

Description

Knowledge graph recording treats learned information as a property graph: each concept is a node with a name, kind, summary, rationale, and file references; relationships are typed edges (depends_on, implements, calls, connects_to, configured_by). Unlike flat notes or documents, the graph structure encodes how concepts relate, enabling queries that traverse relationships (e.g., "what does this module depend on?").

Problem solved: Coding agents have no implicit memory between sessions. Flat notes lose structure and are hard to search by relationship. A knowledge graph gives the agent a queryable, persistent model of the project's concepts, architecture, decisions, and their interconnections. Recording in natural language (not code symbols) keeps the graph meaningful to the LLM and resilient to refactors.

Context: MegaMemory stores its graph in a per-project SQLite database (.megamemory/knowledge.db). Concepts are created with createConcept, updated with updateConcept, linked with link, and soft-deleted with removeConcept. Soft-delete preserves history (removed_at, removed_reason) and cascade-deletes incident edges. Each node stores a 384-dim embedding of its "kind: name — summary" text for semantic search.

Usage

Use this principle when:

  • You need persistent, structured project knowledge that survives across agent sessions
  • Relationships between concepts matter (dependency graphs, call graphs, configuration links)
  • You want to record rationale (why) alongside what a concept is
  • Soft-delete with history is preferable to hard-delete (audit trail, merge support)

Theoretical Basis

A property graph G=(V,E) where:

  • V is a set of nodes (concepts), each with properties: id, name, kind ∈ {feature, module, pattern, config, decision, component}, summary, why, file_refs, parent_id
  • E is a set of directed edges (relationships), each with: from_id, to_id, relation ∈ {connects_to, depends_on, implements, calls, configured_by}, description

Node identity: IDs are slug-derived (parentId/child-slug), enabling hierarchical nesting up to 3 levels deep.

Soft-delete semantics: A node is "active" iff removed_at IS NULL. Edges from/to a soft-deleted node are cascade-deleted. This preserves an audit trail while keeping queries simple (WHERE removed_at IS NULL).

Embedding-backed retrieval: Each node's "kind: name — summary" is embedded and stored as a BLOB, enabling semantic search without re-embedding the corpus.

Pseudo-code:

# Abstract creation (NOT real implementation)
node = create(name, kind, summary, why, parent_id, file_refs, edges)
node.embedding = embed(f"{kind}: {name} — {summary}")
db.insert(node)
for edge in edges:
    if db.exists(edge.to):
        db.insert_edge(from=node.id, to=edge.to, relation=edge.relation)

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment