A newer version of the Gradio SDK is available: 6.20.0
EmpathRAG Core Architecture
EmpathRAG Core is a guarded conversational RAG system for emotional/student support navigation. It is not a therapist, diagnostic system, emergency service, or clinical product.
Flow
- Intake: user message, session state, and mode (
studentorhelping_friend). - Hard safety precheck: deterministic safety policy scans the current message.
- Hybrid classifier: lightweight TF-IDF + logistic regression predicts route and safety tier when confidence is sufficient.
- Hard safety override: crisis/imminent rules override ML predictions.
- Resource registry and curated retrieval: filter by route/tier/usage mode before source cards are shown.
- Response planner: validation, reframe, recommended next action, source option, backup option, follow-up question.
- Output guard: catches pure validation, unsafe agreement, dependency language, and ungrounded contact/resource claims.
- UI/eval metadata: route, tier, classifier confidence, retrieval mode, output guard, sources, trajectory.
Four-Mode Ladder
imminent_safety: normal generation blocked; crisis/human handoff only.high_distress: short support, grounding, and urgent support options.support_navigation: practical next step with source-grounded campus route.wellbeing: low-risk coping support plus campus option where useful.
Current Routes
academic_setbackexam_stressaccessibility_adsadvisor_conflictcounseling_navigationbasic_needscare_violence_confidentialpeer_helperloneliness_isolationanxiety_paniclow_moodcrisis_immediategeneral_student_supportout_of_scope
Resource Registry / Service Objects
Minimal resource registry file:
data/curated/service_graph.jsonl
Loader:
src/pipeline/service_graph.py
The current filename is retained for compatibility, but the paper/demo concept is a resource registry of service objects, not a graph algorithm. It only uses verified source URLs from the current corpus. Missing phone numbers, hours, locations, and eligibility rules are marked unknown.
Output Guard
File:
src/pipeline/output_guard.py
Current checks:
- crisis responses must not continue normal academic coaching
- non-crisis responses must include a recommended next action
- pure validation with no redirect is flagged
- dependency-forming language is flagged
- harmful/sycophantic agreement is flagged
- self-degrading compliance is flagged
- ungrounded contact claims are flagged
Demo Backend
The class demo should use:
$env:EMPATHRAG_DEMO_BACKEND='fast'
$env:EMPATHRAG_RETRIEVAL_CORPUS='curated_support'
.\venv\Scripts\python.exe -u demo\app.py
The demo uses EmpathRAG Core in hybrid_ml mode. If local ML router artifacts are missing, it falls back to the deterministic route rules. The full local LLM backend remains experimental because local model loading can stall.
ML Router
Files:
src/pipeline/ml_router.pyeval/prepare_karthik_dataset.pyeval/train_ml_router.pyeval/run_router_eval.py
The current model uses TF-IDF n-grams plus logistic regression. It is intentionally lightweight and auditable. Hard safety checks always override it.
Unified Evaluation
Run:
.\venv\Scripts\python.exe -B eval\run_empathrag_core_eval.py
Current local checkpoint metrics on the 92-row prepared evaluation dataset:
- Rule route accuracy: 0.935
- Hybrid ML route accuracy: 0.978
- Safety tier accuracy: 0.902
- Intercept accuracy: 1.000
- Source organization hit rate: 0.913
- Unsafe generation count: 0