⚡ SynapseMem
A zero-dependency, temporal belief-graph memory engine designed to eliminate chronological amnesia and context bloat in local edge language models (SLMs).
📄 Preprint: Read the Research Paper (PDF) • Zenodo Record
Architecture • Key Innovations • Benchmarks • Quickstart • Ollama Integration • Citation
🔬 The Core Problem: Chronological Amnesia in RAG
When an autonomous AI agent operates over days, weeks, or months, environment states drift constantly:
- Day 1:
"The production database runs on port 5432." - Day 5:
"We migrated the production database to port 6432."
Standard Vector RAG (Retrieval-Augmented Generation) converts text into static embeddings and retrieves chunks based purely on semantic similarity. Because both statements discuss database ports, standard cosine similarity retrieves both chunks with near-identical scores.
Small Language Models (SLMs, e.g., 1B–3B parameter models running on edge CPUs) cannot reliably resolve this contradiction. They frequently hallucinate obsolete values, compromise between the two, or slow down dramatically as conversation logs balloon context windows at an $O(N)$ rate.
🏗️ Architecture
SynapseMem replaces unstructured vector dumps with an embedded, deterministic temporal belief graph backed by standard SQLite:
User / Sensor Input
│
▼
┌─────────────────────────┐
│ CQRS Query Gater │ ──[ Interrogative ]──► Read-Only Context Retrieval
└──────────┬──────────────┘
│ (Declarative Fact)
▼
┌─────────────────────────┐
│ Semantic Singularity │ ──► Predicate conflict detected?
│ Gate │ ├── YES: Invalidate old state (active=0, set forward pointer)
└──────────┬──────────────┘ └── NO: Append / update belief
▼
┌─────────────────────────┐
│ Ebbinghaus Retention │ ──► Recalculate decay R(t) = exp(-Δt · λ / S)
│ Engine │ Prune entropy below threshold τ
└──────────┬──────────────┘
▼
┌─────────────────────────┐
│ Partitioned Injection │ ──► Inject: [ACTIVE MEMORY] vs [RESOLVED PAST CHANGES]
└─────────────────────────┘
💡 Key Innovations
- Semantic Singularity Gate: Stateful predicates (
uses_*,has_*,is_*,deployed_*) are mutually exclusive. When a new belief arrives for a singular slot, previous values are deterministically marked inactive and archived without requiring secondary LLM arbitration passes. - Ebbinghaus Memory Decay: Memory retention decays over time via $R(t) = \exp(-\Delta t \cdot \lambda / S)$, while repeated references reinforce synaptic strength $S$. Transient noise fades automatically while core operational parameters remain consolidated.
- Partitioned Prompt Injection: Structured prompt sections strictly separate current operational truth (
### VERIFIED ACTIVE MEMORY) from superseded context (### RESOLVED STATE CHANGES (DO NOT USE OLD VALUES)). - CQRS Prompt Gating: Interrogative inquiries (questions) are routed through a read-only path, preventing user queries from corrupting or mutating state representations.
- Zero External Dependencies: Built purely on Python standard library modules (
sqlite3,math,re,time). No Docker, vector databases, or external services required.
📊 Benchmark Results
Evaluated locally against qwen2.5:3b on CPU via Ollama across sequential state-inversion tasks:
| Metric | Naive History Baseline | SynapseMem (Ours) | Delta |
|---|---|---|---|
| State-Inversion Accuracy | 100%* | 100% | Parity |
| Injected Context Footprint | 455 words | 234 words | -48.6% |
| Average Query Latency (CPU) | 0.36 s | 0.15 s | ~58% Faster |
| Context Scaling Curve | $O(N)$ Linear Bloat | $O(1)$ Constant Ceiling | Bounded |
*Note: Baseline accuracy collapses rapidly as conversation length exceeds the context boundary, while SynapseMem maintains a constant ~25-word context footprint per entity inquiry.
🚀 Quickstart
Installation
pip install synapsemem-ai
Basic Usage
from synapsemem import SynapseMemoryEngine
# Initialize memory engine with local SQLite storage
memory = SynapseMemoryEngine(db_path="agent_memory.db")
# Ingest initial belief
memory.ingest_belief(
subject="auth_service",
predicate="uses_port",
obj="8000"
)
# Later: state changes (automatically archives port 8000)
memory.ingest_belief(
subject="auth_service",
predicate="uses_port",
obj="9090"
)
# Retrieve deterministic, conflict-free context
context = memory.retrieve_active_context(subject="auth_service")
print(context)
Local Agent Integration (Ollama)
from synapsemem import SynapseMemoryEngine, OllamaBridge
# Connect SynapseMem to your local Ollama instance
bridge = OllamaBridge(
model="qwen2.5:3b",
db_path="local_agent.db"
)
# Ingest state change and execute prompt with O(1) bounded memory
response = bridge.chat("We migrated payment_gateway to AWS us-east-1.")
print(response)
response = bridge.chat("Where is payment_gateway deployed?")
print(response)
📜 Citation
If you use SynapseMem in your research or applications, please cite the preprint:
@article{dhar2026synapsemem,
title={SynapseMem: Deterministic Temporal Belief Invalidation and Ebbinghaus Memory Consolidation for Edge Language Models},
author={Dhar, Rohan},
year={2026},
publisher={Zenodo},
doi={10.5281/zenodo.23970380},
url={[https://doi.org/10.5281/zenodo.23970380](https://doi.org/10.5281/zenodo.23970380)}
}
📄 License
Distributed under the MIT License.
Metadata
Release files for synapsemem-ai 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| synapsemem_ai-0.2.0.tar.gz | 13.3 kB | Without provenance | Details for synapsemem_ai-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| synapsemem_ai-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for synapsemem_ai-0.2.0-py3-none-any.whl |
Total release size: 24.3 kB
Release files / synapsemem_ai-0.2.0.tar.gz
| Download URL | synapsemem_ai-0.2.0.tar.gz |
|---|---|
| Size | 13.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
18c95d3e1d8128c92c520f4912aa663b647616caf70e7597c082dd482274007c
|
|
BLAKE2b-256 checksum How to use checksums |
a542d26ebfbfb90717de48bc722a022c60f6adf4d82ff9fdcd61aa5888188664
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / synapsemem_ai-0.2.0-py3-none-any.whl
| Download URL | synapsemem_ai-0.2.0-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1f044510e8ee95088cd2fe7bc4df9e40af894d313a8512085ceb07f6cd310d6a
|
|
BLAKE2b-256 checksum How to use checksums |
ce69f562daf05ecfb3ef9b8a438eb2fdb8a85e808145980dbe530ce9f7cd74e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for synapsemem-ai 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.