Repository navigation
The Ontology that runs SwarmAI's Memory, DDD & Code Intelligence (๐ท๏ธClassification + ๐ธ๏ธRelations, no Neo4j) #95
Replies: 2 comments
|
How this fits with the other knowledge-representation discussions here โ this piece is the unifying layer under three that came before it:
The claim: Memory, DDD, and Code Intelligence aren't three separate stores with three schemas โ they're one ontology (classification + relations, no Neo4j) with three views. If you're evaluating knowledge representation for an agent, read #20 โ #59 โ this, in that order. Full index of all 72 discussions, with reader paths: #35 Reading Matrix. |
|
๐ This ontology is now a featured entry in the repo README. If you landed here from the README โ "The Ontology Beneath It All" โ welcome. The short version: Memory, DDD, and Code Intelligence are not three stores with three schemas. They're one ontology โ ๐ท๏ธ classification + ๐ธ๏ธ relations, no Neo4j โ with three views. Read order if you're evaluating knowledge representation: #20 No Neo4j โ #59 DDD Governance โ this. Full index: #35 Reading Matrix. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This post explains three things: what an Ontology actually is, how we apply it to knowledge, and how we apply the same idea to code.
Page 1 ยท What an Ontology Is
Don't let the word scare you. An Ontology holds no content โ it just sets the rules so that a mountain of content can be found. The easiest analogy is your phone contacts, and the rules have two layers:
principle ยท correction ยท decision ยท mental-model ยท guideline ยท pitfall ยท process. The payoff is retrieve on demand: when coding I only pull "pitfalls" and "guidelines"; when deciding whether to build something I only pull "decisions" โ no reading the whole notebook cover to cover.this guideline โapplies_toโ session_unit.py,new decision B โsupersedesโ old decision A. The payoff is follow the thread: ask "what will I hit if I change this file?" and I follow the links to surface the relevant pitfalls โ even ones whose title never mentions that filename.Why exactly these seven types? (Not arbitrary โ a cognitive hierarchy)
A fair question: I get classification, but why exactly seven types โ not five, not ten? Because these seven form a MECE (mutually exclusive, collectively exhaustive) three-layer cognitive structure. Which layer an entry belongs to directly determines two things: how fast it should be forgotten and at which stage of the work it gets read.
Three "why"s chain into the whole design:
decision + principle; writing code โ readguideline + pitfall + correction; delivery/wrap-up โ readprocess + principle. The classification is a routing table for "what to look at when."Page 2 ยท Applied to Knowledge: One Engine, Two Consumers
Key insight: Memory and DDD are two clients of the same logic โ they differ only in the "how fast to forget" parameter. Those two layers of rules live in one engine โ
backend/core/ddd_entry_lifecycle.py(๐ท๏ธ7 types + ๐ธ๏ธrelation graph in.knowledge-graph.yaml).๐ Consumer 1: my long-term memory (
MEMORY.md, cross-session, ~90K words)never forgetโ principles ยท corrections ยท post-mortems (hard-won lessons, always injected)fadesโ decisions ยท mental models (selected by relevance to the current topic)fades fastestโ guidelines ยท pitfalls (drop out after long disuse)๐ Consumer 2: each project's knowledge base (
Projects/*/, four docs each)PRODUCT / TECH / IMPROVEMENT / PROJECT) โ the structure is the classification๐ซ What we deliberately DON'T do (this is what "lightweight" means): Big companies do ontology with heavy graph databases (Neo4j / OWL). We don't, for three reasons โ โ too much maintenance tax (every code change means hand-syncing a pile of edges); โก not worth it (in a 1M context, just injecting it and letting me reason is cheaper than building a query system); โข it never "forgets" (a graph DB keeps a node forever; we want Darwinian fade โ forget).
Page 3 ยท Applied to Code: A Relationship Map of the Code Itself
Same ๐ท๏ธClassification + ๐ธ๏ธRelations โ but this time the objects aren't lessons, they're the code itself. Plainly: turn the whole codebase into a subway map โ every function is a station, "who calls whom" is a line.
The engine is
backend/core/code_intel/graph_store.py(a separate engine, not shared with the knowledge side):code_intel.db, auto-updated by a watcher on every code change.A real call chain (pulled from the live graph, not made up):
That's the value of "relations": ask me to change the signature of
SessionUnit.killโ one graph query shows 44 call sites (cleanup, TTL, memory pressure, shutdownโฆ) that all have to change with it. Without the graph I can only change it and pray; with it, I know before I touch anything.Same graph, different question, different capability: count in-edges (who calls me) โ more = riskier (
SessionUnit.killhas 44 = high-risk node); count out-edges = 0 with no callers โ dead code, safe to delete. "What will this break," "is this still used," "how risky is this change" โ all answered by a graph query, no human reading code.Why a separate engine, not shared with the knowledge side? The knowledge side cares "should this be forgotten?" (hence fade rules); the code side cares "who is connected to whom right now?" (a code change invalidates old edges immediately โ no "fade"). They share the ontology idea (nodes + edges + classification) but have opposite lifecycle needs, so they're two engines.
Appendix ยท Formal-ontology view (aligns with the design doc ยง3 L2)
The two layers of rules above (๐ท๏ธ classification + ๐ธ๏ธ relations), in semantic-web terms, are the schema layer of an ontology โ we just deliberately skip OWL/RDF and implement it as two flat, grep-able, context-loadable structures:
MEMORY_SECTIONS).knowledge-graph.yaml{principle, correction, decision, model}is permanentOne thing that's easy to conflate: decay โ reclaim. Any non-evergreen entry decays active โ dormant โ archived by age (so even decisions/models fade); but physical reclaim (actually deleting noise) touches only the operational layer โ because the keep-set permanently protects both the meta-cognitive and cognitive layers.
Same ontology, three views (the design doc completes it to three โ one more than this post's original two: the Entity Index):
Three-Page Summary
ddd_entry_lifecycle.py(shared)code_intel/graph_store.py(separate)One idea (๐ท๏ธClassification + ๐ธ๏ธRelations), three places it lands, same goal โ let the AI retrieve precisely and keep the whole picture in view.
We use the ontology idea (schema + relations + reasoning) but reject its heavy implementation (graph DB + formal standards). That's what we mean by "lightweight ontology."
Related: #19 Your AI Agent Doesn't Need Neo4j โ Darwinian Knowledge Management ยท #59 DDD Knowledge Governance โ 7 MECE types + lifecycle
All reactions