32b5afd1d9 feat(memory): topic trees (lazy hotness-driven materialisation) (#709) (#799)
Phase 3c of the memory architecture (umbrella #711). Adds per-entity
topic trees spawned lazily when an entity's hotness crosses a threshold,
so Phase 4 retrieval can resolve "what did Alice say about Phoenix?"
without scanning the full chunk pool.

## What's in this commit

New module `src/openhuman/memory/tree/topic_tree/`:

- `types.rs` — `EntityIndexStats` (hotness input), `HotnessCounters` (the
  persisted row) and the `TOPIC_CREATION_THRESHOLD=10.0`,
  `TOPIC_ARCHIVE_THRESHOLD=2.0`, `TOPIC_RECHECK_EVERY=100` constants.
- `hotness.rs` — pure arithmetic scorer plus deterministic
  `hotness_at(entity_id, stats, now_ms)` variant for tests, and a
  piecewise-linear `recency_decay` helper.
- `store.rs` — SQLite helpers (`get`, `get_or_fresh`, `upsert`,
  `distinct_sources_for`, `count`) for the new `mem_tree_entity_hotness`
  table.
- `registry.rs` — `get_or_create_topic_tree`, `force_create_topic_tree`,
  `list_topic_trees`, `archive_topic_tree`. Race-recovers on UNIQUE
  violations via `is_unique_violation`, mirroring `source_tree::registry`.
- `curator.rs` — `maybe_spawn_topic_tree` (per-ingest tick) and
  `force_recompute` (admin path). Implements the
  `TOPIC_RECHECK_EVERY`-gated recompute: refresh `distinct_sources` from
  the entity index, compute hotness, spawn + backfill if threshold
  crossed.
- `backfill.rs` — `backfill_topic_tree` walks the entity index and routes
  every historic leaf (ts-ASC ordered) through
  `source_tree::bucket_seal::append_leaf`. Capped at 500 leaves. Skips
  summary-node hits so topic trees only ever ingest raw leaves. Missing
  chunks log a warn and are skipped, never failing the spawn.
- `routing.rs` — `route_leaf_to_topic_trees` fans a kept leaf out to
  every active matching topic tree and ticks the curator for each
  entity. Archived trees are skipped but counters still bump.

Wired from ingest (`tree/ingest.rs::append_leaves_to_tree`) AFTER the
source-tree `append_leaf` succeeds — non-fatal on error, logged at warn
level so routing issues never poison the ingest hot path.

## Hotness scoring (pure)

```
hotness = ln(mentions + 1)          // dampened volume
        + 0.5 * distinct_sources    // cross-source bonus
        + recency_decay(last_seen)  // 1.0 @ day 0 → 0 @ day 30
        + graph_centrality          // Phase 4+; None → 0
        + 2.0 * query_hits          // retrieval feedback; Phase 4+
```

`graph_centrality` and `query_hits_30d` columns are persisted but the
increment code paths are deferred to later phases, as planned.

## Schema (additive, idempotent)

New table `mem_tree_entity_hotness` (keyed on `entity_id`) added to the
Phase 1 `SCHEMA` constant in `tree/store.rs` so it migrates through the
same `with_connection` path as the existing tables. `CREATE TABLE IF NOT
EXISTS` keeps it re-run-safe. An ancillary index on `last_hotness`
supports future sweep queries.

## Routing

The ingest path is the only non-admin caller. After `append_leaf` puts a
leaf in the source tree, `route_leaf_to_topic_trees` runs with the
chunk's canonical entity list. For each entity:

1. If an active topic tree exists, append the leaf to it (reusing
   `source_tree::bucket_seal::append_leaf` with `entities=[entity_id]`).
2. Tick `maybe_spawn_topic_tree` — may bump counters or, on cadence,
   recompute hotness and spawn + backfill a new tree.

Per-entity errors are caught and logged; a top-level failure is demoted
to a warn in the ingest caller so the source-tree append always wins.

## Reuses from Phase 3a

- `source_tree::bucket_seal::append_leaf` — same `&Tree` API works for
  `TreeKind::Topic` end-to-end.
- `source_tree::summariser::{Summariser, InertSummariser}` — honest stub
  emits empty entity/topic vecs on summary nodes.
- `mem_tree_trees` / `mem_tree_summaries` / `mem_tree_buffers` schema,
  discriminated by `kind = 'topic'` and `scope = <entity canonical id>`.
- Registry race recovery via `is_unique_violation` (catches UNIQUE on
  `insert_tree`, re-queries on collision).
- Idempotent append (duplicate `item_ids` in the L0 buffer are no-ops),
  so backfill is safe to re-run.

## Tests

40 new tests (10 hotness, 3 types, 6 store, 7 registry, 4 curator, 4
backfill, 5 routing, 1 integration). `memory::tree` suite: 201 passing,
0 regressions (Phase 3a baseline was 161 → +40 new).

Coverage highlights:
- Hotness pure math (zero-entity, spike-over-threshold, old-but-widely-
  cited retains signal, query-hit boost, recency decay edges).
- Curator: first-ingest-just-bumps, no-spawn-below-threshold,
  spawn-fires-exactly-once-when-crossed, cadence gating.
- Backfill: appends-all-entity-leaves, skips missing chunks,
  idempotent, skips summary nodes.
- Routing: empty-entities-noop, appends-to-existing-tree, archived-tree-
  skipped, multi-entity-fan-out, end-to-end-integration-materialisation.
- Registry: idempotent get-or-create, UNIQUE race recovery, archive
  flips status (not deletion), kind/scope cleanly separated from source.

## Deliberate non-goals (deferred)

- No JSON-RPC surface (out of scope for Phase 3c core).
- No archive cron sweep — `archive_topic_tree` primitive only.
- `graph_centrality` / `query_hits_30d` increments deferred to later
  phases (columns exist, reads work, writes are Phase 4+).

## Stacked on #789

Base is `feat/709-summary-trees`. Merge #789 first, then rebase this
branch.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 13:40:08 -07:00
2026-04-21 14:14:15 +00:00
2026-04-22 04:42:12 +00:00
2026-02-20 13:03:15 +04:00
2026-02-20 13:03:15 +04:00

OpenHuman

The age of super intelligence is here. OpenHuman is your Personal AI super intelligence. Private, Simple and extremely powerful.

DiscordRedditX/TwitterDocs

Early Beta Platforms: desktop only Latest Release

The Tet

"The Tet. What a brilliant machine" — Morgan Freeman as he reminisces about alien superintelligence in the movie Oblivion

Early Beta — Under active development. Expect rough edges.

To install or get started, either download from the website over at tinyhumans.ai/openhuman or run

# For MacOS/Linux
curl -fsSL https://raw.githubusercontent.com/tinyhumansai/openhuman/main/scripts/install.sh | bash

# For Windows
irm https://raw.githubusercontent.com/tinyhumansai/openhuman/main/scripts/install.ps1 | iex

What is OpenHuman?

OpenHuman is an open-source agentic assistant that is designed to integrate with you in your daily life. Here's what makes OpenHuman special:

  • Simple, UI-first — A clean desktop experience and short onboarding paths so you can go from install to a working agent in a few clicks, without a config-first setup. You don't need a terminal to run OpenHuman.

  • One subscription, many providers — You only need one account to get access to many agentic APIs (AI Models, Search, Webhooks/Tunnels and other 3rd party APIs etc..), simplifying the experience to get a powerful agent going.

  • Rich Skills — Plug into Gmail, Slack, Notion, and the rest of your stack via rich, feature-backed skills. Connections are typically one click through setup wizards instead of wiring APIs by hand. Workflow data is kept on device, encrypted locally, and treated as yours: encryption and sensitive context stay on your machine. Webhooks give instant feedback into the agent when external systems or skills emit events, so the loop stays tight without constant polling.

  • Local knowledge base — Built from your data and your activity. How you work across tools, sessions, and connected services—so the agent gets rich, workflow-aware context, not a one-off chat transcript. Everything is stored on your machine and compounding over time without becoming a cloud dossier. Channels, skills and ongoing conversations feed the same loop so day-to-day context does not reset every session.

  • Local AI model — The Rust core exposes local AI paths (and the desktop bundle can ship local/bundled runners where applicable) for the workloads above—vision snippets, speech helpers, summarization, tooling—so sensitive steps can stay off the cloud when you choose.

  • Deep desktop integrations — OpenHuman is a native desktop assistant, not a web-only chat: memory-aware keyboard autocomplete, voice (STT listening and TTS replies), screen intelligence that understands what is on screen and feeds your local context, plus windowing and OS-level permissions—so the agent meets you on the machine, not trapped in a browser tab.

Architecture: docs/ARCHITECTURE.md. Contributor orientation: CONTRIBUTING.md. Running from source: docs/install.md.

Highlights

  • Neocortex — local-first knowledge base that learns from your data and activity, compounding context across tools and sessions.
  • The Subconscious — background self-learning loops that turn everyday usage into workflow-aware intelligence.
  • Screen Intelligence — the agent sees what's on your screen and feeds it into your local context.
  • Inline Autocomplete — memory-aware keyboard autocomplete anywhere on your desktop.
  • Voice (STT + TTS) — speak to OpenHuman and hear it reply, natively on the desktop.
  • Skills & Integrations — one-click skills for Gmail, Slack, Notion and the rest of your stack, with local encryption and webhooks for instant feedback.
  • Messaging Channels — inbound/outbound across the channels you already use, routed through your agent.
  • Teams & Organizations — shared workspaces for collaborating with an agent across a team.
  • Rewards & Achievements — gamified progression as your agent grows with you.
  • Privacy & Security — workflow data stays on device, encrypted locally, and treated as yours.

OpenHuman vs other agents

High-level comparison (products evolve—verify against each vendor). OpenHuman is built to minimize vendor sprawl, keep workflow knowledge on-device, and ship deep desktop features—not only chat.

Claude Code/Cowork OpenClaw Hermes Agent OpenHuman
Open-source 🚫 Proprietary MIT MIT GNU
Simple to start Desktop + CLI ⚠️ Terminal-first ⚠️ Terminal-first Clean UI, minutes
Cost ⚠️ Sub + add-ons ⚠️ BYO models ⚠️ BYO models Local-friendly
Memory & KB Chat-scoped ⚠️ Plugin-reliant Self-learning 🚀 Local KB + learning
API sprawl 🚫 Extra keys 🚫 BYOK 🚫 Multi-vendor One account
Extensibility MCP SKILL.md SKILL.md 🚀 Rich Skills
Desktop integration ⚠️ Basic ⚠️ Light ⚠️ Light STT/TTS/screen/more

Contributors Hall of Fame

Show some love and end up in the hall of fame

OpenHuman contributors
S
Description
No description provided
Readme GPL-3.0
214 MiB
Languages
Rust 59.1%
TypeScript 37.9%
JavaScript 1.6%
Shell 1.2%
CSS 0.1%