1. Executive Summary
memhub is a Python memory SDK and a local "Memory Hub" that gives Claude Code, Codex, Cursor and the other hosts in its installer one shared store. Hooks and transcript import feed a local Core, a worker extracts claims with an LLM, and a closed-set decision model, Jev, decides whether each claim adds to, replaces, negates, conflicts with or repeats a current memory. Prompt hooks inject recalled memories and the project's conventions before each turn.
Notable: memory is versioned, not edited. Stored documents are immutable, a replacement links the old version behind the new one, and every change is one version plan committed under a revision check. The decision model picks targets only from ids it was offered, and an event-time guard stops a late report of an older state from retiring a later one. The accompanying paper measures that guard.
Weak: scope is held by the caller. The SDK's MCP server lets the model name the user, list every scope and delete a whole app. The REST service accepts any bearer string. The Hub is one user, and its project filter is widened by a second pass. Delete archives and nothing erases one memory. The default decision endpoint is a hosted third-party model.
Lineage. The package was dual_mem until
0.2.2 (CHANGELOG.md:126). It is not a GitHub fork of Hy-Memory, and the repository has no parent,
but it borrows from Hy-Memory by name. System 2 is "aligned with
hy-memory 2.0.4" (memhub/system2/system2_agent.py:1), the
read engine claims "Hy-Memory parity"
(memhub/retrieval/hybrid_engine.py:3), and the Hub was
modelled on Hy-Memory's MemHub (CHANGELOG.md:235). Three
differences matter against Hy-Memory at its atlas pin. memhub checks a
decision's target against the offered ids; Hy-Memory's chat reconciler
does not. Its delete archives and restores nothing; Hy-Memory's restores
the predecessor. Its updates append; Hy-Memory's UPDATE rewrites in
place.
Three marks are present and four are withheld (section 9).
Licence. The default write-decision model is a
hosted service outside the grant: jev_endpoint is
https://api.typesafe.ai/v1/systemone with model
jev-1.13.0 (memhub/config.py:171-173), and the
terms for that service are nowhere in the tree. Every write that finds a
similar memory sends the extracted claims and candidate memories there.
The self-hostable alternative the paper evaluates, MEMJEV, is trained
and served from a separate repository. The code itself is Apache-2.0 in
LICENSE, with the appendix's copyright line left as the
template. There is no SECURITY.md.
2. Mental Model
A turn becomes evidence before it becomes belief. The raw dialogue is
stored as an L0_RAW node whose document can never change
(memhub/storage/vector_store.py:1034-1072). An LLM then
proposes atomic claims, each tagged with who said it and, only for an
explicitly limited exception, a validity window
(memhub/agent/extractor.py:168-173).
A belief is a node that is ACTIVE and
is_latest. MemoryStatus has one
value, ACTIVE (memhub/types.py:38-39), so
currency is carried entirely by is_latest,
supersedes, superseded_by and an
archived flag in custom.
Each claim is compared with the scope's current heads. A head below
cosine 0.60 is not a candidate, and a claim with none is appended
without a model call (memhub/agent/reconciler.py:398-402,
:477-481). Otherwise Jev answers two closed questions:
which offered id, or NONE, is this claim about; and which
action applies (:505-552). The answer must be one of the
offered ids (:519-521) and one of the offered actions
(:295-296).
| Action | Effect on the target | New node |
|---|---|---|
ADD_SUPPLEMENT |
none | current |
ADD_TEMPORAL |
none | current, with a validity window |
ADD_OVERRIDE, ADD_NEGATE |
not latest, linked forward | current, supersedes the target |
ADD_HISTORICAL |
stays current, links back | not latest, behind the target |
ADD_CONFLICT |
stays current | current, conflicts_with the target |
DELETE |
archived, not latest | none |
SKIP, RAW_ONLY, INVALID |
none | none |
The event-time guard. When the claim's source is
older than a chosen target, the action set shrinks to
ADD_HISTORICAL, ADD_CONFLICT,
SKIP, INVALID and NEED_CONTEXT
(memhub/agent/reconciler.py:53-61, :141,
:524-543). An imported old conversation can record a past
value, linked behind the head at commit
(memhub/storage/vector_store.py:1445-1459); it cannot
retire a later one. An undecided relation, or one under the configured
confidence floor, is written as an independent supplement
(:651-659).
Diagram source
%% caption: every claim is decided against the scope's current heads, and a retired head stays in the store as a bridge to what replaced it
flowchart TD
TURN["Host turn or<br/>SDK add"] --> RAW["L0_RAW node<br/>immutable document"]
RAW --> EXT["LLM extraction<br/>claims, owner,<br/>explicit window"]
EXT --> NB{"current head in scope<br/>at cosine 0.60+?"}
NB -- "no" --> APP["ADD_SUPPLEMENT<br/>or ADD_TEMPORAL"]
NB -- "yes" --> TGT["Jev picks a target<br/>from offered ids"]
TGT --> AGE{"source older<br/>than target?"}
AGE -- "yes" --> OLD["HISTORICAL, CONFLICT,<br/>SKIP or INVALID"]
AGE -- "no" --> ACT["OVERRIDE, NEGATE,<br/>DELETE, CONFLICT,<br/>SKIP"]
APP --> PLAN["apply_version_plan<br/>revision and scope CAS"]
OLD --> PLAN
ACT --> PLAN
PLAN --> HEAD["new head<br/>is_latest true"]
PLAN --> RET["old head not latest,<br/>or archived"]
HEAD --> READ["recall: app, user, agent,<br/>ACTIVE, latest"]
RET -. "bridge to successor" .-> READ3. Architecture
The SDK is MemoryClient (memhub/client.py).
It builds a MemoryWriter in system1 mode or a
System2Writer in dual mode, and both write
through MemAgent and Reconciler
(memhub/agent/). ChromaVectorStore holds every
node in one Chroma collection and owns a SQLite journal,
versions.db, of plans, a replication log, scope epochs,
request keys and node tombstones
(memhub/storage/vector_store.py:214-288). Coding
trajectories take a parallel path in memhub/coding/ that
distils procedures through the same version plans. Dual mode adds Kuzu
for derived schemas (memhub/storage/graph_store.py).
The Hub (memhub/hub/) is the product most users install.
memhub serve runs one FastAPI Core, refused any host but
loopback, behind a bearer token it generates
(memhub/cli/hub.py:320-341,
memhub/hub/server.py:615-626). A durable
hub_writes queue receives evidence, and one worker
processes it in event-time order with retries
(memhub/hub/queue.py:1-17, :276).
memhub/hub/hosts.py:733-837 defines 19 host entries, each
wired with an MCP server, a recall skill and, where the host has hooks,
capture and prompt-time recall. memhub/hub/sync.py
replicates the store's change log across devices through a git
repository, a folder or SSH, with no model call on the receiving
side.
A separate REST service (memhub/api/app.py) and an SDK
MCP server (memhub/mcp/server.py) expose the SDK's
operations to developers embedding it.
Deployment and ergonomics
pip install "memhub[all]",
memhub install-service, memhub install-host
and optionally memhub scan to import past transcripts.
Three model endpoints are configured in
~/.memhub/config.yaml: an LLM, an embedding model and the
Jev decision endpoint. The LLM and embedding keys are checked at start
(memhub/client.py:193-215); the Jev key is not. Nothing
else runs as a service: Chroma, SQLite and Kuzu are embedded.
4. Essential Implementation Paths
- Capture (Hub). A host hook or transcript scan posts
to
/v1/hub/writes; the Core skips excluded workspaces and<private>turns, sanitises, and queues (memhub/hub/server.py:652-712). - Raw evidence.
MemoryWriter.writederives the raw node's id from the request, stores it and its embedding, and then extracts (memhub/writer/memory_writer.py:53-123,:125-176). - Extract.
MemAgent.run_system1: one extraction pass; no candidates records aRAW_ONLYdecision (memhub/agent/mem_agent.py:297-355). - Decide.
Reconciler.reconcile: neighbours per claim, target questions, action questions, ops (memhub/agent/reconciler.py:382-583), under a per-scope lock (memhub/agent/mem_agent.py:373-387). - Commit.
apply_version_plan: replay check, revision and scope check on every target, patch old heads, retire derived schemas that cited a retired fact, journal the plan, then write Chroma and the history events (memhub/storage/vector_store.py:1324-1603,:952-990). - Recall (Hub). The prompt hook calls
/v1/hub/recallwith the workspace; the Core builds the project view and runs the scoped search and a wider pass (memhub/cli/hub.py:841-856,memhub/hub/server.py:861-956). - Search.
search_hybrid: filtered vector query, lexical candidates, BM25 fusion, superseded bridges, profile and procedure groups (memhub/retrieval/hybrid_engine.py:628-712,:176-218). - Correct.
MemoryClient.updateappends a version anddeletearchives, both throughapply_version_plan(memhub/client.py:712-777).
5. Memory Data Model
MemoryNode (memhub/types.py:68-94):
- scope:
app_id,user_id,agent_id,session_id; layer:L0_RAW,L1_FACT,L2_PROFILE,L3_DERIVED, withkindfor fact, profile, intention, procedure, schema and persona catalog;- version:
revision,supersedes,superseded_by,is_latest, and incustomtheupdate_type,conflicts_with,source_idsandarchived; - time:
memory_at(when the source happened),gmt_created(the clock at write),gmt_modified, andvalid_from,valid_until; owner:useroragent, from the extractor's speaker field (memhub/agent/mem_agent.py:227-230).
versions.db holds plans (one row per
committed plan, with its decisions, nodes, patches and an
audit list), log (every local change by origin
and sequence), epochs, requests,
projections and tombstones, which is keyed on
node id and exists so a replica does not bring a deleted node back
(memhub/storage/vector_store.py:227-256).
history.db holds history, an event table of
old and new metadata
(memhub/storage/history_store.py:14-24).
A procedure keeps task, solution, files, branch and environment
boundaries in custom["procedure"]; a correction to one
replaces its solution and keeps the task as the index text
(memhub/client.py:724-728).
6. Retrieval Mechanics
The read path has no model call. search_hybrid builds
three filters from the caller's app ids, user, agent ids and session
ids: current facts and profiles (ACTIVE, latest, not
procedures), profiles, and superseded versions
(memhub/retrieval/hybrid_engine.py:681-712). It queries
Chroma for a pool of at least 60, adds lexical candidates from an
inverted BM25 index keyed on the store's write generation, and fuses
semantic and BM25 scores at 0.6 and 0.4
(memhub/config.py:249-250).
Superseded wording leads to its replacement. Up to
20 superseded versions near the query are fetched, and each passes its
score to the current node that replaced it, which is added if it is
latest, in the same app and user, and valid at as_of
(memhub/retrieval/hybrid_engine.py:176-218,
:727-737). A committed test asserts the replacement is
returned and the superseded version is not
(tests/test_hybrid_engine.py:164-169).
as_of drops nodes whose explicit window excludes it
(:73-80). Only the REST search passes one through from a
request (memhub/api/app.py:192); the Hub never does. The
Hub's project view, built per workspace from current nodes, checks
windows against the clock (memhub/hub/server.py:192-199,
:202-269).
Hub scope. The Hub has one user,
default (memhub/hub/server.py:67). A workspace
maps to the sessions recorded in it. Recall searches those sessions,
then searches the whole user and admits any other project's fact that
scores above this project's best (:890-919). A committed
test pins that admission (tests/test_memhub.py:2347-2409).
The Hub MCP server's memory_search passes no workspace at
all (memhub/hub/mcp.py:287-299).
The prompt hook also asks for up to three dated raw excerpts
(memhub/cli/hub.py:853-855). Superseded or archived wording
drawn from an excerpt's dialogue is attached as
retired_claims, so the reader sees which of its sentences
were retired (memhub/hub/server.py:293-346,
:930-940).
7. Write Mechanics
On the Hub, writes do not block the agent: the Core answers once the
evidence row is durable, and the worker extracts later
(memhub/hub/server.py:709-712). A memory is retrievable
once the worker has committed its plan; the project view and the
retired-claims index rebuild on the next read after the store's write
generation changes (memhub/hub/server.py:328-346,
:366-372). Through the SDK, add blocks for
extraction and decision.
Extraction asks for atomic claims with speaker, durability and an
explicit window when stated, and drops candidates marked
durable=false
(memhub/agent/mem_agent.py:196-258). Assistant claims are
kept as L1_FACT with owner agent; the project
view excludes them (memhub/hub/server.py:255).
The decision runs under a per-scope lock, so a concurrent write sees
the prior heads. Collisions inside one batch are settled without another
model round: two proposals retiring one head leave the higher-confidence
one linked and the rest as supplements
(memhub/agent/mem_agent.py:45-126). An external update that
moves a linked head between decision and commit fails the revision check
and raises for a retry (:431-434).
Nothing waits for review. The writer's docstring
says so: there is no review queue to come back to
(memhub/agent/mem_agent.py:306-311), and the reconciler
writes an undecided relation as a supplement instead of deferring it
(memhub/agent/reconciler.py:651-654).
No background pass rewrites the store. In dual mode, System 2
clusters current facts into derived schemas and a persona catalog; a
schema whose evidence is retired is set not latest at commit
(memhub/storage/vector_store.py:1471-1504).
Operational cost
One LLM extraction per write and one embedding per claim. Jev is called only for claims with a candidate head; the paper reports that the cosine shortcut skips 41.2% of production writes. Reads cost one query embedding.
8. Agent Integration
The Hub MCP server registers memory_add,
memory_search, memory_get,
memory_list, memory_update,
memory_delete, conversation_search and
memory_status, all bound to the Hub's one user
(memhub/hub/mcp.py:245-428). Hooks inject a
<relevant-memories> block with the project view,
memories and excerpts before each prompt
(memhub/cli/hub.py:841-880).
The SDK MCP server registers ten tools. It takes user_id
and app_ids from the model on memory_add,
memory_search, conversation_search and
memory_list, and adds memory_get,
memory_update and memory_delete by id,
memory_delete_scope, memory_list_scopes and
memory_digest (memhub/mcp/server.py:72-216).
Framework integrations for Agentica, Hermes and OpenClaw fix the user
and agent from configuration for reads and writes, and pass update and
delete through by id
(memhub/integrations/_base.py:953-978).
9. Reliability, Safety, and Trust
Versions commit or replay
A plan's id hashes its scope, nodes, archives and expected revisions.
A replay of a done plan checks that the content matches and returns; a
different content under the same id raises
(memhub/storage/vector_store.py:1347-1374). Every target
must exist, sit in the plan's scope, be latest and active, and carry the
expected revision (:1377-1387). The plan is journalled
before Chroma changes, and unfinished plans are completed on the next
open (:316-330).
Scope is the caller's
build_filter applies app, user, agent and session on
every SDK read (memhub/isolation.py:15-51), and commit
refuses a node that crosses scope
(memhub/storage/vector_store.py:1422-1424). Who chooses the
scope is the gap. The SDK MCP server takes the user from the model and
lists every scope. memory_delete_scope with
confirm=true and no user deletes every memory in the app
(memhub/mcp/server.py:189-203,
memhub/client.py:787-798). get,
update and delete by id check no scope
(memhub/client.py:684-689, :712-777).
The documentation describes the REST service as authenticated
(docs/architecture.md:48,
docs/mcp_integration.md:110), but
_verify_bearer accepts any non-empty bearer string, and
auth_disabled defaults to true
(memhub/api/app.py:49-60,
memhub/config.py:152-153). The user comes from the request
body.
Correction and erasure
Update appends and delete archives. The archived node keeps its
content and embedding, and the documentation says so
(docs/memhub.md:86-87). The only physical delete is the
scope-wide one. A deleted value extracted again finds no current head,
because the candidate filter reads latest nodes only
(memhub/agent/reconciler.py:429-438), and is appended as a
new memory. ADD_NEGATE is the nearest thing to a refusal:
the negation is a current head the next extraction is compared against,
and the model decides the relation.
Privacy
<private> blocks and whole private turns are
dropped before storage; secret redaction is off by default
(memhub/config.py:157-161). The README calls the product
local-first with no telemetry, while the default Jev endpoint is a
third-party host that receives claims and candidate memories.
Marks
bitemporal— present. A validity window apart from record time and source time, filtered byas_of; set only for explicit exceptions, and the Hub's dynamic recall never passesas_of.audit_log— present.historyis insert-only and receives every version plan's events;persist_historydefaults to false, and the always-on record is the plan journal'sauditlist.negative_eval— present. Populated absences for a superseded version, an expired window, another workspace and another agent.scope_enforced— withheld. The library filters on scope, and the shipped SDK MCP server lifts it: the model names the user, lists every scope and can delete an app. The Hub has one user and treats project as a preference.trust_state— withheld.MemoryStatushas one value;is_latest,archivedandconflicts_withare lifecycle and relation, and both sides of a conflict are delivered.tombstone— withheld. Thetombstonestable is keyed on node id for replication; an archived value re-extracted is appended anew. A negation head is compared by the model, not keyed on the value.human_review— withheld. Nothing waits: the writer commits every decision, and the UI and the agent's ownmemory_updateedit after the write.
10. Tests, Evals, and Benchmarks
The suite is pytest with fake embeddings, a scripted LLM and a
scripted Jev: 579 test functions in 63 files, 88 of them in
tests/test_memhub.py for the Hub. One recall benchmark is
behind a benchmark marker and skipped by default. The
repository's only workflow builds the documentation
(.github/workflows/docs.yml), so no CI runs the tests. I
ran none of them.
The negative cases are populated. The supersession case puts five
distractors closer to the query than the replacement, so only the bridge
can recall it, and asserts the old version absent
(tests/test_hybrid_engine.py:125-169). The validity case
asserts the same memory present inside the window, absent after it and
present with no time
(tests/test_decision_protocol.py:181-198).
A paper describes the system. Its subtitle is
Versioned Long-Term Memory for Chat Agents in Deployed Advertising
Support; it is committed as
docs/public/Versioned-memory.pdf, by six Tencent authors,
with arXiv submission pending and no id. Its two-stage decision, 0.60
cosine shortcut, event-time guard and version bridges match the code.
Its decision model is MEMJEV, self-hosted; the code's default is
TypeSafe's jev-1.13.0. Its offline benchmark, Ad-MemBench,
is internal and not released, and no harness for its LoCoMo,
LongMemEval-S or PersonaMem-v2 numbers is committed: /exp/
and tmp/ are gitignored.
Cases to want first: one SDK user's search beside another user's populated memories; a deleted value extracted again; an expired window through Hub recall.
11. For Your Own Build
Steal
- Guard replacement with event time. If the incoming source is older than the target, offer only historical, conflict and skip. Imports and late messages then record the past without overwriting the present.
- Constrain the decision to offered ids. Ask a closed
question whose options are the candidate ids plus
NONE, and reject anything else. - Make documents immutable and versions plans. A journalled plan with expected revisions gives retries, crash recovery and replication one shape.
- Let retired wording find its replacement. Searching superseded versions and following the edge recalls a change whose new wording shares nothing with the question.
Avoid
- Do not let the model choose the scope. A
user_idargument and a list-scopes tool on an agent-facing server put every user's memory one call away. - Do not accept any bearer string. Compare it with something.
- Do not make archive the only delete. A memory a person removes should be erasable, and its value should not return on the next extraction.
Fit
Fits one developer who uses several coding tools on one or more machines, wants corrections to replace rather than accumulate, and is content to call three model endpoints. The decision layer and the version journal are worth reading whatever the product.
Walk away if several people share a deployment, if memory must not leave the machine and the decision model cannot be self-hosted, or if a deleted memory must be gone.
12. Open Questions
- Whether the SDK MCP server is meant for multi-user deployments,
given the model-supplied
user_idandmemory_delete_scope. - Whether the REST bearer check is meant to be completed by something in front of the service, since nothing in it compares the token.
- Whether the Hub's dynamic recall should pass the clock as
as_of, as the project view effectively does. - How the paper's MEMJEV relates to the default
jev-1.13.0endpoint for users who follow the README.
Appendix: File Index
- Domain:
memhub/types.py,memhub/isolation.py,memhub/config.py - Write:
memhub/writer/memory_writer.py,memhub/agent/mem_agent.py,memhub/agent/extractor.py,memhub/agent/reconciler.py,memhub/providers/jev.py - Store:
memhub/storage/vector_store.py,memhub/storage/history_store.py,memhub/storage/graph_store.py - Read:
memhub/retrieval/hybrid_engine.py,memhub/retrieval/reader.py,memhub/retrieval/bm25.py - Coding:
memhub/coding/ - System 2:
memhub/system2/system2_agent.py - Hub:
memhub/hub/server.py,memhub/hub/queue.py,memhub/hub/mcp.py,memhub/hub/sync.py,memhub/hub/hosts.py,memhub/cli/hub.py - Developer surfaces:
memhub/client.py,memhub/api/app.py,memhub/mcp/server.py,memhub/integrations/_base.py - Paper and docs:
docs/public/Versioned-memory.pdf,docs/memhub.md,docs/jev-memory-design.md,docs/benchmarks.md - Tests:
tests/test_hybrid_engine.py,tests/test_decision_protocol.py,tests/test_memhub.py,tests/test_progressive_recall_and_project_view.py,tests/test_sqlite_stores.py
Recorded searches
Run from the repository root at the pinned commit with
/usr/bin/git grep. .gitmodules is absent.
- One status value.
git grep -n -E "MemoryStatus\.[A-Z_]+" -- memhubreturns onlyMemoryStatus.ACTIVE. - The history table is never updated, deleted or
read.
git grep -n -i -E "DELETE FROM|UPDATE (plans|log|history)|DROP TABLE" -- memhubreturnscache_store.py:103and:148,vector_store.py:540,:806,:827and:988, none onhistory;git grep -n list_for_node -- memhubreturns only its definition atmemhub/storage/history_store.py:83. persist_historyhas no setter in code.git grep -n persist_historyreturns the default, the registry,client.py:806, a test of the default and documentation.- Only the REST service passes
as_offrom outside.git grep -n -E "as_of=" -- memhub | grep -v "as_of=as_of"returnsmemhub/api/app.py:192. - The write path does not consult archived nodes.
git grep -n -E "archived" -- memhub/agent memhub/coding memhub/system2returns nothing; the same pattern overmemhub/hub/server.pyreturns its read filters. - No review queue.
git grep -n -i -E "approve|pending_review|review_queue" -- memhubreturns nothing;git grep -n -i review -- memhub/agentreturns the confidence floor and one docstring. - The REST bearer is not compared.
git grep -n -E "compare_digest|api_key|token" -- memhub/apireturnsmemhub/api/app.py:58-59, the prefix strip and the emptiness check. - No cross-user negative case.
git grep -n -E 'user_id="(u2|bob|other|user2|b|u_b)"' -- testsreturnstests/test_list_scopes.py:14only, a scope listing. - CI.
git ls-files .githubreturns.github/workflows/docs.ymlonly. - No benchmark harness.
git grep -l -i -E "locomo|longmemeval|personamem" -- .returnsCHANGELOG.md, the two READMEs,docs/benchmarks.md,docs/index.md,memhub/config.pyandtests/test_formatter.py. - Paper.
CITATION.cffis absent;git grep -n -i -E "arxiv|doi\.org|bibtex" -- .returns the README badges, citation blocks and news lines for the committed PDF,docs/benchmarks.md:3,docs/index.md:70, andCHANGELOG.md:289, which cites DCPM (arXiv 2606.09483) as a design source.
History
2026-12-04 — 74ddc2d4….
First reading, from the 2026-12-04 triage shortlist, at the head of
main. Triage assessed cb32124, 21 commits
before the pin; the depth-1 clone does not hold it. Screened: five files
scanned, no auto-run surface; pyproject.toml and
requirements-docs.txt inside the seven-day cooldown, a
count the depth-1 clone inflates; one build-time execution point
(tests/conftest.py); two unpinned surfaces. Nothing was
installed, built or run, and none of the 579 test functions was run.
Three marks (section
9).