Hindsight Memlake
A storage engine written in Rust, built for memory that only grows. 100 million memories at under 100 ms p99, every write durable before it is acknowledged, and four kinds of search over one copy, in a bucket you control. Part of Hindsight Enterprise.
The workload
Agents improve by remembering what worked and what didn’t, and unlike people, they never stop writing it down. Every fact, observation and mental model is more memory, and each one has to be findable in under a second.
Open-source Hindsight stores memory in Postgres, and for most deployments that’s the right choice. Running Hindsight across thousands of organizations, we measured where it stops keeping up with this workload:
Postgres isn’t doing anything wrong. The workload has an unusual shape: tiny records that only accumulate, four kinds of search over the same data on every recall, and every write visible the moment it lands. So we built a store for that shape of data.
Architecture
Each organization gets its own bucket, and each memory bank is a prefix inside it. Every write becomes one new, immutable log object; indexers fold the log into segments that are written once and never modified.
Only two objects ever change, the manifest and the head pointer, and only by conditional write: the store accepts a new version only if nobody changed it first. No database, lock service or leader beside the bucket.
Because nothing is overwritten in place, a reader always sees a complete version of a bank, never something in between, and servers never need to talk to each other.
01
A server writes each retain to the log with a conditional create, so two writers can never claim the same position, then advances the head pointer with another conditional write, and only then acknowledges. A retain is a single log entry, so it lands entirely or not at all. Writes don’t wait for indexing: the next recall, from any server, reads the part of the log that hasn’t been indexed yet.
02
Each bank is routed to the same server so its cache, in memory and on local NVMe, stays warm, and since objects never change, that cache never needs invalidating. A recall checks the head pointer, reads only the blocks it needs, scans the unindexed tail of the log and runs four searches. Hindsight sends its ranking policy with the request, so the server ranks next to the data.
03
A bank’s index lives on one server at a time, and Memlake grows by spreading banks across servers. When a server disappears, another picks up its banks with no handover and warms its cache as it serves. It held a cache, never data.
04
Indexers run apart from the servers that answer queries. An indexer folds new log entries into a fresh segment and publishes it by swapping the manifest, so indexing cost follows what’s new, not what’s stored. Two indexers can work on the same bank with no lock: one wins the swap, and the other’s files are garbage-collected.
05
An archiver copies every bank’s log, plus daily snapshots, to a separate bucket, ideally in another account with credentials that can’t delete. A bank can be restored to any point in time, and every restore is verified before traffic moves to it.
Written in Rust
Hindsight’s memory isn’t just vectors: entities, links and time are part of every recall. No off-the-shelf engine fit that shape, so we wrote one, in Rust, for the performance and the control over memory that a query path measured in milliseconds needs.
Design goals
Every change to Memlake is still reviewed against them.
Performance
Head to head through the full Hindsight API, same cluster, same data: on a small bank Memlake answers in a fifth of the time and serves ten times the traffic. On a large bank the gap is two orders of magnitude.
Correctness
Because correctness comes down to a handful of conditional writes, the write, indexing and garbage-collection protocols are specified in TLA+. A model checker explores every interleaving: many writers and indexers racing, servers crashing at any step, responses lost, processes stalling.
The specifications are re-checked in CI on every protocol change, and recorded executions of the real engine are checked against them so the code can’t drift from what was proven.
Cost and tradeoffs
A year for a whole company, one bank per employee or agent, each cluster sized to answer recall within 1 second at p99. Almost all of the difference is the memory store itself.
Availability
Memlake plugs into Hindsight’s storage layer. Your agents, SDKs and API calls don’t change.
Documentation
The 35-page technical whitepaper covers the storage layout, the write, index and query paths, durability, formal verification and the full evaluation, with every result labelled as measured, modelled or projected.