Skip to content

hanzo-brain: pure-CPU algorithm primitives + BLAKE3 across all 5 runtimes#8

Merged
hanzo-dev merged 3 commits into
mainfrom
brain/canonical-rust
May 11, 2026
Merged

hanzo-brain: pure-CPU algorithm primitives + BLAKE3 across all 5 runtimes#8
hanzo-dev merged 3 commits into
mainfrom
brain/canonical-rust

Conversation

@hanzo-dev
Copy link
Copy Markdown
Member

Summary

Adds hanzo-libs/hanzo-brain — the canonical Rust port of the Hanzo Brain algorithm surface inside the node workspace. Brain's recall / search / ingest are now first-class node calls; no sidecar needed.

Five runtimes ship the same algorithm surface, byte-equivalent on the wire:

Runtime Where Hash backend
TypeScript hanzoai/brain@hanzo/bot-memory @noble/hashes/blake3
Python hanzoai/python-sdkhanzo-memory blake3 pip (mirror: hanzoai/blake3-py)
Go hanzoai/bot-gopkg/brain lukechampine.com/blake3 (mirror: hanzoai/blake3-go)
Rust (node) this PR — hanzo-libs/hanzo-brain blake3 crate (hanzoai/blake3 fork)
Rust (mcp) hanzoai/mcp blake3 crate
C++ hanzoai/bot-cpp vendored BLAKE3 reference impl (tracked from hanzoai/blake3)

Cross-runtime verification — encode_address([0u8; 32], "hanzo"):

hanzo:UFC8qCW8LRUmpfyRq2qnAvYi11cqftY3b

(identical on every runtime).

What this adds to the node workspace

  • hanzo-libs/hanzo-brain (new workspace member)
    • src/algorithms.rs — 1454 lines, 38 unit tests
    • src/lib.rs — crate root + doc cross-references to sibling crates
    • Cargo.toml — depends on blake3 = { workspace = true } and once_cell
  • Cargo.toml (1 line in [workspace.members])
  • Cargo.lock (regenerated)

Commits

  • hanzo-brain: pure-CPU algorithm primitives shipped as a node-side lib (initial crate)
  • hanzo-brain: silence unused_mut warning + tighten lib doc
  • hanzo-brain: BLAKE3 (matches all five brain runtimes)

Test plan

  • cargo build -p hanzo-brain — clean
  • cargo test -p hanzo-brain --lib — 38 / 38 passed
  • Cross-runtime BLAKE3 address verification — all five runtimes produce byte-identical output

Sister crates the brain wires into (already in workspace)

  • hanzo-libs/hanzo-consensus (Quasar metastable consensus)
  • hanzo-libs/hanzo-zap (ZAP transport)
  • hanzo-libs/hanzo-pqc (post-quantum signatures)
  • hanzo-libs/hanzo-db-sqlite (SQLite + FTS5 default storage)

Chain layer (validators, bridge, DEX, faucet, explorer, wallet) lives in the hanzonet org and is inherited by the node.

hanzo-dev added 3 commits May 11, 2026 12:54
Adds hanzo-libs/hanzo-brain — the canonical Rust port of the Hanzo
Brain algorithm surface inside the node workspace. Mirrors the TS
canonical (@hanzo/bot-memory), Python (hanzo-memory), Go (bot-go/pkg/
brain), and C++ (bot-cpp) ports. 38 unit tests passing.

Lives alongside the rest of the brain's wire-up inside hanzoai/node:

  hanzo-consensus    Quasar metastable consensus (storage quorum)
  hanzo-zap          ZAP transport
  hanzo-pqc          post-quantum signatures (recipient blocks)
  hanzo-machine      threshold-crypto primitives (MMPKE01 wraps)
  hanzo-db-sqlite    SQLite + FTS5 default storage

This makes brain.recall / brain.search / brain.ingest first-class node
RPC methods — any agent talking to a Hanzo Node gets the brain without
a sidecar.

Algorithm surface (mirrored across all five runtimes):
- Retrieval: RRF, RSF, adaptive k + weights, MMR, dedup, two-stage MRL
- Text:      Unicode script detection, CJK bigrams, emoji trigrams,
             websearch_to_tsquery, FTS5 MATCH renderer
- Embed:     model registry, asymmetric E5 prefixes, MRL truncation
- Eval:      MRR, recall@k, precision@k, NDCG@k
- Temporal:  UUIDv7 floor/ceiling
- Captions:  WebVTT / SRT / RTTM
- Crypto:    wallet-style content-addressable ids
- Graph:     normalize → SNN → PFNET → Louvain
- Inference: provider slug, runtime config (db_override → env →
             default), link-type classifier
- algorithms.rs: drop redundant `mut` from the `flush` closure binding in
  estimate_tokens (the closure is `FnMut` via the captures it needs, not
  via the binding). Clears the only cargo-build warning the crate emits.
- lib.rs: describe siblings as "workspace crates" without org-style links;
  spell out that this crate lives at hanzo-libs/hanzo-brain/ inside the
  hanzoai/node Cargo workspace; add hanzo-runtime as a sibling integration.

Build clean. cargo test -p hanzo-brain --lib: 38 passed; 0 failed.
Algorithm surface unchanged (byte-equivalent with hanzoai/mcp mirror).
Swapped sha2 stand-in for the workspace blake3 crate so wallet addresses
match the TS canonical (@noble/hashes/blake3), Python (blake3 pip),
Go (lukechampine.com/blake3), and C++ (vendored reference impl) byte-
for-byte:

  encode_address([0u8;32], None)
  → hanzo:UFC8qCW8LRUmpfyRq2qnAvYi11cqftY3b   (all five runtimes)

38 brain tests still pass.
@hanzo-dev hanzo-dev merged commit b132d2b into main May 11, 2026
3 of 5 checks passed
@hanzo-dev hanzo-dev deleted the brain/canonical-rust branch May 11, 2026 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant