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