Concepts

Engram makes five promises: memories are found by meaning; every write is tamper-evident; any recall can run in the past; new facts reconcile themselves with old ones; and forgetting is provable.

Entries and the chain

Every record in a space is an entry with a sequence number. Its ID encodes that number, m_<space>_<seq as 12 digits>, so ordering by ID is chain order. An entry is one of four ops:

OpHoldsEffect
remembertext and an embeddinga new memory (fact, preference, event, observation)
reflecta model-written summarya summary memory linked to its sources
forgeta reason, a tombstone vectorthe target's text, salt and vector are erased
linka reason, a tombstone vectorrecords a resolution: supersede, refine, dismiss, or a conflict found later

The four hashes

  • genesis: SHA-256("engram:genesis:v1:" + space), the previous hash of entry 0.
  • content hash: a salted hash of the text. Forgetting deletes the text and the salt and keeps this hash, so a short fact cannot be recovered by guessing.
  • vector hash: binds the exact embedding (rounded to 5 decimals), so a swapped vector is detected.
  • header hash: over the canonical form of every immutable field, including the previous entry's hash.

Status, validity windows, conflicts and access counts are derived: they are recomputed by replaying the chain, and the verifier flags any disagreement.

Lock-free writes

Two writers that read the same head compute the same next ID. VectorsDB accepts only one create for that ID; the other gets a conflict and rebuilds on the new head. No queue, no lock document. Derived updates on neighbours (status, validity, conflicts) are then applied one conditional compare-and-swap write at a time, each only if the document is unchanged since it was read, because VectorsDB transactions do not work on this project. They are idempotent, and the new entry stays marked as pending until all of them land, so the next writer finishes a batch an instance left half done.

Checkpoints

A scheduled Function builds an RFC 6962 Merkle tree over the header hashes, signs the root, head and size with Ed25519, and stores the checkpoint as a file. Each checkpoint links to the previous one. Optionally the root is committed to a public GitHub repository, an outside timestamp the operator cannot rewrite. Inclusion proofs show that one memory is part of a signed checkpoint.

Contradictions

When a new memory is close to existing active ones, Engram classifies each pair as duplicate, supersedes, contradicts, refines or unrelated. Fast rules handle near-identical text and different subjects; a small model handles the rest; a write is never blocked on the model. Supersessions retire the old memory with a validity end. Real conflicts keep both memories active and land in the conflict inbox, where a decision is recorded as a link entry.

Time travel

An as-of recall keeps memories created at or before the chosen time that were still valid then. The fast path reads derived validity fields; the authoritative mode replays the chain from entry 0. Memories erased later are shown as receipts: the past is reconstructable except for what was deliberately erased, and the erasure is on record.

Tamper Lab

In sandbox spaces, nine attackers corrupt the stored documents with full database access, each smarter than the last: editing text, fixing the content hash, fixing the entry hash, swapping entries, poisoning a vector, hiding a supersession, resurrecting erased data, truncating the chain, and rewriting all later history. Each is caught by a different layer, the last two only by the signed checkpoint.

Spec corrections

The implementation corrects a few issues in the original design documents: checkpoint fields are all strings so they can be signed canonically (and the GitHub anchor is signed too); a memory without text must be targeted by a later forget entry; a tombstone vector is allowed only on forget/link entries and forgotten memories; space keys allow digits; createdAt is forced to never decrease. See docs/spec-corrections.md in the repository.