-
Notifications
You must be signed in to change notification settings - Fork 59
Cortex Causal Graphs
geoffrey fernald edited this page Feb 1, 2026
·
1 revision
Causal graphs are the foundation of Cortex V2's "why" explanations. They connect memories with causal relationships, enabling narrative generation and deep understanding.
Traditional memory systems store isolated facts. Cortex V2 connects them:
βββββββββββββββββββ caused βββββββββββββββββββ
β Security Audit β ββββββββββββββββΆβ bcrypt Adoption β
β (Jan 2024) β β β
βββββββββββββββββββ ββββββββββ¬βββββββββ
β
β derived_from
βΌ
βββββββββββββββββββ
β Password Hash β
β Pattern β
βββββββββββββββββββ
| Relation | Description | Example |
|---|---|---|
caused |
Direct causation | "Security audit caused bcrypt adoption" |
enabled |
Made possible | "TypeScript enabled strict null checks" |
prevented |
Blocked outcome | "Rate limiting prevented DDoS" |
contradicts |
Conflicts with | "MD5 usage contradicts security policy" |
supersedes |
Replaces | "bcrypt supersedes MD5 for hashing" |
supports |
Reinforces | "Unit tests support refactoring safety" |
derived_from |
Based on | "Login pattern derived from auth spec" |
triggered_by |
Initiated by | "Migration triggered by performance issue" |
interface CausalEdge {
id: string;
sourceId: string; // Memory that caused
targetId: string; // Memory that was affected
relation: CausalRelation;
strength: number; // 0.0 - 1.0
evidence: string[]; // Supporting evidence IDs
createdAt: Date;
validatedAt?: Date;
}Cortex V2 automatically infers causal relationships using four strategies:
Memories created close in time may be related:
// If memory B was created within 1 hour of memory A
// and they share entities, infer: A -> triggered_by -> BMemories with similar content may be related:
// If memory A mentions "bcrypt" and memory B is about "password hashing"
// infer: A -> supports -> BMemories mentioning the same entities are likely related:
// If both memories mention "UserService"
// infer: A -> derived_from -> B (if A is newer)Direct references in content:
// If memory A says "because of the security audit"
// and memory B is about the security audit
// infer: A -> caused -> BFind what caused a memory:
const origins = await causalGraph.traceOrigins('mem_abc123', {
maxDepth: 3,
minStrength: 0.5
});
// Returns: [Security Audit] -> [bcrypt Decision] -> [Password Pattern]Find what a memory influenced:
const effects = await causalGraph.traceEffects('mem_security_audit', {
maxDepth: 5
});
// Returns all downstream decisions and patternsFind connection between two memories:
const path = await causalGraph.findPath('mem_audit', 'mem_login_pattern');
// Returns: [Audit] -> caused -> [bcrypt] -> derived_from -> [Login Pattern]Causal chains are converted to human-readable narratives:
{
"nodes": [
{ "id": "mem_1", "summary": "Security audit in Jan 2024" },
{ "id": "mem_2", "summary": "Adopted bcrypt for password hashing" },
{ "id": "mem_3", "summary": "Login endpoint uses bcrypt" }
],
"edges": [
{ "source": "mem_1", "target": "mem_2", "relation": "caused" },
{ "source": "mem_2", "target": "mem_3", "relation": "derived_from" }
]
}The login endpoint uses bcrypt for password hashing. This pattern was
derived from the team's decision to adopt bcrypt, which was caused by
the security audit conducted in January 2024.
Visualize memory relationships:
{
"memoryId": "mem_abc123",
"direction": "both",
"maxDepth": 3,
"format": "mermaid"
}Get causal explanation:
{
"memoryId": "mem_abc123",
"includeNarrative": true
}Get "why" narrative for a topic:
{
"intent": "understand_code",
"focus": "authentication"
}CREATE TABLE causal_edges (
id TEXT PRIMARY KEY,
source_id TEXT NOT NULL,
target_id TEXT NOT NULL,
relation TEXT NOT NULL,
strength REAL DEFAULT 1.0,
evidence TEXT, -- JSON array
created_at TEXT,
validated_at TEXT,
FOREIGN KEY (source_id) REFERENCES memories(id),
FOREIGN KEY (target_id) REFERENCES memories(id)
);
CREATE INDEX idx_causal_source ON causal_edges(source_id);
CREATE INDEX idx_causal_target ON causal_edges(target_id);- Validate inferences β Review auto-inferred relationships
- Add explicit edges β When you know the causation
- Use strength scores β Higher for confirmed relationships
- Prune weak edges β Remove edges with strength < 0.3
- Cortex V2 Overview
- Memory Setup Wizard
- Memory CLI
- Universal Memory Types
- Learning System
- Token Efficiency
- Causal Graphs
- Code Generation
- Predictive Retrieval
- Architecture
- Call Graph Analysis
- Impact Analysis
- Security Analysis
- Data Boundaries
- Test Topology
- Coupling Analysis
- Error Handling Analysis
- Wrappers Detection
- Environment Variables
- Constants Analysis
- Styling DNA
- Constraints
- Contracts
- Decision Mining
- Speculative Execution
- Watch Mode
- Trends Analysis
- Projects Management
- Package Context
- Monorepo Support
- Reports & Export
- Dashboard
- 10 Languages
- 21 Frameworks
- 16 ORMs
- 400+ Detectors
- 50+ MCP Tools
- 60+ CLI Commands
- 23 Memory Types