Skip to content

Commit 0742e5b

Browse files
committed
feat: Phase 3 Complete - Learning & Post-Processing Migration
Phase 3.1: Abstract Learning Pipeline - Created stillme_core/learning/base.py with LearningPipeline, LearningFetcher interfaces - LearningResult dataclass for cycle results Phase 3.2: Learning Components Migration - Migrated content_curator.py → stillme_core/learning/curator.py - Migrated learning_scheduler.py → stillme_core/learning/scheduler.py - Created stillme_core/learning/fetchers/ with 4 fetchers (RSS, arXiv, CrossRef, Wikipedia) - Updated backend/services/learning_scheduler.py to use stillme_core components - Integrated unified metrics into learning scheduler Phase 3.3: Abstract Post-Processing - Created stillme_core/postprocessing/base.py with PostProcessor interface - PostProcessingResult dataclass Phase 3.4: Post-Processing Migration - Migrated all 7 post-processing components to stillme_core/postprocessing/ - Updated exports in __init__.py files - Created backward compatibility adapters Step 2.8: Learning Metrics Integration - Integrated unified metrics into learning scheduler - Records cycle_number, entries_fetched, entries_added, entries_filtered, sources, duration, errors Backward Compatibility: - backend/services/learning_scheduler.py uses stillme_core components - backend/services/content_curator.py forwards from stillme_core - backend/postprocessing/__init__.py forwards from stillme_core - All existing imports continue to work All imports tested and working. No breaking changes.
1 parent 2e71349 commit 0742e5b

24 files changed

Lines changed: 4491 additions & 526 deletions
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
=== CRITICAL: COPY EXACT TEXT BELOW - DO NOT MODIFY OR INTERPRET ===
2+
3+
Create a professional flowchart diagram with EXACT text as specified below.
4+
5+
=== TITLE ===
6+
"StillMe Validation Chain: Multi-Layer Hallucination Reduction"
7+
Subtitle: "12+ Validators | Validation Pass Rate 93.9% | Zero Hallucination in Custom Tests"
8+
9+
=== START ===
10+
Grey box: "Start: RAG Response"
11+
Arrow down
12+
13+
=== MAIN VALIDATION BLOCK ===
14+
Grey container: "StillMe Validation Chain (12+ Validators)"
15+
16+
LEFT COLUMN - Core Validators (GREEN boxes, exact text):
17+
18+
1. Box text:
19+
"LanguageValidator"
20+
"Check language match"
21+
22+
2. Box text:
23+
"CitationRequired"
24+
"Ensure citations are present"
25+
26+
3. Box text:
27+
"CitationRelevance"
28+
"Validate citation quality"
29+
30+
4. Box text:
31+
"NumericUnitsBasic"
32+
"Validate numeric/units claims"
33+
34+
5. Box text:
35+
"ConfidenceValidator"
36+
"Detect when to express uncertainty"
37+
38+
6. Box text:
39+
"FactualHallucinationValidator"
40+
"Detect factual errors"
41+
42+
7. Box text:
43+
"ReligiousChoiceValidator"
44+
"Reject religion choice in responses"
45+
46+
RIGHT COLUMN - Conditional Validators (GREEN boxes, exact text):
47+
48+
8. Box text:
49+
"EvidenceOverlap"
50+
"Check content matches context"
51+
"(Only when has context)"
52+
53+
9. Box text:
54+
"SourceConsensusValidator"
55+
"Detect contradictions between sources"
56+
"(Only when has 2+ sources)"
57+
58+
10. Box text:
59+
"EgoNeutralityValidator"
60+
"Catch 'Hallucination of Experience'"
61+
"(Only when has context)"
62+
63+
11. Box text:
64+
"IdentityCheckValidator"
65+
"Prevent anthropomorphism"
66+
"(If enabled)"
67+
68+
12. Box text:
69+
"PhilosophicalDepthValidator"
70+
"Validate philosophical depth"
71+
"(Only for philosophical questions)"
72+
73+
13. Box text:
74+
"EthicsAdapter"
75+
"Ethical content filtering"
76+
77+
=== ARROWS ===
78+
Connect validators with arrows as shown in flow.
79+
80+
=== DECISION POINT 1 ===
81+
YELLOW diamond: "All Validations Passed?"
82+
83+
IF YES → RIGHT arrow to:
84+
GREEN box: "Final Response with Citations + Transparency Metadata"
85+
Inside box (3 lines):
86+
- "93.9% Validation Pass Rate"
87+
- "Zero Hallucination in Custom Tests"
88+
- "91.1% Citation Rate (full) / 100% (subset)"
89+
90+
IF NO → DOWN arrow to:
91+
92+
=== DECISION POINT 2 ===
93+
YELLOW diamond: "Critical Failure?"
94+
95+
IF YES → RIGHT arrow to:
96+
RED box: "Fallback Handler"
97+
Inside box (2 lines):
98+
- "Epistemic Fallback Response"
99+
- "Honest 'I don't know' answer"
100+
101+
IF NO → DOWN arrow to:
102+
ORANGE box: "Response with Warning"
103+
Inside box (2 lines):
104+
- "Uncertainty + Validator Flags"
105+
- "Non-critical warnings"
106+
107+
=== SPELLING CHECKLIST - VERIFY EVERY WORD ===
108+
✓ "LanguageValidator" (not "Language Validator" or "LanguageValidator")
109+
✓ "CitationRequired" (not "Citation Required" or "CitationRequire")
110+
✓ "CitationRelevance" (not "CitationReletance" or "Citation Relevance")
111+
✓ "NumericUnitsBasic" (not "NumericUnits" or "Numeric Units Basic")
112+
✓ "ConfidenceValidator" (not "Confidence Validator" or "Facfdence Validator")
113+
✓ "FactualHallucinationValidator" (not "FactualHallucination" or "Reject HalluchationValidator" or "Halluchation")
114+
✓ "ReligiousChoiceValidator" (not "Religious Choice Validator")
115+
✓ "EvidenceOverlap" (not "Evidence Overlap" or "EvidenceOverlapValidator")
116+
✓ "SourceConsensusValidator" (not "SourceConsneusValidator" or "Source Consensus Validator")
117+
✓ "EgoNeutralityValidator" (not "EgoNeutrality" or "Ego Neutrality Validator")
118+
✓ "IdentityCheckValidator" (not "IdentityCheriity Validator" or "Identity Check Validator")
119+
✓ "PhilosophicalDepthValidator" (not "PhilospocicalDepth Validator" or "Philosophical Depth Validator")
120+
✓ "EthicsAdapter" (not "EthicsAdapter" or "Ethics oment filterkng")
121+
122+
✓ "anthropomorphism" (not "antrhoporrgrism" or "anthropophism")
123+
✓ "hallucination" (not "hailucination" or "Halluccination" or "Halluchation" or "Hallucation")
124+
✓ "uncertainty" (not "uncertianty" or "Uncertimity")
125+
✓ "Epistemic" (not "Epistettic")
126+
✓ "sources" (not "sontext" or "sourtest")
127+
✓ "philosophical" (not "phliosocnical")
128+
✓ "YES" (not "YÓ")
129+
✓ "NO" (not "NÓ")
130+
✓ "are present" (not "are presnt" or "are ptiee" or "arepresent")
131+
✓ "matches" (not "matthes")
132+
✓ "content" (not "conten" or "contet")
133+
134+
=== EXACT PHRASES TO USE ===
135+
- "Check language match" (not "language are presnt")
136+
- "Ensure citations are present" (not "Ensure citations are ptiee")
137+
- "Validate citation quality" (not "validates numeric/units claims" - that's for NumericUnitsBasic)
138+
- "Validate numeric/units claims" (for NumericUnitsBasic only)
139+
- "Detect when to express uncertainty" (not "uncertianty")
140+
- "Detect factual errors" (not "Detect factual erros")
141+
- "Catch 'Hallucination of Experience'" (not "Hallucation" or "Halluchation")
142+
- "Prevent anthropomorphism" (not "antrhoporrgrism")
143+
- "Detect contradictions between sources" (not "between sontext" or "sourtest")
144+
- "Check content matches context" (not "Vallect content matthes context")
145+
- "Validate philosophical depth" (not "phliosocnical")
146+
- "Ethical content filtering" (not "Ethics oment filterkng")
147+
148+
=== FINAL VERIFICATION ===
149+
Before generating, check:
150+
1. All validator names are EXACTLY as listed above
151+
2. All descriptions use EXACT phrases above
152+
3. NO typos in: hallucination, anthropomorphism, uncertainty, epistemic, philosophical, sources, matches, content
153+
4. Decision points say "YES" and "NO" (not "YÓ" or "NÓ")
154+
5. All percentages are correct: 93.9%, 91.1%, 100%
155+
6. "12+ Validators" (not "11" or "12 Validators")
156+
157+
=== DESIGN ===
158+
- Professional, clean flowchart
159+
- Clear top-to-bottom flow
160+
- Color coding: GREY (start/container), GREEN (validators/success), YELLOW (decisions), RED (failures), ORANGE (warnings)
161+
- Arrows show flow direction clearly
162+
- Text is readable and properly spaced
163+

arxiv/main_2.pdf

231 KB
Binary file not shown.

backend/postprocessing/__init__.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
"""
22
Post-processing modules for StillMe output normalization and quality enforcement
3+
4+
⚠️ MIGRATION NOTE: This module is being migrated to stillme_core.postprocessing.
5+
During migration, imports are forwarded from stillme_core.postprocessing for backward compatibility.
36
"""
47

5-
from backend.postprocessing.style_sanitizer import StyleSanitizer
6-
from backend.postprocessing.quality_evaluator import QualityEvaluator
7-
from backend.postprocessing.rewrite_llm import RewriteLLM
8-
from backend.postprocessing.optimizer import PostProcessingOptimizer
8+
# During migration: Forward imports from stillme_core.postprocessing
9+
try:
10+
from stillme_core.postprocessing import (
11+
PostProcessor,
12+
PostProcessingResult,
13+
QualityEvaluator,
14+
StyleSanitizer,
15+
RewriteLLM,
16+
PostProcessingOptimizer,
17+
)
18+
except ImportError:
19+
# Fallback to local imports if stillme_core is not available yet
20+
from .style_sanitizer import StyleSanitizer
21+
from .quality_evaluator import QualityEvaluator
22+
from .rewrite_llm import RewriteLLM
23+
from .optimizer import PostProcessingOptimizer
924

10-
__all__ = ['StyleSanitizer', 'QualityEvaluator', 'RewriteLLM', 'PostProcessingOptimizer']
25+
__all__ = [
26+
'PostProcessor',
27+
'PostProcessingResult',
28+
'StyleSanitizer',
29+
'QualityEvaluator',
30+
'RewriteLLM',
31+
'PostProcessingOptimizer'
32+
]
1133

backend/services/content_curator.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@
33
Prioritizes and optimizes learning content based on quality and effectiveness
44
Includes Pre-Filter mechanism to reduce costs by filtering before embedding
55
Now includes ReviewAdapter for simulated peer review evaluation
6+
7+
⚠️ MIGRATION NOTE: This module is being migrated to stillme_core.learning.curator.
8+
During migration, imports are forwarded from stillme_core.learning.curator for backward compatibility.
69
"""
710

11+
# During migration: Forward imports from stillme_core.learning.curator
12+
try:
13+
from stillme_core.learning.curator import ContentCurator
14+
except ImportError:
15+
# Fallback to local implementation if stillme_core is not available yet
16+
import os
17+
818
from typing import List, Dict, Any, Optional, Tuple
919
import logging
1020
from datetime import datetime

backend/services/learning_scheduler.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
Learning Scheduler Service for StillMe
33
Automatically runs learning cycles every N hours to fetch content and add to RAG
44
CRITICAL: This is a core feature - must always be enabled and running
5+
6+
⚠️ MIGRATION NOTE: This module is being migrated to stillme_core.learning.scheduler.
7+
During migration, this file serves as fallback. New code should use stillme_core.learning.scheduler.
58
"""
69

710
import asyncio
@@ -64,12 +67,12 @@ def __init__(
6467

6568
if source_integration is None:
6669
from backend.services.source_integration import SourceIntegration
67-
from backend.services.content_curator import ContentCurator
70+
from stillme_core.learning.curator import ContentCurator
6871
content_curator = content_curator or ContentCurator()
6972
source_integration = SourceIntegration(content_curator=content_curator)
7073

7174
if content_curator is None:
72-
from backend.services.content_curator import ContentCurator
75+
from stillme_core.learning.curator import ContentCurator
7376
content_curator = ContentCurator()
7477

7578
if rss_fetch_history is None:
@@ -234,6 +237,22 @@ async def run_learning_cycle(self) -> Dict[str, Any]:
234237
except Exception as e:
235238
logger.error(f"❌ Error in learning cycle #{cycle_number}: {e}", exc_info=True)
236239

240+
# Record error in unified metrics
241+
try:
242+
from stillme_core.monitoring import get_metrics_collector, MetricCategory
243+
unified_metrics = get_metrics_collector()
244+
unified_metrics.record_learning_cycle(
245+
cycle_number=cycle_number,
246+
entries_fetched=0,
247+
entries_added=0,
248+
entries_filtered=0,
249+
sources={},
250+
duration_seconds=(datetime.now() - start_time).total_seconds(),
251+
error=str(e)
252+
)
253+
except Exception as metrics_error:
254+
logger.debug(f"Failed to record learning error metrics: {metrics_error}")
255+
237256
# Don't increment cycle count on error
238257
return {
239258
"cycle_number": 0, # 0 indicates error
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
Adapter for LearningScheduler - Backward Compatibility
3+
4+
⚠️ MIGRATION NOTE: LearningScheduler has been migrated to stillme_core.learning.scheduler.
5+
This adapter forwards imports for backward compatibility.
6+
"""
7+
8+
# Forward import from stillme_core
9+
try:
10+
from stillme_core.learning.scheduler import LearningScheduler
11+
except ImportError:
12+
# Fallback to local import if stillme_core is not available
13+
from backend.services.learning_scheduler import LearningScheduler
14+
15+
__all__ = ["LearningScheduler"]
16+

0 commit comments

Comments
 (0)