First Memory
First Memory Tutorial
Section titled “First Memory Tutorial”Let’s create a small neural network and watch it come alive.
What We’ll Build
Section titled “What We’ll Build”A simple associative network:
graph TD
fire[fire<br/>E=0.9] -->|+1, s=0.8| heat[heat]
fire -->|+1, s=0.6| light[light]
fire -->|-1, s=0.7| ice[ice]
heat -->|+1, s=0.5| burn[burn]
Step-by-Step
Section titled “Step-by-Step”-
Create the core memory
Using CLI:
Terminal window mfcli create fire 0.9Or TypeScript:
await brain.lineage.create({ key: 'fire', energy: 0.9 })This creates a “fire” memory with high initial energy (0.9).
-
Create associated memories
Terminal window mfcli create heat 0.5mfcli create light 0.4mfcli create ice 0.6mfcli create burn 0.3 -
Form synergy bonds
// fire → heat (synergy)await brain.bond.connect({from: 'fire',to: 'heat',strength: 0.8,polarity: 1,})// fire → light (synergy)await brain.bond.connect({from: 'fire',to: 'light',strength: 0.6,polarity: 1,})// heat → burn (synergy)await brain.bond.connect({from: 'heat',to: 'burn',strength: 0.5,polarity: 1,}) -
Form an antagonistic bond
// fire → ice (antagonism)await brain.bond.connect({from: 'fire',to: 'ice',strength: 0.7,polarity: -1, // Negative!})Now when “fire” is stimulated, “ice” will be suppressed.
-
Stimulate and observe
// Before stimulationconsole.log('Before:')console.log('heat:', (await brain.lineage.get('heat')).energy)console.log('ice:', (await brain.lineage.get('ice')).energy)// Stimulate fire!await brain.lineage.stimulate({ key: 'fire', delta: 1.0 })// After stimulationconsole.log('\nAfter fire stimulation:')console.log('heat:', (await brain.lineage.get('heat')).energy)// Expected: ~0.9 (was 0.5, +0.4 from cascade)console.log('ice:', (await brain.lineage.get('ice')).energy)// Expected: ~0.25 (was 0.6, -0.35 from antagonism)console.log('burn:', (await brain.lineage.get('burn')).energy)// Expected: ~0.5 (2-hop cascade: fire→heat→burn)
What Just Happened?
Section titled “What Just Happened?”When you stimulated “fire”:
- Direct cascade to “heat” (+0.4) and “light” (+0.3)
- Antagonistic suppression of “ice” (-0.35)
- Secondary cascade from “heat” to “burn” (+0.2)
The entire network responded to a single stimulus. This is synaptic propagation.
Experiment Further
Section titled “Experiment Further”Change the Mood
Section titled “Change the Mood”// Depressive mood: raise consciousness thresholdawait brain.system.setMood(0.2)
// Now lower-energy memories become inaccessibleconst burn = await brain.lineage.get('burn')// May throw "NotFound" if burn.energy < thresholdObserver Effect
Section titled “Observer Effect”// Each GET reinforces the memoryfor (let i = 0; i < 10; i++) { await brain.lineage.get('fire')}// fire.energy has increased by ~0.1 (10 × 0.01)Surgical Stimulation
Section titled “Surgical Stimulation”// Stimulate WITHOUT cascade (maintenance mode)await brain.lineage.stimulate({ key: 'fire', delta: 0.5, flags: 0x01, // NO_PROPAGATE})// Only 'fire' affected, no neighbors touchedComplete Code
Section titled “Complete Code”import { MindFry } from '@mindfry/client'
async function firstMemory() { const brain = new MindFry({ host: 'localhost', port: 9527 }) await brain.connect()
// Create memories await brain.lineage.create({ key: 'fire', energy: 0.9 }) await brain.lineage.create({ key: 'heat', energy: 0.5 }) await brain.lineage.create({ key: 'light', energy: 0.4 }) await brain.lineage.create({ key: 'ice', energy: 0.6 }) await brain.lineage.create({ key: 'burn', energy: 0.3 })
// Form bonds await brain.bond.connect({ from: 'fire', to: 'heat', strength: 0.8, polarity: 1 }) await brain.bond.connect({ from: 'fire', to: 'light', strength: 0.6, polarity: 1 }) await brain.bond.connect({ from: 'fire', to: 'ice', strength: 0.7, polarity: -1 }) await brain.bond.connect({ from: 'heat', to: 'burn', strength: 0.5, polarity: 1 })
// Stimulate and observe console.log('Before:', (await brain.lineage.get('heat')).energy) await brain.lineage.stimulate({ key: 'fire', delta: 1.0 }) console.log('After:', (await brain.lineage.get('heat')).energy)
await brain.disconnect()}
firstMemory()Next: Explore Recipes for real-world patterns or dive into Architecture.