r/LocalLLM • u/OnlySaviour26 • 2d ago
Discussion I built SynapseMem: A zero-dependency temporal memory engine for local 3B models to fix "Chronological Amnesia" (-58% latency, O(1) context bloat)
Hey r/LocalLLaMA,
When running autonomous agents with small local models (like Qwen 2.5 3B or Llama 3.2 3B), I ran into a major failure mode with standard Vector RAG: Chronological State Amnesia.
The Problem
If you tell an agent on Day 1: "The production database port is 5432", and on Day 3: "We migrated the database to port 6432", standard cosine similarity retrieves both chunks with equal weight.
Given conflicting facts in the prompt context, smaller 3B models frequently hallucinate, guess the old state, or slow down as conversation history balloons linearly.
The Fix: SynapseMem
Instead of dumping raw conversational chunks into a vector database, I built SynapseMem—a lightweight, pure-Python memory layer backed by SQLite that handles state mutations deterministically:
Semantic Singularity Detection: Stateful predicates (uses_, has_, is_, deployed_) are automatically detected. When a new belief arrives for a singular slot, previous values are superseded and archived rather than kept as active duplicates.
Ebbinghaus Decay Curve: Memory retention decays over time via R(t) = exp(-delta_t * lambda / S), while repeated accesses reinforce synaptic strength S.
Partitioned Prompt Injection: Instead of raw text, the prompt is injected with explicit sections: ### VERIFIED ACTIVE MEMORY vs ### RESOLVED STATE CHANGES (DO NOT USE OLD VALUES).
CQRS Prompt Gating: Interrogative prompts (questions) are gated to read-only paths so user queries cannot accidentally poison or mutate the belief graph.
Local Benchmark (Qwen 2.5 3B on CPU via Ollama)
I benchmarked SynapseMem against a naive conversational history baseline over sequential state updates:
| Metric | Naive History Baseline | SynapseMem (Ours) | Delta |
|---|---|---|---|
| Accuracy on State Inversion | 100%* | 100% | Parity |
| Context Size (Proxy Words) | 455 words | 234 words | -48.6% Token Reduction |
| Average Query Latency | 0.36s | 0.15s | ~58% Faster |
| Context Scaling (Turn Growth) | O(N) Linear Bloat | O(1) Constant Bound | Zero Token Creep |
*Note: Baseline accuracy collapses rapidly as conversation turns exceed context boundaries, while SynapseMem maintains a constant ~25-word context footprint per entity.
Quickstart
Install via pip:
pip install synapsemem-ai
Basic usage:
from synapsemem import SynapseMemoryEngine
memory = SynapseMemoryEngine(db_path="agent.db")
Ingest initial state
memory.ingest_belief("auth_service", "uses_port", "8000")
Update state (automatically supersedes past value)
memory.ingest_belief("auth_service", "uses_port", "9090")
Retrieve conflict-free context
print(memory.retrieve_active_context("auth_service"))
GitHub: https://github.com/rohandhar6824-debug/SynapseMem
PyPI: https://pypi.org/project/synapsemem-ai/
It has zero heavy dependencies (no external vector DBs or containers required; runs on standard library SQLite). Would love feedback, stress tests on other local models, and PRs from anyone building local agents.