Skip to content
This repository was archived by the owner on Sep 5, 2026. It is now read-only.

Commit cdafaec

Browse files
committed
refactor: dedupe count_md into common (was defined 2x); drop now-unused imports
1 parent abdac16 commit cdafaec

3 files changed

Lines changed: 29 additions & 21 deletions

File tree

engine/common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,8 @@ def write_note(path: Path, meta: dict, body: str) -> None:
113113
lines.append("---\n")
114114
path.parent.mkdir(parents=True, exist_ok=True)
115115
path.write_text("\n".join(lines) + "\n" + body.strip() + "\n")
116+
117+
118+
def count_md(p: Path) -> int:
119+
"""Number of `.md` notes in a vault directory (0 if it does not exist)."""
120+
return len(list(p.glob("*.md"))) if p.exists() else 0

engine/metrics.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
import logging
1414
import sys
1515
from collections import Counter
16-
from pathlib import Path
1716

18-
from cogmem.common import SOCK_PATH, VAULT, read_note
17+
from cogmem.common import SOCK_PATH, VAULT, count_md as _count, read_note
1918

2019
logging.basicConfig(level=logging.INFO, format="%(message)s")
2120
log = logging.getLogger("cogmem.metrics")
@@ -35,10 +34,6 @@ def scope_tokens(path) -> int:
3534
return chars // 4
3635

3736

38-
def _count(p: Path) -> int:
39-
return len(list(p.glob("*.md"))) if p.exists() else 0
40-
41-
4237
def rule_feedback() -> dict:
4338
helpful = contradicted = recalled = 0
4439
top = []

engine/tune.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313

1414
import logging
1515
import sys
16-
from pathlib import Path
1716

1817
from cogmem import config
19-
from cogmem.common import VAULT
18+
from cogmem.common import VAULT, count_md as _count
2019

2120
logging.basicConfig(level=logging.INFO, format="%(message)s")
2221
log = 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

2827
def 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

5253
def 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

Comments
 (0)