Synapse Formation & Graph
Relevant source files
The following files were used as context for generating this wiki page:
Synapse Formation and the associative Graph constitute the long-term associative memory system of CORTEX. This system transforms isolated memory nodes into a weighted, emotional, and associative network that mimics biological neural connectivity. By forming synapses based on semantic similarity, shared entities, and temporal proximity, CORTEX enables complex retrieval, pattern completion, and memory consolidation.
Sources: README.md:14-25, src/ingestion/synapse-formation.ts:7-12
Synapse Formation Logic
The system automatically creates connections between new and existing memory nodes during the ingestion process. It employs three primary connection types to build the graph structure.
Automatic Connection Types
| Connection Type | Logic Basis | Strength & Decay |
|---|---|---|
| Semantic | Cosine similarity > 0.85 between node embeddings. | Strength: 0.85–1.0. Decay: 0.005. |
| Entity Shared | Shared entity mentions (e.g., people, places, projects). | Strength: 0.6. Decay: 0.01. |
| Temporal | Co-located content originating from the same source file. | Strength: 0.4. Decay: 0.02. |
Sources: src/ingestion/synapse-formation.ts:13-145, benchmarks/cogbench/client.ts:145-151
The Ingestion Pipeline
When content enters the system, it undergoes a multi-stage process to integrate into the graph.
The diagram shows the sequence of operations from raw content ingestion to the final update of the associative graph in the database.
Sources: src/mcp/server.ts:316-368, src/ingestion/synapse-formation.ts:7-145
Memory Graph Visualization and Categories
The graphRouter provides an API endpoint for 3D visualization of the agent's memory network. It classifies memory nodes into specific categories based on content keywords and semantic tags to improve visual navigation.
Classification Categories
The system maps memories to one of eight visualizer categories:
- Strategic: Business goals, decisions, and roadmaps.
- Technical: Code, APIs, and infrastructure.
- Creative: Design, branding, and narrative.
- Operational: Workflows, SOPs, and monitoring.
- Research: Data analysis and market trends.
- Communication: Meetings, emails, and chat transcripts.
- Identity: Core values, mission, and personality traits.
- Environmental: Context, time, and screen observations.
Sources: src/api/graph.ts:9-41
API: Graph Retrieval
The endpoint GET /api/v1/graph returns the active memory nodes and their synaptic connections, limited to a maximum of 50,000 nodes for performance.
The diagram illustrates the flow of data when a client requests the memory graph for visualization.
Sources: src/api/graph.ts:73-195
Graph Maintenance: The Dream Cycle
The "Dream Cycle" is a nightly synthetic sleep process that maintains the graph's health through pruning, strengthening, and consolidation.
Slow-Wave Sleep (SWS) Phases
- Resonance Analysis: Updates the
resonance_scorefor all active memories using an Ebbinghaus stability-adjusted decay curve. Connections strengthen stability, slowing decay. - Pruning: Removes weak synapses (strength < 0.1) and archives or deletes low-resonance memory nodes based on adaptive percentile thresholds.
- Consolidation: Identifies high-resonance clusters using Union-Find on the synapse graph and generates abstractive summaries.
Sources: src/dream/dream-cycle.ts:37-75, src/dream/dream-cycle.ts:175-197
Rapid Eye Movement (REM) Phases
- Free Association: Randomly activates memory nodes and uses
pgvectorto find novel semantic connections (similarity between 0.6 and 0.85). - Synthesis: Examines novel weak synapses and generates "synthesis" artifacts that bridge disparate domains.
Sources: src/dream/dream-cycle.ts:77-94, src/dream/dream-cycle.ts:340-450
Implementation Details
Synapse Data Structure
Synapses are stored in the memory_synapses table, linking two memories (memory_a and memory_b).
// Example of synapse insertion with conflict handling
await db
.insert(schema.memorySynapses)
.values({
memoryA: memA,
memoryB: memB,
connectionType: "semantic",
connectionStrength: Math.min(row.similarity, 1.0),
decayRate: 0.005,
})
.onConflictDoUpdate({
target: [
schema.memorySynapses.memoryA,
schema.memorySynapses.memoryB,
schema.memorySynapses.connectionType,
],
set: {
connectionStrength: sql`GREATEST(memory_synapses.connection_strength, ${Math.min(row.similarity, 1.0)})`,
lastActivatedAt: sql`NOW()`,
},
});
Sources: src/ingestion/synapse-formation.ts:40-62, src/dream/dream-cycle.ts:468-477
Graph Statistics
The graph system tracks several metrics to monitor cognitive health:
- Synapse Count: Total number of associative connections.
- Drift Score: Measured via self-diagnostics to ensure identity consistency.
- Novelty Score: Derived from CA1 novelty detection during ingestion.
Sources: src/api/graph.ts:197-230, src/mcp/server.ts:474-510
Synapse formation and graph management enable the agent to maintain a coherent identity over time. By linking disparate memories into a unified structure, the system facilitates higher-order reasoning and prevents the information loss typical of simple context-window architectures.