Spreading-activation graph memory over SQLite, with supersession that filters recall

NeuralMemory

A local Python memory for coding agents: notes become neuron graphs in SQLite, recalled by keyword-seeded spreading activation; resolving a conflict hides the loser.

LicenceMIT in LICENSE and pyproject.toml, and again for the VS Code extension; Pro features in the same tree run only under a licence tier the code checks
Size145,475 lines of Python in src/neural_memory (engine 44,116, storage 28,998, MCP 19,671), plus a React dashboard, a VS Code extension, an OpenClaw plugin and a Cloudflare sync hub
Activity1,082 commits from 5 February to 30 November 2026 on 103 distinct days, release v4.63.0; 1,034 under the maintainer's two names, the rest from 13 others
Tests8,045 pytest functions in 433 files; CI runs the suite on every push and pull request to main with a 67% coverage floor; none run here

Carries 4 of 7 rubric mechanisms. Most systems here carry none or one (41%), and a dash means the mechanism was not found at this commit — not that the system needed it. Each mark is one LLM reviewer's reading of the code at this commit rather than a run of it — known limits.

  • Tombstone
  • Trust state
  • Bi-temporal
  • Scope enforced
  • Mutation audit
  • Human review
  • Negative evals

1. Executive Summary

NeuralMemory is a local memory for coding agents, served over MCP with a Claude Code plugin, a CLI and an HTTP server. A note becomes a small graph: an anchor neuron holding the text, neurons for the times, entities and concepts in it, and typed synapses between them. Recall finds seed neurons by FTS5 keyword match and spreads activation through the graph. No model is called on either path, and embeddings are an option that new installs leave off.

The notable part is that the status filter is real. Every neuron can carry a status, and the full recall pipeline drops anything not active, with a second pass that drops a fiber whose anchor was dropped so the text cannot return through its concept neurons. A person resolving a conflict through nmem_conflicts marks the losing memory superseded, and from then on it is out of recall. A caller can also give a memory a validity window and recall as of a past moment, and project scoping is tested end to end through the MCP server with a positive control.

The weak part is the path a correction usually takes. Conflict detection hands each conflict to try_auto_resolve first. Its rules settle the common cases (a newer memory more than a day later, a longer restatement within the hour), and the step only logs what they decided: the older memory is never marked superseded or disputed. Separately, the fiber-summary fast path, on by default, answers from an FTS5 search that skips the status and validity filters. Recall's min_trust, tier and prefer_recent options do nothing, because the code calls _replace on a dataclass that does not have it.

Licence. The MIT grant in LICENSE covers the whole tree, and the same tree checks a licence tier before running some of what it grants. Merkle delta sync, tier configuration and storage migration run only when UnifiedConfig.is_pro() finds a pro or team tier that a remote /verify call wrote to local config (src/neural_memory/unified_config.py:1454-1466, src/neural_memory/mcp/sync_handler.py:139, :519-560). Remember, recall and consolidation are not gated.

2. Mental Model

A memory enters as text and becomes a fiber. The anchor neuron holds the text; the extractors add time, entity, concept, action and intent neurons and link them. Belief is a status on the neuron, stored in its metadata as _status: active, superseded or expired (src/neural_memory/core/neuron.py:33-47). The property falls back to a legacy _superseded flag, so either spelling counts (:239-255).

There are two ways to stop being believed. A person runs nmem_conflicts with keep_existing or keep_new, and the loser is marked superseded with a pointer to the winner (src/neural_memory/mcp/conflict_handler.py:200-250). Or the encode pipeline's conflict step marks the older memory disputed, and superseded too if its activation has fallen below 0.2 (src/neural_memory/engine/conflict_detection.py:554, :623-640). That second path only runs for conflicts the auto-resolver could not settle.

Separately from status, a neuron may carry _valid_from and _valid_until, which the caller sets. Recall as of a moment drops fibers whose anchor is outside the window there. A memory with no window is valid at every moment.

Diagram — a remembered note becomes a fiber with an active anchor; a conflict the auto-resolver settles is only logged, so the older memory stays active; only unsettled conflicts and a person's resolution write superseded; the full pipeline filters on status and validity, while the default fiber-summary fast path answers before either filter runs
Diagram source
%% caption: a remembered note becomes a fiber with an active anchor; a conflict the auto-resolver settles is only logged, so the older memory stays active; only unsettled conflicts and a person's resolution write superseded; the full pipeline filters on status and validity, while the default fiber-summary fast path answers before either filter runs
flowchart TD
    R[nmem_remember] --> E[encode pipeline<br/>SimHash dedup, anchor,<br/>synapses]
    E --> C{similar memory<br/>contradicts?}
    C -->|no| F[fiber, anchor active]
    C -->|yes| AR{try_auto_resolve<br/>settles it?}
    AR -->|"yes: >24h newer,<br/>same-hour restatement"| LOG[verdict logged only<br/>old memory stays active]
    AR -->|no| CD[conflict step:<br/>old marked disputed,<br/>superseded if activation<br/>below 0.2]
    CD --> P[nmem_conflicts<br/>a person picks a side]
    P --> S[loser: _status superseded]
    LOG --> F
    F --> Q[nmem_recall]
    S --> Q
    Q --> FS{fiber-summary tier<br/>confidence at least 0.7?}
    FS -->|yes| OUT1[summaries returned<br/>no status or<br/>validity filter]
    FS -->|no| SA[spreading activation]
    SA --> ST[drop non-active neurons,<br/>drop fibers with dropped<br/>or out-of-window anchors]
    ST --> PS[project post-filter]
    PS --> OUT2[context to the agent]

3. Architecture

Everything runs in one Python process per client. The MCP server (src/neural_memory/mcp/server.py) dispatches 63 tools, of which a fresh install lists ten. The CLI is nmem. nmem serve starts a FastAPI server (src/neural_memory/server/), which also runs scheduled consolidation when the HTTP transport is used (src/neural_memory/mcp/http_transport.py:68).

Storage. Each brain is its own SQLite file, brains_dir / f"{name}.db" (src/neural_memory/unified_config.py:1823-1844), and the brain name is also the brain_id every table is keyed on. Two adapters exist: the legacy SQLiteStorage and a unified SQLStorage over a SQLite or PostgreSQL dialect. New configs get the unified adapter; existing configs without the key stay on legacy (unified_config.py:1414, :1511-1516, storage/factory.py:160-176). The adapters differ in what they log, as section 9 shows.

Model calls. None on the default write or read path. The dedup pipeline has embedding and model tiers that run only when configured (src/neural_memory/engine/dedup/pipeline.py:86-115). Embeddings need the sentence-transformers extra and EmbeddingSettings.enabled, which defaults to False (unified_config.py:167).

Deployment and ergonomics

pip install neural-memory and an MCP entry are the whole install; the server creates the brain on first use. The plugin manifest launches the server through uvx, which fetches the package at run time. A sync hub for Cloudflare Workers lives in sync-hub/ for people who want several machines on one brain.

4. Essential Implementation Paths

Path Where What it does
Remember mcp/remember_handler.py:180, :383-700 Validates the window, encodes, writes the typed memory, sets _source and the window on created neurons, batch-saves
Encode engine/encoder.py:109-135 Extract, dedup, anchor, synapses, conflict detection, build fiber
Near-duplicate engine/pipeline_steps.py:1275, :1337-1371 Content of 20+ characters within SimHash distance 7 gets an alias concept neuron and an ALIAS synapse; the new fiber is still written
Conflict step engine/pipeline_steps.py:1850-1880 Auto-resolve first, log the settled ones, send the rest to resolve_conflicts
Auto-resolve engine/conflict_auto_resolve.py:46-163 Returns verdicts; writes nothing
Person's resolution mcp/conflict_handler.py:110, :200-250 Marks the loser superseded, the winner active
Recall mcp/recall_handler.py:174-470, engine/retrieval.py:280 Fast paths, seed, spread, filter, score, format, project scope, global layer
Status filter engine/retrieval.py:780-785, :2453-2525 Keeps active unless include_status widens it
Fiber-anchor filter engine/retrieval.py:1036, :2409-2451 Drops fibers whose anchor is not active or out of window
Forget mcp/lifecycle_handler.py:153-270 Soft: expires_at = now; hard with confirm=true: typed memory and fiber
Project scope engine/project_scope.py:54-74, :150-170 Resolves the reader's project; hides other projects' fibers

5. Memory Data Model

neurons holds id, brain_id, type, content, a JSON metadata (where _status, _valid_from, _valid_until, _source and the conflict flags live), a SimHash content_hash, device columns, created_at, last_accessed_at, lifecycle_state, frozen and ephemeral (src/neural_memory/storage/sqlite_schema.py:861-883). The schema comment on lifecycle_state says it is derived by consolidation and "NOT a recall gate", and points to _status instead.

fibers group neurons and synapses, with time_start and time_end (both set to the event time the caller passes, or now), salience, conductivity, summary, essence, tags split into automatic and agent-supplied, compression_tier and pinned (:936-968). typed_memories adds memory_type, priority, provenance, expires_at, project_id, tags, trust_score, source and tier (:985-1003).

Time therefore lives in three places: created_at is record time, fibers.time_start is the event time a caller may backdate, and the neuron window is validity. expires_at is a retention deadline, not validity: utcnow() + expires_in_days, and also what a soft forget writes (src/neural_memory/core/memory_types.py:256-257).

cognitive_state holds hypotheses and predictions with a confidence, evidence counts and a status (active, confirmed, refuted, superseded, pending, expired). That status lives beside the neuron, not in its metadata, and recall reads neither it nor the confidence.

6. Retrieval Mechanics

nmem_recall builds a ReflexPipeline and calls query (src/neural_memory/mcp/recall_handler.py:386-420). In order:

  1. Fast paths. Temporal reasoning, then the fiber-summary tier, which runs FTS5 over fiber summaries in the current brain and returns them as the context when its confidence reaches 0.7 (engine/retrieval.py:364-385, :1600-1683). Both are skipped only when the caller widens include_status.
  2. Seeds. Time neurons, then FTS5 over neuron content with a LIKE fallback, fuzzy matches, embeddings if a provider exists, and graph expansion, merged by reciprocal rank fusion (:2942, :3185, :426).
  3. Spreading activation. The default classic strategy is a priority-queue walk multiplying level by decay and synapse weight, cut at 0.3, with hop limits by depth (engine/activation.py:410-413, retrieval.py:1745-1753).
  4. Filters. Step 4.65 drops non-active neurons; step 4.66 scores neurons outside their window at 0.1x (:780-792); fibers whose anchor is non-active or out of window are dropped (:1036).
  5. Scoring. The top 20 neurons bring up to three fibers each, scored by salience, recency, conductivity and activation, then MMR with SimHash dedup to ten (:3272-3418, :3623).
  6. Context. ## Relevant Memories with up to five fibers and ## Related Information with up to 40 neurons, after a [Reflexes] block, in about 500 tokens by default (engine/retrieval_context.py:520).

Then the handler applies the project filter and rebuilds the context (recall_handler.py:422-431). Under the default layer="auto", it queries the _global brain and appends that result as [global] … without a project filter (:433-462).

The fast path and the filters. The comment above the fast paths says the bypass methods "now filter their own results" (retrieval.py:356-361). _try_fiber_summary_tier does not: it searches, sums tokens and returns (:1600-1683). Every nmem_remember writes a summary-bearing "column" fiber (engine/pipeline_steps.py:2213), so the tier has material from the first write, and a superseded or out-of-window memory whose summary matches the query can come back on it.

Options that do nothing. min_trust and tier compute a filtered fiber list and assign it with result._replace(...) if hasattr(result, "_replace") else result (recall_handler.py:586-610). RetrievalResult is a plain @dataclass (engine/retrieval_types.py:67-68), so the branch keeps the unfiltered result, and the context was never rebuilt anyway. The emotion filter (:644) and prefer_recent (:652-706) use the same guard. The tests of prefer_recent check the ranking helper and the schema, not the handler (tests/unit/test_recall_prefer_recent.py:33-88).

7. Write Mechanics

nmem_remember blocks the call until the encode and batch save finish; the memory is retrievable when the call returns. No model is involved.

Dedup. SimHash always runs, with a threshold of 7 (engine/dedup/config.py:29). A near-duplicate is not refused: the new anchor gets an alias concept neuron pointing at the old one, an ALIAS synapse, and its own fiber and typed memory; the response carries a dedup_hint (engine/pipeline_steps.py:1337-1371, mcp/remember_handler.py:837-864).

Conflicts. ConflictDetectionStep finds contradicting memories, then calls try_auto_resolve for each (engine/pipeline_steps.py:1850-1880). The resolver returns keep_new for an older memory that no longer exists, for a conflict the classifier marks as temporal supersession ("newer memory replaces older (>24h gap)"), for a high-confidence new memory against a stale one, and for a longer restatement within an hour; it returns keep_existing when the old neuron is grounded (engine/conflict_auto_resolve.py:46-130). It reads storage and writes nothing, and the step appends its verdicts to a list and logs a count. Only the conflicts it could not settle reach resolve_conflicts, which writes _disputed, a CONTRADICTS synapse, and _superseded when the old memory's activation is under 0.2 (engine/conflict_detection.py:554, :623-660).

So the correction most worth recording, a newer statement replacing an older one, leaves both memories active, with no synapse between them. The unit tests check the verdicts (tests/unit/test_conflict_auto_resolve.py); no test file names ConflictDetectionStep.

Hooks. The Stop hook reads the last 150 transcript entries, picks lines by pattern at a 0.7 threshold and encodes them; PreCompact does the same with looser settings; PostToolUse records tool events (src/neural_memory/hooks/stop.py:27-40, :313-356). An optional write gate can refuse a memory before encoding; it is off unless configured (mcp/remember_handler.py:295-316).

Operational cost

Nothing per call beyond local CPU and SQLite. Consolidation offers twenty strategies (engine/consolidation.py:59-80) and rewrites fibers in place when it merges, summarises or compresses; it runs on request, on a health hint when auto_consolidate is set, or on a schedule under HTTP.

8. Agent Integration

The Claude Code plugin registers four hooks. SessionStart does not read the database: it injects .neuralmemory/surface.nm, found by walking up from the working directory, or a default surface, capped at 6,000 characters after redaction (src/neural_memory/hooks/session_start.py:90-134, :175-176). A surface file committed to a repository the agent opens is injected as written. The surface generator that writes these files reads neurons and fibers with no status or expiry filter (src/neural_memory/surface/generator.py:192, :400).

nmem_context loads recent fibers with only a brain predicate, so it applies neither the status nor the expiry filter, though it does apply project scope (mcp/recall_handler.py:1199-1240, storage/sqlite_fibers.py:574). nmem_recap uses typed memories, which drop expired rows, and applies no project scope.

9. Reliability, Safety, and Trust

The status filter holds on the full pipeline

The design is sound where it runs. Status is stored, defaults to active, and the filter drops both the neuron and any fiber anchored on it, which closes the leak through concept neurons that a neuron-only filter would leave. A caller who wants history passes include_status, and the fast paths step aside for that call.

Corrections the resolver settles are never written

Section 7 is the finding to carry away. The resolver's rules encode a reasonable policy (newer wins after a day; a longer restatement wins within the hour) and the pipeline discards the outcome. A product depending on "the old preference stops being recalled" gets that only when a person runs nmem_conflicts, or when the unsettled path happens to find the old memory's activation below 0.2.

Forgetting does not hold

nmem_forget sets expires_at to now; with confirm=true it deletes the typed memory and the fiber, and delete_fiber deletes only the fiber and its junction rows, leaving the anchor neurons (mcp/lifecycle_handler.py:193-267, storage/sqlite_fibers.py:373-378). Nothing records the forgotten content. Saving it again is a new memory, or an alias of the surviving anchor.

What holds

  • Every core read I checked carries brain_id = ?. One lookup, has_neuron_by_content_hash, does not (storage/sqlite_neurons.py:171), which matters only if one file ever holds several brains.
  • Brain ACL columns exist and enforcement is off by default (src/neural_memory/utils/config.py:46, :100); the REST server allows every request when NEURAL_MEMORY_API_KEY is unset (src/neural_memory/server/auth.py:72-73). This is a single-user tool.

Marks

  • trust_state — awarded. A stored status with a state that withholds a memory, filtered on the main read path and set by a person's resolution. The fiber-summary fast path is a live route around it.
  • bitemporal — awarded. A caller-set validity window separate from created_at, read by as_of recall. Nothing closes a window when a correction arrives, and expired is never set (recorded searches).
  • scope_enforced — awarded. project_id stored per memory and filtered on recall and nmem_context. Unscoped memories pass every project, and the global layer is appended after the filter.
  • negative_eval — awarded. The project-scope integration test asserts absence beside a positive control and an unscoped control.
  • tombstone — withheld. No record of forgotten or rejected content exists; the hits for "tombstone" are a session-end memory, a vector-index removal and sync's delete-wins rule.
  • audit_log — withheld. change_log is append-only and named, and on the unified adapter records inserts and deletes of neurons, fibers and synapses (storage/sql/mixins/change_log.py:44-95). It does not record updates, so a supersession, a conflict resolution or a soft forget leaves no row, and the legacy adapter, still the default for existing configs, records nothing. It is a sync outbox.
  • human_review — withheld. approve adds an APPROVED_BY synapse that nothing in the engine or storage reads; no memory waits for a decision.

10. Tests, Evals, and Benchmarks

The suite has 8,045 test functions across unit, integration, stress and Pro directories. CI runs pytest tests/ -m "not stress" with a 67% coverage floor on every push and pull request to main (.github/workflows/ci.yml:72). A nightly workflow runs a LongMemEval job (.github/workflows/benchmark.yml).

The strongest memory test is the project-scope file: it goes through the MCP JSON-RPC surface and asserts absence only after showing the same query returns the material unscoped. The status-filter unit cases are filter-level, with a fake storage. The gaps are where the findings are: no test drives a contradiction through the encode pipeline and then recalls, and the prefer_recent tests stop short of the handler.

Committed evidence lives in scripts/benchmark/results/. release-evidence.json was generated on 9 August 2026 at e82a2f4e… and records a curated recall@5 of 0.84 and nDCG@5 of 0.63 beside gate booleans. The README's comparison table against Mem0 and Cognee measures write and read time and API calls, not retrieval quality. I did not re-run either. No paper describes the system; the one arXiv identifier in docs/ cites another project's work.

11. For Your Own Build

Steal

  • Drop the fiber with its anchor. A status filter on neurons alone lets a superseded note return through its concepts; filtering fibers by anchor status closes that.
  • include_status as an explicit widening, with the shortcuts disabled for that call, so history is a request and not a default.
  • The project-scope test shape: seed two scopes and an unscoped item, assert the unscoped query sees everything, then assert each scoped query sees its own and not the other's.

Avoid

  • Computing a verdict and not applying it. If the resolver decides keep_new, write the supersession in the same step, and test the recall after it.
  • A fast path that a comment says is filtered. Put the status and validity predicates in the query every path shares.
  • hasattr guards around an update. A filter that falls back to the unfiltered result on a type mismatch fails silently.

Fit

A single developer who wants a local, model-free memory across Claude Code, Cursor and similar clients, and who will resolve conflicts by hand, gets a fast graph recall with a real status model. A team or service should look elsewhere: authorisation is off, scoping is a Python post-filter with unscoped memories visible everywhere, and corrections only take effect when a person resolves them.

12. Open Questions

  • Is the auto-resolver meant to write? Its verdicts carry a resolution field the step never applies, which reads as unfinished wiring rather than a choice.
  • How much recall is answered by the fiber-summary tier in practice? The 0.7 sufficiency threshold decides how often the filters are bypassed.
  • Does the Pro storage path keep the same status filter? It was not read.

Appendix: File Index

  • MCP server and handlers: src/neural_memory/mcp/server.py, remember_handler.py, recall_handler.py, conflict_handler.py, lifecycle_handler.py, eternal_handler.py, tool_schemas.py
  • Neuron model and status: src/neural_memory/core/neuron.py, core/memory_types.py
  • Encode and conflicts: src/neural_memory/engine/encoder.py, engine/pipeline_steps.py, engine/conflict_detection.py, engine/conflict_auto_resolve.py, engine/dedup/
  • Recall: src/neural_memory/engine/retrieval.py, engine/activation.py, engine/retrieval_context.py, engine/project_scope.py
  • Storage: src/neural_memory/storage/sqlite_schema.py, storage/factory.py, storage/sql/mixins/
  • Hooks: src/neural_memory/hooks/, .claude-plugin/hooks/hooks.json
  • Tests: tests/integration/test_project_scope_mcp.py, tests/unit/test_retrieval_status_filter.py, tests/unit/test_conflict_auto_resolve.py, tests/unit/test_recall_prefer_recent.py

Recorded searches

Run from the repository root at the pinned commit with /usr/bin/git grep.

  • expired is never set. git grep -n -F 'NeuronStatus.EXPIRED' -- src returns nothing; the control git grep -n -F '.with_status(' -- src returns engine/reflex_conflict.py:141, :176 and mcp/conflict_handler.py:207, :214, :245.
  • The auto-resolver writes nothing. grep -n -E 'update_neuron|add_synapse|with_status|with_metadata' src/neural_memory/engine/conflict_auto_resolve.py returns nothing; the control grep -n 'storage\.' … returns :61 and :96, both reads.
  • No pipeline-level conflict test. git grep -n ConflictDetectionStep -- tests returns nothing; the control git grep -l -E 'try_auto_resolve|conflict_auto_resolve' -- tests returns tests/unit/test_conflict_auto_resolve.py and tests/unit/test_grounded_neurons.py.
  • No record of forgotten content. git grep -n -i -E 'tombstone|blocklist|denylist|rejected_hash' -- 'src/*.py' returns mcp/session_handler.py:210-223, :410 (a session-end memory), storage/sql/mixins/neurons.py:513 and vector_search.py:177 (the vector index) and sync/incremental_merge.py:44, :54 (sync).
  • Updates are not journalled. git grep -n -E 'safe_log\(' -- src/neural_memory/storage/sql returns inserts and deletes only (fibers.py:149, :514, neurons.py:173, :527, :572, synapses.py:100, :239); the update methods are at fibers.py:410, neurons.py:456, synapses.py:174 and typed_memory.py:249.
  • Approval is not read. git grep -n -E 'APPROVED_BY|is_approved' -- src/neural_memory/engine src/neural_memory/storage returns nothing; the control on src/neural_memory/mcp returns three hits each in provenance_handler.py and tool_handler_utils.py.
  • lifecycle_state is not a recall gate. git grep -n lifecycle_state -- src/neural_memory/engine/retrieval.py src/neural_memory/mcp/recall_handler.py returns nothing.
  • The post-filters depend on _replace. git grep -n -F '_replace(' -- src/neural_memory/mcp/recall_handler.py returns :606, :644, :666, :704 beside the dataclasses.replace calls at :559, :1080, :1120; git grep -n 'def _replace' -- src returns only cache/manager.py:257, an unrelated _replace_cache.

History

2026-12-03 — 64757710…. First reading at the head of main (v4.63.0), from the 2026-12-03 triage shortlist. Four marks: trust_state, bitemporal, scope_enforced, negative_eval. Screened before reading: two auto-run surfaces, the Claude Code plugin directory with its four hooks and .claude-plugin/plugin.json, which starts the MCP server through uvx; npm-package/package.json and pyproject.toml inside the seven-day cooldown; eight build-time execution points (a Makefile, two setup.py, four conftest.py, one prepublishOnly); five floating surfaces, pyproject.toml with no lockfile; docs/agent-instructions/CLAUDE.md read as data. Nothing was installed, built or run, and no test was run.