1313
1414import logging
1515import sys
16- from pathlib import Path
1716
1817from cogmem import config
19- from cogmem .common import VAULT
18+ from cogmem .common import VAULT , count_md as _count
2019
2120logging .basicConfig (level = logging .INFO , format = "%(message)s" )
2221log = logging .getLogger ("cogmem.tune" )
2322
24- PENDING_WARN = 15 # pending Layer-A rules above this suggests too-liberal capture
25- RULES_WARN = 200 # Layer-B rules above this suggests dedup is too loose
23+ PENDING_WARN = 15 # pending Layer-A rules above this suggests too-liberal capture
24+ RULES_WARN = 200 # Layer-B rules above this suggests dedup is too loose
2625
2726
2827def tune_thresholds () -> None :
2928 from cogmem import eval as evalmod
29+
3030 data = evalmod .load_eval_set (regen = False )
3131 if not data :
3232 log .info ("No eval set; skipping threshold tuning." )
@@ -41,12 +41,13 @@ def tune_thresholds() -> None:
4141 cfg = config .load ()
4242 cfg ["recall_floor" ], cfg ["recall_gap" ] = best [1 ], best [2 ]
4343 config .save (cfg )
44- log .info ("Tuned: recall_floor=%.2f recall_gap=%.1f (recall@5=%.3f fp=%.3f)" ,
45- best [1 ], best [2 ], best [3 ]["recall_at_k" ], best [3 ]["false_pos_rate" ])
46-
47-
48- def _count (p : Path ) -> int :
49- return len (list (p .glob ("*.md" ))) if p .exists () else 0
44+ log .info (
45+ "Tuned: recall_floor=%.2f recall_gap=%.1f (recall@5=%.3f fp=%.3f)" ,
46+ best [1 ],
47+ best [2 ],
48+ best [3 ]["recall_at_k" ],
49+ best [3 ]["false_pos_rate" ],
50+ )
5051
5152
5253def health () -> None :
@@ -55,12 +56,19 @@ def health() -> None:
5556 quarantine = _count (VAULT / "quarantine" )
5657 log .info ("Health: %d Layer-B rules, %d pending, %d quarantined" , rules , pending , quarantine )
5758 if pending > PENDING_WARN :
58- log .info (" WARN: %d rules pending approval (> %d). The extractor is marking too "
59- "much as Layer-A; run `cogmem review list` to curate, and consider "
60- "tightening the Layer-A bar." , pending , PENDING_WARN )
59+ log .info (
60+ " WARN: %d rules pending approval (> %d). The extractor is marking too "
61+ "much as Layer-A; run `cogmem review list` to curate, and consider "
62+ "tightening the Layer-A bar." ,
63+ pending ,
64+ PENDING_WARN ,
65+ )
6166 if rules > RULES_WARN :
62- log .info (" WARN: %d Layer-B rules (> %d). Consolidation dedup may be too loose." ,
63- rules , RULES_WARN )
67+ log .info (
68+ " WARN: %d Layer-B rules (> %d). Consolidation dedup may be too loose." ,
69+ rules ,
70+ RULES_WARN ,
71+ )
6472 if quarantine :
6573 log .info (" WARN: %d quarantined notes need a look." , quarantine )
6674
0 commit comments