1. Executive Summary
Surreal-Memory is a fork of NeuralMemory, a local Python memory for
coding agents served over MCP, with a Claude Code plugin, a CLI and an
HTTP server. NOTICE names the fork and what it changed. A
note becomes a fiber: an anchor neuron holding the text, neurons for its
times, entities and concepts, and typed synapses between them. Recall
seeds from full-text and, when configured, vector matches and spreads
activation. The fork's changes are the store and the correction path:
SurrealDB replaces SQLite, the paid tier is gone, and a supersession is
written onto the memory.
Notable: a correction the encode pipeline settles through
smem_remember closes the old memory's validity window and
links the two with a SUPERSEDES edge
(src/surreal_memory/engine/supersession.py:47-102). The
recall handler drops any matched fiber whose window is closed unless the
caller asks for history, and a committed test asserts the superseded
fact absent beside the current one.
Weak: the Claude Code hooks that capture most memories run the same
conflict step and never apply its verdicts. When every match is
superseded, or the caller sets recall_token_budget, the old
text comes back as the answer. Cross-brain recall and the session-start
block skip the filter. The window is record time only: nothing on a
product path sets valid_from.
Two marks are present and five are withheld (section 9).
Licence. MIT, and LICENSE names only
the upstream's holders ("Copyright (c) 2024 NeuralMemory
Contributors"); the fork's own copyright for its modifications is
asserted in NOTICE and in
integrations/surreal-memory-client/LICENSE, not in the root
licence. SECURITY.md forbids public issues for
vulnerabilities and directs reports to the upstream author's personal
address, not this fork's maintainer, and lists 4.x as the supported line
while this package is 3.13.0.
2. Mental Model
A memory is a fiber plus a typed_memory row. The row
holds valid_from, valid_until and
superseded_by beside created_at
(src/surreal_memory/core/memory_types.py:202-238). A memory
is current while valid_until is empty.
is_valid_at treats an empty valid_from as
created_at (:396-406).
A memory stops being current one way:
supersede_typed_memory sets valid_until to the
time of the call and superseded_by to the successor, adds a
SUPERSEDES edge, and stamps _superseded on the
old anchor neuron. A closed window never reopens or moves
(src/surreal_memory/engine/supersession.py:64-102). Three
callers reach it: the conflict verdicts of an smem_remember
call, a keep_new resolution through
smem_conflicts, and a backfill action of
smem_lifecycle
(src/surreal_memory/mcp/remember_handler.py:34-70,
src/surreal_memory/mcp/conflict_handler.py:28-55,
src/surreal_memory/mcp/lifecycle_handler.py:450-500).
Separately, a conflict marks the old anchor _disputed,
and _superseded too when its activation falls below 0.2.
Those flags scale activation; they do not close a window.
Diagram source
%% caption: a correction closes the old memory's window only when it arrives through smem_remember; recall's handler drops closed windows and rebuilds the answer, except when nothing survives or a token budget was set; cross-brain recall and the session-start block read without the filter
flowchart TD
subgraph WR["writers"]
direction TB
RM["smem_remember"] ~~~ HK["Stop, PreCompact<br/>and task hooks"]
end
WR --> CD["encode pipeline:<br/>conflict step"]
CD --> PS["pending_supersessions<br/>(keep_new, or activation<br/>below 0.2)"]
PS --> Q1{"arrived through<br/>smem_remember?"}
Q1 -- "yes" --> SUP["valid_until set,<br/>superseded_by,<br/>SUPERSEDES edge"]
Q1 -- "hook" --> LOST["list unused;<br/>window stays open"]
SUP --> DB["SurrealDB rows<br/>keyed by brain_id"]
LOST --> DB
DB --> RC["smem_recall:<br/>fast paths or<br/>spreading activation"]
RC --> PF{"handler filter:<br/>window closed<br/>or expired?"}
PF -- "kept" --> ANS["answer from<br/>survivors"]
PF -- "dropped" --> LEFT{"any fiber left,<br/>no token budget?"}
LEFT -- "yes" --> ANS
LEFT -- "no" --> OLD["prior answer text<br/>returned unchanged"]
DB --> SS["SessionStart block:<br/>project_id = repo,<br/>no window check"]
DB --> XB["recall with brains:<br/>no handler filter"]3. Architecture
Everything runs in one Python process per client against a SurrealDB
server. The MCP server (src/surreal_memory/mcp/server.py)
dispatches 57 tools in tiers. The CLI is smem;
smem serve starts a FastAPI server with a React dashboard.
The plugin manifest launches the MCP server through uvx,
which fetches the package at run time
(.claude-plugin/plugin.json).
Storage. SurrealDB 3.2 is the only production
backend; the in-memory store survives as a test fixture. The compose
file runs it on SurrealKV with root credentials
(docker-compose.surrealdb.yml:24), and the client defaults
to user root with a fixed password unless
SURREALDB_PASS is set
(src/surreal_memory/storage/surrealdb/connection.py:16-18).
All brains share one namespace and database; a brain is the
brain_id value on each row
(src/surreal_memory/storage/surrealdb/store.py:920-929).
Synapses are native RELATE edges, and the schema defines
BM25 full-text and HNSW indexes
(src/surreal_memory/storage/surrealdb/schema.py).
Model calls. None on the default write or read path.
Embeddings default to off
(src/surreal_memory/unified_config.py:133); the README's
smem init --full detects and enables a provider
(src/surreal_memory/cli/full_setup.py:75).
The paid tier. UnifiedConfig.is_pro()
returns True unconditionally, with a docstring saying the
Pro chain was removed
(src/surreal_memory/unified_config.py:1986-1994). The
community plugin supplies directional compression
(src/surreal_memory/plugins/community.py).
Deployment and ergonomics
pip install surreal-memory[surrealdb], a SurrealDB
server, and smem init --full. The SurrealDB server is the
cost NeuralMemory does not have: a second long-running process, its
credentials, and its version, which CI pins to 3.2.0 and 3.2.4.
4. Essential Implementation Paths
| Path | Where | What it does |
|---|---|---|
| Remember | mcp/remember_handler.py:110, :417-427,
:517-523 |
Redacts, encodes, writes the typed memory with no project, applies pending supersessions, batch-saves |
| Encode | engine/encoder.py:136-162 |
Extract, dedup, anchor, synapses, conflict detection, build fiber |
| Conflict step | engine/pipeline_steps.py:1341-1422 |
Auto-resolve first; a keep_new verdict, or an unsettled
conflict that falls below 0.2, joins
pending_supersessions |
| Auto-resolve | engine/conflict_auto_resolve.py:44-127 |
Returns verdicts; called with new_confidence=0.5 |
| Supersede | engine/supersession.py:47-102 |
Closes the window, adds SUPERSEDES, stamps the old
anchor |
| Recall | mcp/recall_handler.py:258-600 |
Cross-brain branch, surface fast path, pipeline query, token-budget pass, post-filter, context rebuild |
| Pipeline | engine/retrieval.py:410-425,
:1121-1205 |
Temporal and fiber-summary fast paths, then anchors, activation, scoring |
| Session start | hooks/session_start.py:31-69 |
Ten most recent typed memories of the resolved project |
| Forget | mcp/lifecycle_handler.py:174-244 |
Soft: expires_at set to the current time; hard: typed
memory and fiber deleted |
| Cross-brain | engine/cross_brain.py:52-120 |
Runs the pipeline per named brain and merges |
5. Memory Data Model
neuron holds content, a JSON metadata where
_disputed, _superseded and their timestamps
live, a SimHash, and an embedding_vec when embeddings are
on. fiber groups neurons and synapses, with
time_start and time_end, a summary, tags and a
fiber_vec. typed_memory adds type, priority,
tags, trust score, source, project, expiry, tier and the three validity
fields, indexed on (brain_id, valid_until)
(src/surreal_memory/storage/surrealdb/schema.py:262-285).
Time lives in three places, and only one is validity.
created_at is record time. time_start and
time_end are both set to the write's timestamp, which
event_at may backdate
(src/surreal_memory/engine/pipeline_steps.py:1720-1729,
src/surreal_memory/mcp/remember_handler.py:330-343).
valid_at recall treats that zero-width window as unbounded
(src/surreal_memory/engine/retrieval.py:139-162).
valid_from is written only by consolidation merges, which
carry the minimum of their sources' values, and no tool argument sets it
(recorded searches).
change_log is a replication journal: inserts, deletes
and neuron, fiber and synapse updates, with a synced flag
and a sequence
(src/surreal_memory/storage/surrealdb/schema.py:210-240).
6. Retrieval Mechanics
smem_recall with a brains list goes to
cross-brain recall and returns from there
(src/surreal_memory/mcp/recall_handler.py:271-273).
Otherwise:
- Surface. If a Knowledge Surface is loaded and an
entity in it is marked sufficient for the query, the handler answers
from the surface text and returns (
:392-401,:190-256). - Pipeline fast paths. Temporal reasoning, then a
fiber-summary tier that answers from full-text matches over summaries
when its confidence clears the sufficiency threshold
(
src/surreal_memory/engine/retrieval.py:410-425,:1121-1205). - Anchors. BM25 full-text per keyword, KNN over
neuron and fiber vectors when a provider exists, and graph expansion
(
:1704,:1906,:2053). - Activation. Spreading activation, lateral
inhibition, stabilization, then disputed neurons at 0.5x and
superseded-and-disputed at 0.25x (
:575-590,:1502-1545). - Handler filter. For each matched fiber the handler
reads its typed memory and drops it if expired, or if its window is
closed and the caller did not pass
include_superseded; withvalid_at, it keeps only memories valid at that moment (src/surreal_memory/mcp/recall_handler.py:518-580). - Rebuild. When the filter dropped something, the
context is rebuilt from the surviving fibers
(
:584-599).
Steps 5 and 6 cover both pipeline fast paths, because each returns
its fibers in fibers_matched. They do not cover the surface
answer, cross-brain recall or the session-start block.
When nothing survives.
_rebuild_context_for_fibers returns the result unchanged
when it has no fibers to format (:50-51). If every matched
fiber was superseded or expired, fibers_matched is empty
and the answer, taken from result.context
(:722), is the text the filter meant to remove.
With a token budget. The
recall_token_budget pass formats the context from every
matched fiber before the filter runs (:424-494). The filter
then treats the budget as a later rebuild and skips its own
(:586-589), so the superseded fiber's text stays in the
answer.
7. Write Mechanics
smem_remember blocks until the encode and batch save
finish; the memory is retrievable when the call returns. It redacts
sensitive content, runs the encode pipeline and writes the typed memory
with no project_id
(src/surreal_memory/mcp/remember_handler.py:138-155,
:417-427).
Conflicts. The conflict step calls
try_auto_resolve with a fixed
new_confidence=0.5
(src/surreal_memory/engine/pipeline_steps.py:1384). That
value disables the resolver's stale-memory rule, which needs 0.8, and
its both-fresh guard, which needs 0.7
(src/surreal_memory/engine/conflict_auto_resolve.py:72-98).
What can return keep_new is a missing old neuron, a longer
restatement within the hour, or an old neuron that is both disputed and
superseded (:59-66, :100-117). Unsettled
conflicts go to resolve_conflicts, which marks the old
anchor disputed, lowers its activation, adds a CONTRADICTS
synapse, and marks it superseded below 0.2
(src/surreal_memory/engine/conflict_detection.py:396-500).
Both outcomes append the old anchor to
pending_supersessions
(src/surreal_memory/engine/pipeline_steps.py:1386-1421).
Applying them. Only smem_remember and
the tools that call it, such as smem_remember_batch and
smem_auto, apply the list, inside the save window
(src/surreal_memory/mcp/remember_handler.py:517-523). The
Stop, PreCompact and task-context hooks call encoder.encode
and never read it (src/surreal_memory/hooks/stop.py:508,
src/surreal_memory/hooks/pre_compact.py:295). A correction
captured by a hook leaves the old window open; if it went through
resolve_conflicts, the old anchor carries
_disputed and the smem_lifecycle backfill can
close the window later.
Hooks. Stop and PreCompact pick memorable lines from
the transcript and stamp project_id with the repository
name from SMEM_PROJECT, the git root or the working
directory (src/surreal_memory/hooks/stop.py:385-400,
:515-530,
src/surreal_memory/hooks/project_context.py:25-53).
Operational cost
Local CPU and one SurrealDB round trip per batch. Scheduled
consolidation runs every 24 hours by default
(src/surreal_memory/unified_config.py:650-651) over twenty
strategies
(src/surreal_memory/engine/consolidation.py:256-277), with
leases, checkpoints and resumable progress; most of the CHANGELOG's
recent entries are about that machinery.
8. Agent Integration
The plugin registers five hooks
(.claude-plugin/hooks/hooks.json). SessionStart reads the
shared brain: it asks for the project's typed memories with
project_id and expiry as SurrealQL predicates and injects
the summaries of the ten most recent
(src/surreal_memory/hooks/session_start.py:31-69,
src/surreal_memory/storage/surrealdb/typed_memory.py:181-223).
Neither query nor hook reads valid_until, so a superseded
memory of the project is injected beside its replacement. Memories the
agent saved through smem_remember carry no project and
never appear there.
UserPromptSubmit injects mined reasoning strategies, off by default.
The tool surface includes smem_conflicts with
resolve, smem_provenance with
approve, smem_forget and
smem_lifecycle
(src/surreal_memory/mcp/tool_schemas.py:477-490,
:997-1034, :1840-1862).
9. Reliability, Safety, and Trust
The fork's correction path
The design is sound where it runs. A supersession is written on the
record that loses, the successor is named, the edge is in the graph, and
the closed window is immutable. The handler filter covers both pipeline
fast paths and rebuilds the answer when it drops something, using
dataclasses.replace on the real result type
(src/surreal_memory/mcp/recall_handler.py:113-134). An
environment variable turns the filter off process-wide
(:137-146).
Where it does not reach
Four read paths miss it: the surface answer, cross-brain recall
(src/surreal_memory/engine/cross_brain.py:84-120), the
session-start block, and a recall whose survivors are none or whose
context came from the budget pass. On the write side, hook captures
never close a window. Under the escape hatch the fallback is weaker than
its docstring says: the 0.25x demotion requires _disputed,
which supersede_typed_memory does not set
(src/surreal_memory/engine/retrieval.py:1532-1536,
src/surreal_memory/engine/supersession.py:94-100).
Brains and projects
A brain is a predicate value, not a database boundary. Every recall
read I opened in the adapter puts brain_id inside the
statement, including both KNN queries
(src/surreal_memory/storage/surrealdb/store.py:1608,
:3925, :3985-3987); some maintenance
statements scan the fiber table across brains by neuron id
(:1845, :1882). The agent chooses brains:
smem_recall takes up to five names
(src/surreal_memory/engine/cross_brain.py:26), and the
server connects as root.
Forgetting
smem_forget sets expires_at to the current
time, which recall and the session-start query honour, or with
hard=true deletes the typed memory and fiber
(src/surreal_memory/mcp/lifecycle_handler.py:211-244).
Nothing keeps the forgotten content; saving it again is a new
memory.
Marks
scope_enforced— present.brain_idinside every recall statement andproject_idin the session-start query; recall has no project predicate and the caller picks brains.negative_eval— present. The recall test asserts a superseded fact absent beside the current one, through the MCP handler.trust_state— withheld. A closed window is a supersession timestamp with a successor, and_disputedand_supersededare booleans that scale activation. Hypothesis statuses incognitive_stateare never read by recall (recorded searches).bitemporal— withheld, the near miss.valid_atrecall exists, butvalid_untilis the time of the supersession call,valid_fromhas no product writer, andevent_atproduces a zero-width windowvalid_atignores. Every bound is record time.audit_log— withheld.change_logis a replication journal by its own docstring; typed-memory updates, including a supersession, leave no row, and consolidation deletes pending update rows (src/surreal_memory/storage/surrealdb/store.py:4242-4275,src/surreal_memory/engine/consolidation.py:1970-1980).human_review— withheld.smem_conflicts resolveandsmem_provenance approveare on the agent's tool surface, and no memory waits for a decision.tombstone— withheld. The hits for "tombstone" are compression placeholders; nothing records forgotten or rejected content.
10. Tests, Evals, and Benchmarks
The suite has 7,866 pytest functions in 531 files. CI runs
pytest tests/ -m "not stress" on Python 3.11 and 3.12 with
a 65% coverage floor, then again in an integration job against live
SurrealDB 3.2.0 and 3.2.4, where the SURREALDB_URL-gated
cases run (.github/workflows/ci.yml:97,
:167-262). I ran none of them.
The supersession tests are the strongest memory tests. The recall
file seeds a superseded and a current fact, asserts the default call
returns only the current fiber, that include_superseded and
the escape hatch return both, that valid_at returns the old
one, and that the answer is rebuilt without the old words
(tests/unit/test_recall_supersession.py:139-207). The
pipeline is a mock there. A live case checks that a supersession
round-trips through SurrealDB
(tests/unit/test_surrealdb_supersession_live.py:74-105).
The project case asserts an exact set for one project beside another and
unscoped rows
(tests/unit/test_get_project_memories.py:160-171).
The gaps are where the findings are: no case drops every match, none sets a token budget with a superseded match, none drives a correction through a hook, and none recalls across brains with a superseded memory.
docs/benchmarks.md says its figures were measured on the
removed SQLite backend; scripts/benchmark_results.json
measures write and read time and API calls against Mem0. No paper
describes Surreal-Memory; the one arXiv identifier in docs/
cites another project's work.
11. For Your Own Build
Steal
- Write the supersession on the loser.
valid_until,superseded_byand an edge, set once and never moved, give history and a filter one column. - Filter in the handler after every retrieval path. One pass over the matched ids covers fast paths a pipeline-level filter would miss.
- Make history an argument.
include_supersededandvalid_atkeep the default current and the past reachable.
Avoid
- A verdict list only one writer reads. If the encoder computes supersessions, apply them in the encoder's own save, for every caller.
- A rebuild that falls back to the unfiltered answer. When nothing survives the filter, return nothing.
- Formatting before filtering. A budget pass that builds the answer from the unfiltered set defeats the filter that runs after it.
Fit
A single developer who runs SurrealDB, or wants one engine for document, graph and vector data, gets NeuralMemory's model-free graph recall with corrections that take effect for what the agent saves through MCP. The cost over upstream is a database server with root credentials.
Walk away if hook capture is the main write path and corrections must take effect, or if several people or projects share a server and may not see each other: the brain is a value the caller names.
12. Open Questions
- Whether the hooks are meant to apply
pending_supersessions, given thatsmem_rememberdoes. - Whether
new_confidence=0.5in the conflict step is deliberate, given that it disables two of the resolver's rules. - How often the surface answer fires in practice, since it skips the filter.
Appendix: File Index
- Fork notes:
NOTICE,docs/promo/vs-neural-memory.md,CHANGELOG.md - MCP server and handlers:
src/surreal_memory/mcp/server.py,remember_handler.py,recall_handler.py,conflict_handler.py,lifecycle_handler.py,provenance_handler.py,tool_schemas.py - Typed memory and supersession:
src/surreal_memory/core/memory_types.py,src/surreal_memory/engine/supersession.py - Encode and conflicts:
src/surreal_memory/engine/encoder.py,engine/pipeline_steps.py,engine/conflict_detection.py,engine/conflict_auto_resolve.py - Recall:
src/surreal_memory/engine/retrieval.py,engine/cross_brain.py - Storage:
src/surreal_memory/storage/surrealdb/schema.py,store.py,typed_memory.py,connection.py - Hooks:
src/surreal_memory/hooks/,.claude-plugin/hooks/hooks.json - Tests:
tests/unit/test_recall_supersession.py,tests/unit/test_surrealdb_supersession_live.py,tests/unit/test_get_project_memories.py
Recorded searches
Run from the repository root at the pinned commit with
/usr/bin/git grep. .gitmodules is absent.
- Hooks never apply supersessions.
git grep -n -E 'pending_supersessions|_apply_supersessions|supersede_typed_memory' -- 'src/*.py', outsideengine/supersession.py,engine/pipeline.py,engine/pipeline_steps.pyandengine/encoder.py, returns onlymcp/conflict_handler.py,mcp/lifecycle_handler.pyandmcp/remember_handler.py; nothing undersrc/surreal_memory/hooks. - No product writer of
valid_from.git grep -n -E 'with_validity\(|valid_from=' -- 'src/*.py'returns the dataclass itself, the SurrealDB row mapping attyped_memory.py:96, two consolidation merges atconsolidation.py:3005and:5073, andsupersession.py:77, which passesvalid_untilonly. - No window check on the session-start read.
git grep -n valid_until -- src/surreal_memory/storage/surrealdb/typed_memory.pyreturns:97,:142and:323, the row mapping and two writes;git grep -n -E 'valid_until|superseded' -- src/surreal_memory/hooks/session_start.pyreturns nothing. The controlgit grep -n valid_until -- src/surreal_memory/mcp/recall_handler.pyreturns the handler filter. - No filter in cross-brain recall.
git grep -n -E 'valid_until|superseded|is_expired|get_typed_memory' -- src/surreal_memory/engine/cross_brain.pyreturns nothing. - Typed-memory updates are not journalled.
git grep -n _record_change -- src/surreal_memory/storage/surrealdb/typed_memory.pyreturns nothing; the control onstore.pyreturns neuron, fiber and synapse updates at:1769,:1868,:2694and others. - Recall never reads hypothesis status.
git grep -n -E 'cognitive_state|refuted|get_cognitive' -- src/surreal_memory/engine/retrieval.py src/surreal_memory/mcp/recall_handler.py src/surreal_memory/engine/retrieval_context.pyreturns nothing; the control onmcp/cognitive_handler.pyreturns:132and:141. - No neuron status field.
git grep -n NeuronStatus -- srcreturns nothing. - No record of forgotten content.
git grep -n -i -E 'tombstone|blocklist|denylist|rejected_hash|forgotten_hash' -- 'src/*.py'returns compression placeholders (engine/compression.py,core/constants.py), a dedup census marker, and noise denylists inengine/quality_scorer.pyandengine/reasoning_miner.py. - No project argument on remember or recall.
git grep -n -i project -- src/surreal_memory/mcp/remember_handler.py src/surreal_memory/mcp/recall_handler.pyreturns two comments inrecall_handler.pyabout a datetime contract. - Change-log pruning has no product caller.
git grep -n prune_synced_changes -- srcreturns the definitions and comments; the calls are intests/unit/test_change_log.py.collapse_pending_updatesis called atengine/consolidation.py:1977and:2286. - Fiber reads without a brain predicate.
git grep -n -E 'FROM (neuron|fiber|typed_memory)( |")' -- src/surreal_memory/storage/surrealdbreturns 53 lines; opening those without a predicate on the same line found continuation lines carrying it, and maintenance scans atstore.py:1845and:1882that match by neuron id across brains. - No paper.
CITATION.cffis absent;git grep -n -i -E 'arxiv|doi\.org|bibtex' -- . ':!CHANGELOG.md' ':!*package-lock.json'returns one line indocs/architecture/architect-260302-0506-kb-retrieval-analysis.md.
History
2026-12-03 — d0f8a93e….
First reading, from the 2026-12-03 triage shortlist, at the head of
main (3.13.0). A fork of NeuralMemory, read for what differs.
Screened: two auto-run surfaces (the .claude-plugin/
directory and its plugin.json, which starts the MCP server
through uvx); seven build-time execution points
(Makefile, two npm prepublishOnly scripts
under integrations/,
src/surreal_memory/cli/setup.py,
src/surreal_memory/integrations/nanobot/setup.py,
tests/conftest.py, tests/stress/conftest.py);
six floating surfaces (pyproject.toml and five
package.json files, each npm one with a lockfile); nothing
inside the cooldown; AGENTS.md read as data. Nothing was
installed, built or run, and none of the 7,866 tests was run. Two marks
(section 9).