feat: auto-link entity mentions for orphan reduction#1378
Open
garrytan-agents wants to merge 3 commits into
Open
feat: auto-link entity mentions for orphan reduction#1378garrytan-agents wants to merge 3 commits into
garrytan-agents wants to merge 3 commits into
Conversation
The judgeSignificance trimming (slice at 4000 chars) could split a UTF-16 surrogate pair when an emoji sits exactly at the boundary, producing a lone high surrogate that Anthropic's JSON parser rejects with 'no low surrogate in string'. Add safeSliceEnd() helper that backs up by one char when the cut lands between a high and low surrogate. Apply to: - judgeSignificance transcript trimming (the direct cause) - findBoundary hard-split fallback (defense-in-depth) Fixes: dream cycle SYNTH_PHASE_FAIL on 2026-05-24 caused by 🤖 emoji at pos 3999 in telegram/2026-05-20-topic-1-topic-1.md
Add proposal for automatic entity mention linking to reduce orphan pages. In a 165K-page production brain, 88% of pages are orphans because link extraction only finds explicit markdown links, not text mentions. Proposes a link-by-mention pass in the dream/extract cycle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposal: Auto-Link Entity Mentions (Orphan Reduction)
Problem
In a production brain with 165K+ pages, approximately 88% of pages are orphans — they have zero inbound links. This happens because the current link extraction only recognizes explicit markdown links (
[Name](path)). When a page mentions an entity by name in body text (e.g., "we discussed Acme Corp's growth trajectory"), no link is created.This means the vast majority of a brain's knowledge graph is disconnected, making it impossible to traverse relationships, find related content, or build meaningful entity profiles through link analysis.
Scale of Impact
Proposed Solution
Add a
link-by-mentionpass in the dream/extract cycle that createsmentionslinks from text references to known entities.How It Works
mentionslinks from the mentioning page to the mentioned entity page, with deduplication to avoid duplicatesgbrain config set auto_link_mentions trueCLI Interface
Implementation Notes
--batch-sizeand--sinceflagsAgent Onboarding
Doctor Detection
gbrain doctorshould detect orphan ratio >50% and surface a recommendation:Fresh Install
On fresh install, the setup wizard should ask:
Migration Prompt (v0.41+)
Add a one-time migration that runs after upgrade:
The migration records completion in the
kvtable so it doesn't prompt again.Evidence
This proposal is based on production data from a 165K-page brain where orphan pages accumulated over months of operation. The operator discovered the issue only after running
gbrain doctor— by then, 146K pages had no connections despite being rich with entity references in their body text.Risks & Mitigations
--sinceflag for incremental runs