Skip to main content

Memory

Plexa stacks three layers between the body and the LLM. Each one answers more situations than the next, so the brain gets called less and less.

PatternStore

Per body. Caches exact and very-similar (entity, decision) pairs. Lives in scp-protocol.
Full reference: see SCP memory layers.

AdaptiveMemory

Per body. Generalizes to “this looks like one we have seen before” using weighted euclidean distance and top-k confidence blending.
Wired into a body via new SCPBody({ patternStore, adaptiveMemory }).

VerticalMemory

Per Space. Cross-session memory of brain decisions for a given world state. This is what lets Plexa skip the LLM on repeated tasks.
On each brain tick, Plexa calls mem.search(worldState) first. If the top match scores above hitThreshold, Plexa uses the remembered decision and skips the LLM. The memory_hit event fires.
Otherwise the brain runs and the response is written back via mem.store. Stats:

How they work together

Three layers of write-through. Three layers of read-through on the next tick. The further you get into a session, the rarer the LLM call.

Cost reduction

Sample run on a Plexa stub workload, 100 brain decisions during ramp-up: Numbers vary by task. The shape is the same: brain decisions get cached locally, repeated situations skip the LLM, latency stops bottlenecking on the brain. Novel situations always wake the brain. Cost is proportional to novelty.

Persistence

AdaptiveMemory and VerticalMemory use better-sqlite3. Plexa lists it as a devDependency, not a runtime one, so production users opt in:
If better-sqlite3 is not installed, both stores still work in memory; persistence calls return 0 and the warning shows up at startup.

Auto-save on shutdown

On SIGINT or SIGTERM, Plexa calls space.stop(), which saves the vertical memory and every body’s pattern store and adaptive memory.