Skip to content

AI second brain: on-device semantic vector tier — 0211 LIVE (checks off) - #236

Merged
crs48 merged 2 commits into
mainfrom
claude/ai-semantic-tier
Jun 22, 2026
Merged

AI second brain: on-device semantic vector tier — 0211 LIVE (checks off)#236
crs48 merged 2 commits into
mainfrom
claude/ai-semantic-tier

Conversation

@crs48

@crs48 crs48 commented Jun 22, 2026

Copy link
Copy Markdown
Owner

The final piece of exploration 0211 — wakes the dormant @xnetjs/vectors engine behind the retriever seam, making the semantic half of the AI second brain live. After #228 (engine), #230 (seam), #232 (graph-aware retrieval live), and #233 (xnet_graph_expand), this flips 0211 to [x].

What ships

ai-vector-search.tscreateVectorEntrySearch (opt-in, lazy, fallback-safe):

  • The heavy @xenova model + usearch load via a dynamic import only on the first search after opt-in — zero boot/bundle cost when off (the 0204 constraint).
  • Once warm it RRF-fuses vector + keyword; until warm and on any failure it falls back to keyword — so enabling it can only ever match or improve results, never break or slow the chat.
  • ai-vector-storage.ts — IndexedDB BlobStore so the index restores across sessions instead of re-embedding the graph each time.
  • AiChatPanel — an opt-in toggle (off by default); the flag is read via a ref so toggling never tears down the AI runtime mid-conversation.

Adversarial review caught 3 real bugs (fixed here)

A 22-agent review (18 findings → 15 false positives killed by verification → 3 confirmed) surfaced:

  1. loadVectorTier returned false on a partial restore but left the index half-populated → now clears on failure so "false ⇒ cold" is honest.
  2. Persistence was never wired (no storage) → re-embedded every session and the realm-fix was dead in prod → now wired via IndexedDB.
  3. Toggling the flag rebuilt surfacereset the active thread mid-conversation → now decoupled via a ref.
    Plus a realm-robustness fix in brain/persist.ts: a plain instanceof Uint8Array mangles bytes across the dynamic-import / IndexedDB structured-clone boundary; the Symbol.toStringTag brand holds.

Verification

  • End-to-end in the real browser: warm → hybrid hit (source: "hybrid"); IndexedDB persist → restore (no re-embed) → query found the node. The cross-realm persist fix exercised under real production conditions.
  • 17 unit tests (vector tier lazy/fallback/persist + the persist clear-on-failure regression + graph retriever); tsc clean for @xnetjs/brain + xnet-web; eslint + prettier clean; fallow audit"✓ No issues in 10 changed files."

Justified defers (documented in the 0211 doc; none block the core)

  • Managed /ai/embed route — the server-side embedding upgrade path; dead infra until demand, so it follows demand.
  • data-bridge localityblocked: apps/web never instantiates a remoteNodeQueryClient, so there's no remote read path to route to.
  • WorkingSetPrewarm planner scores — marginal until per-node frequency/pinned signals are tracked at boot (it already ranks by recency).

🤖 Generated with Claude Code

…cks off)

Wakes the dormant @xnetjs/vectors engine behind the createGraphContextRetriever
seam, making the *semantic* half of the AI second brain live in the assistant.

- ai-vector-search.ts: createVectorEntrySearch — opt-in, lazy. The heavy @xenova
  model + usearch load via a dynamic import only on the first search after opt-in
  (zero boot/bundle cost when off, the 0204 constraint). Once warm it RRF-fuses
  vector + keyword; until warm and on ANY failure it falls back to keyword, so
  enabling it can only match or improve results, never break them.
- ai-vector-storage.ts: IndexedDB BlobStore so the index restores across sessions
  instead of re-embedding the graph each time.
- AiChatPanel: opt-in toggle (off by default); the live flag is read via a ref so
  toggling never tears down the AI runtime mid-conversation.
- brain/persist.ts: realm-robust Uint8Array check (Symbol.toStringTag) — a plain
  instanceof mangles bytes across the dynamic-import / IndexedDB structured-clone
  boundary; and clear-on-failed-restore so "false ⇒ cold" truly means a clean
  slate. (Both surfaced by an adversarial review.)

Verified end-to-end in-browser (warm → hybrid hit; IndexedDB persist → restore →
found). 17 tests. Flips 0211 to [x]: the full hybrid GraphRAG (vector + keyword +
graph-walk, budgeted, with memory + JIT expand) is now live. Remaining items
(managed /ai/embed, data-bridge locality, WorkingSetPrewarm) are justified defers
documented in the exploration.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@crs48
crs48 temporarily deployed to pr-236 June 22, 2026 14:58 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

🖼️ UI changes in this PR

No visual differences detected in the changed UI.

CI run

github-actions Bot added a commit that referenced this pull request Jun 22, 2026
The production vite/rollup build follows the dynamic import('@xnetjs/vectors')
into usearch, a native Node HNSW addon that imports node:fs / node-gyp-build and
can't bundle for the browser ("existsSync is not exported by
__vite-browser-external"). @xnetjs/vectors already falls back to a pure-JS
LinearVectorIndex when usearch is absent — which is what runs in the browser — so
mark usearch external like the other optional dynamically-imported native deps.
The dev server tolerated it; only the production build (typecheck job) bundles
dynamic-import targets. @xenova/transformers bundles fine as a lazy chunk.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@crs48
crs48 temporarily deployed to pr-236 June 22, 2026 15:07 — with GitHub Actions Inactive
github-actions Bot added a commit that referenced this pull request Jun 22, 2026
@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Preview removed for PR #236.

github-actions Bot added a commit that referenced this pull request Jun 22, 2026
@crs48
crs48 merged commit 9ece498 into main Jun 22, 2026
14 checks passed
@crs48
crs48 deleted the claude/ai-semantic-tier branch June 22, 2026 15:13
github-actions Bot added a commit that referenced this pull request Jun 22, 2026
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