maint(brain): add orphan node pruning script#92
Open
rajkripal wants to merge 2 commits into
Open
Conversation
Move extractor_state from <data_dir>/extractor_state/<name>.json into an extractor_state table in brain.db so that state lifecycle matches DB lifecycle. Wiping the DB now also resets extractor progress, eliminating silent skip-all-reprocessing on reingest. - ExtractorRegistry.__init__ accepts optional db_path; creates extractor_state table (name TEXT PK, state_json TEXT, updated_at TEXT) - _save_state / _load_state use DB when db_path is set, JSON otherwise - Backwards-compat shim: on first load, if DB row is missing, import from legacy JSON file and migrate into DB - CLI (cmd_ingest) passes db_path to registry - Four new tests: DB persistence, DB lifecycle matches DB wipe, JSON fallback, legacy shim import Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
159 active nodes (4.8%) have no edges in derivation_edges. These accumulate from extraction runs that don't link new nodes to existing ones. Left alone they waste embedding space and dilute retrieval. `scripts/prune_orphans.py` reports orphan count, domain/type breakdown, and 5 sample nodes. Pass `--execute` to set decayed=1 on all orphans. Defaults to dry-run; reads DB path from core.config or falls back to data/graph.db relative to cashew root.
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.
159 active nodes (4.8% of 3,295) have no edges in
derivation_edges.These accumulate from extraction runs that don't link new nodes to
existing ones. Left alone they waste embedding space and dilute retrieval
quality over time.
scripts/prune_orphans.pyqueries for nodes whereidappears inneither
parent_idnorchild_idof any edge and prints a report:total count, breakdown by domain and node_type, and 5 sample nodes.
Run
--executeto setdecayed=1on all orphan nodes (reversible, nota delete). Defaults to
--dry-runif no flag is given. DB path is readfrom
core.config.get_db_path()with a fallback todata/graph.dbrelative to the cashew root.
Current orphan distribution: bunny 96, raj 62, user 1. Top types: fact
43, observation 36, commitment 35, derived 22.