SORNMemory — SORN-powered episodic memory for LLMs. Demo project.
A self-organizing spiking neural network (SORN) that stores chat history as temporal spike patterns and retrieves relevant context for LLM prompts. The idea of using SORN as a temporal, self-organizing memory module for LLMs is unique to this research direction.
git clone https://github.com/omgbox/SORNMemory.git
cd SORNMemory
julia --project=. -e 'using Pkg; Pkg.instantiate()'Create keys.txt in the project root:
nvida Nim key: nvapi-your-key-here
Only NVIDIA NIM is supported.
No API key needed:
julia --project=. examples/verify_sorn.jl
julia --project=. examples/pattern_learning.jlWith API key:
julia --project=. examples/chat_memory.jlCommands inside chat: quit, stats, history, quiet, verbose
- Beyond context windows — LLM context limits are fixed (8K-128K tokens). SORN stores unlimited conversation history as compressed spike-weight patterns, not raw text. No sliding window, no truncation.
- Content-addressable recall — Retrieves past episodes by topical overlap (Jaccard similarity on token IDs), not recency. A question about something said 500 messages ago triggers the same recall as something said 5 messages ago.
- Inference-time cost efficiency — Instead of prepending the entire conversation history (growing token costs linearly with each turn), SORN injects only ~5-10 relevant token IDs. Cheaper and faster per call.
- No pretrained embeddings — No dependency on BERT, SentenceTransformers, or any external embedding model. The SORN network learns temporal patterns purely through spike-timing-dependent plasticity.
- Online learning — Every message updates the network immediately. No batch training, no finetuning, no gradient descent.
- Persistent chatbots — Give an LLM long-term memory beyond its context window without ballooning API costs.
- Research on biological memory — Study how STDP, synaptic scaling, and intrinsic plasticity interact to store and recall sequences.
- Privacy-sensitive applications — All memory is in local SORN weight matrices, not in a cloud vector database.
- Low-resource memory — SORN runs on CPU (375 neurons, 13K synapses). No GPU needed.
- Explainable memory retrieval — Every recall shows exactly which token overlap triggered the match, unlike opaque vector embedding similarity.
- Each message is tokenized by a bidirectional word-level tokenizer (word → ID, ID → word). Unknown words are assigned new IDs on the fly up to a configurable vocabulary size.
- Token IDs drive a 375-neuron SORN with 5 plasticity rules (STDP, ISTDP, synaptic scaling, intrinsic plasticity, structural plasticity)
- On recall, the current message tokens are matched against stored episodes by Jaccard similarity
- The best-matching episode tokens are decoded back to words and injected as context into the LLM prompt
- The LLM response is also tokenized and stored back into SORN as a new episode
Example chat output showing the tokenizer in action:
You: What about Zephyrian quantum entanglement in the Naxos protocol?
[SORN] Tokens: [262, 227, 344, 345, 346, 18, 213, 347, 348]
-> [what, about, zephyrian, quantum, entanglement, in, the, naxos, protocol]
[SORN] Recalled: 344 (zephyrian), 345 (quantum), 346 (entanglement)
[SORN] Injected: "zephyrian", "quantum", "entanglement"
- Julia 1.10+
- HTTP.jl, JSON3.jl
- NVIDIA NIM API key
SORNMemory/
├── src/
│ ├── SORNMemory.jl # Main module
│ ├── tokenizer.jl # Bidirectional word-level tokenizer (online vocab growth)
│ ├── bridge.jl # Token ↔ spike encoding
│ ├── readout.jl # Spike pattern → token decoding
│ ├── episodic_memory.jl # store!/recall!/consolidate! — core memory API
│ ├── llm_interface.jl # NVIDIA NIM provider
│ ├── context_injection.jl # Memory → prompt formatting
│ ├── session.jl # Chat loop orchestrator
│ └── snn/ # Bundled SORN neural network source
├── examples/
│ ├── verify_sorn.jl # SORN pipeline verification (no API key)
│ ├── pattern_learning.jl # SORN learning demo (no API key)
│ └── chat_memory.jl # Full chat with SORN memory
├── keys.template.txt # API key format template
├── LICENSE # MIT License
├── Project.toml
└── README.md
- Lazar et al. (2009) "SORN: a self-organizing recurrent neural network"
- Turrigiano & Nelson (2000) "Homeostatic plasticity in developing networks"