Closes the relevance gap exposed by ADR-077: cosine-only neural_patterns
search was returning plausible-but-off-topic results because the bridge ONNX
bi-encoder gets distracted on small corpora by IDF-cheap shared tokens.
Three changes, one release:
1) Hybrid retrieval (src/memory/hybrid-retrieval.ts) — BM25 (k1=1.5,b=0.75)
+ cosine + MMR diversity (λ=0.5). Pure functions, no deps, 21 unit tests.
Wired into neural_patterns search via {mode:'hybrid'|'cosine', alpha,
mmrLambda, limit}. Cosine path preserved for A/B.
2) Pattern.content persistence — adds source text (cap 4096 chars) to the
neural store so BM25 has tokens to score against. Backwards compatible:
pre-3.10.18 patterns fall back to `name`.
3) Outcome signal in pretrain harvester — detects reverted (Revert "<X>"
pattern) and hotfixed (≥50% file overlap with later fix commit) commits,
surfacing the verdict mix in summary + recording original outcome in
trajectory metadata.
Measured (N=385, 10 queries, this checkout):
| Metric | Cosine | Hybrid | Δ |
|-----------------------|-------:|-------:|--------:|
| Top-1 hit rate | 0% | 50% | +50pp |
| Top-3 hit rate | 0% | 70% | +70pp |
| MRR@3 | 0.000 | 0.583 | +0.583 |
| Top-1 diversity | 100% | 80% | -20pp |
| Avg query latency | 28.7ms | 40.6ms | +11.9ms |
Cosine was returning 0% relevant top-3 results — finding "something" but
never the right thing. Hybrid lands relevant top-1 50% / top-3 70% with a
12 ms latency cost.
Co-Authored-By: RuFlo <ruv@ruv.net>
Ships a deterministic one-shot harvester so a fresh ruflo install can
bootstrap its self-learning system from the repo's own GitHub history
(git commits + gh issues) instead of starting empty.
Each item flows through the same code paths real-time learning uses —
distillAndSerialise (ADR-076) → recordTrajectory (ADR-074) → neural
store seed. Closes the ADR-075 consistency note "globalStats moved but
neural store stayed empty" by writing to both stores from the same script.
Measured (this checkout):
• 80/80 trajectories trained from 50 commits + 30 issues
• +95 trajectoriesRecorded, +85 patternsLearned, +80 neuralPatternCount
• 3.36 ms avg per trajectory
• 100% retrieval match rate across 10 sample queries
• 7.67 ms avg query latency at N=95
Adds:
- scripts/pretrain-from-github.mjs (harvester, env-configurable)
- scripts/benchmark-pretrained-retrieval.mjs (after-pretrain validator)
- __tests__/pretrain-from-github.test.ts (CI guard, embedded fixture,
no git/gh shell-outs — auto-picked-up by v3-ci.yml line 610)
- v3/docs/adr/ADR-077-pretrain-from-history.md (decision + measured
proof + honest limits)
- v3/docs/learning/self-learning-usage.md (copy-paste guide for all
three learning paths plus this pretrain flow)
Co-Authored-By: RuFlo <ruv@ruv.net>