EEG-MedRAG: Hypergraph RAG for EEG Data
- EEG-MedRAG is a three-layer hypergraph-based retrieval-augmented generation framework that integrates EEG signals, clinical knowledge, and patient histories into a unified relational structure.
- It employs semantic-temporal joint retrieval and causal-chain diagnostic reasoning to enhance EEG interpretation and support data-driven clinical decision-making.
- Benchmark results show significant gains over traditional methods, with improved diagnostic accuracy and validation across multiple neurological disorders and clinical roles.
EEG-MedRAG is a three-layer hypergraph-based retrieval-augmented generation (RAG) framework designed to address the efficient retrieval and semantic interpretation of large-scale, heterogeneous EEG (electroencephalography) data in clinical and neuroscience contexts. By unifying EEG domain knowledge, patient case histories, and extensive EEG repositories into a single traversable n-ary relational hypergraph, EEG-MedRAG enables semantically coherent, temporally informed retrieval and diagnostic reasoning. It further introduces a comprehensive clinical QA benchmark for evaluating generalization and role-specific reasoning across multiple neurological disorders and professional perspectives (Wang et al., 19 Aug 2025).
1. Hierarchical Hypergraph Structure
EEG-MedRAG operationalizes the complete EEG information space as a hypergraph with three disjoint but interconnected layers:
- Knowledge Hypergraph (KGH):
This layer encodes domain knowledge as entities () and hyperedges () representing n-ary clinical relations. Each clinical document is parsed into facts , associating a natural-language relation (hyperedge) with involved entity tuples . The incidence matrix defines the bipartite structure (entities to hyperedges), and all nodes are embedded via a textual encoder .
- Patient Cases Hypergraph (CGH):
Patient cases are modeled as nodes () and multi-attribute hyperedges (0). Each case 1 is represented as a tuple 2 and embedded via 3. Augmented pseudo-cases are included through soft nearest-neighbor inference, creating 4. Incidence matrices are defined analogously to KGH.
- EEG Vector Database (EVD):
Raw EEG segments 5 are transformed via channel-wise Piecewise Aggregate Approximation (PAA) with window size 6:
7
Each EEG segment is thus represented as a fixed-length embedding (nodes 8), absent higher-order hyperedges.
The global hypergraph may be represented either as a high-rank incidence tensor 9 for n-ary relations or as layer-wise incidence matrices. This architecture supports efficient semantic, structural, and temporal traversals.
2. Semantic–Temporal Joint Retrieval
Given a new patient query, consisting of a raw EEG recording 0 and metadata 1 (age, symptoms, history), EEG-MedRAG performs multi-step context retrieval:
- EEG-Level Retrieval:
2 is computed as above. For each stored EEG vector 3, the Dynamic Time Warping (DTW) distance is calculated:
4
The top-5 segments minimizing DTW are retrieved:
6
- Hyperedge-Level (Knowledge) Retrieval:
Query metadata is encoded as 7. For each knowledge hyperedge 8, with embedding 9, cosine similarity is computed:
0
The top-1 hyperedges are selected:
2
- Entity-Level Expansion:
For each retrieved hyperedge, incident entities are collected via 3. Additional hyperedges may be fetched for enhanced context.
- Subgraph Fusion:
The three retrieval sets—EEG similarities (4), knowledge hyperedges (5), and entities (6)—are merged. The context subgraph 7 is computed as:
8
This union defines a connected, clinically meaningful evidence set by closure within one or two hops in the overall hypergraph.
This retrieval process tightly integrates low-level signal similarity, high-level semantic knowledge, and graph connectivity, supporting comprehensive evidence gathering.
3. Causal-Chain Diagnostic Reasoning
Context subgraph 9 forms the prompt for a diagnostic LLM, e.g., GPT-4o-mini. Generation comprises:
- Prompt Assembly:
- A “diagnostic instruction” template 0 (“Based on the following EEG segments, patient history, and medical facts, provide a diagnostic reasoning chain and final recommendation.”)
- Retrieved EEG PAA vectors or their summaries
- Textual descriptions of entities and hyperedges in 1
- The patient’s question 2
- Conditional Generation:
The model samples the output:
3
where 4 denotes the instruction-tuned LLM.
- Supervised Fine-Tuning (optional):
The approach is amenable to chain-of-thought or stepwise reasoning supervision via the loss:
5
where 6 are LLM parameters.
The explicit fusion of retrieved semantic, structural, and time-series evidence enables interpretable, traceable causal-chain diagnostic outputs, in contrast to prior RAG methods lacking domain-specific graph structure or temporal alignment.
4. Cross-Disease, Cross-Role EEG Clinical QA Benchmark
EEG-MedRAG introduces the first large-scale, systematically curated EEG clinical QA dataset spanning both disorder diversity and professional roles:
| EEG Disorder Domain | Clinical Roles | Example Data Sources |
|---|---|---|
| Epilepsy | Doctor, Patient, Nurse, | CHB-MIT, OpenNeuro |
| Depression | Researcher, Hospital Intern | Various OpenNeuro sets |
| Parkinson’s Disease | ||
| Alzheimer’s Disease | ||
| Sleep Deprivation | ||
| Psychiatric Disorders | ||
| mTBI |
- Coverage:
- 7 domains: Epilepsy, Depression, Parkinson’s Disease, Alzheimer’s Disease, Sleep Deprivation, Psychiatric Disorders (e.g., psychosis), Mild Traumatic Brain Injury
- 5 roles: Doctor, Patient, Researcher, Hospital Intern, Nurse
- Data Construction:
- EEG data sourced from CHB-MIT (23 epilepsy patients) and seven OpenNeuro datasets (over 200 subjects).
- Knowledge and QA pairs are derived from clinical guidelines, textbooks, interpretation protocols; totals ~2,500 QA pairs (7 domains × 5 roles × 50–100 questions each).
- Each QA pair undergoes hierarchical retrieval-based automatic generation, followed by validation by two board-certified neurologists.
- Annotation and Release:
Annotated with salient EEG events and labeled factual relations, role-conditioned prompts, and human-validated ground truths; provided in standardized JSON format, split into train/dev/test without cross-subject overlap.
This dataset enables systematic benchmarking of disease-agnostic reasoning and role-awareness within the EEG context (Wang et al., 19 Aug 2025).
5. Empirical Performance and Ablation Analysis
EEG-MedRAG demonstrates quantifiable gains over established baselines in diagnostic accuracy and retrieval:
- Metrics:
- Exact Match (EM): binary correctness
- Token-level F1: overlap between generated and reference responses
- Baselines Compared:
- NaiveGeneration (LLM without retrieval)
- StandardRAG (chunk-based retrieval)
- HyperGraphRAG (binary-relation graph RAG)
- TimeRAG (time-series retrieval, no domain knowledge)
- Key Results (GPT-4o-mini backbone):
- F1:
- NaiveGeneration: 43.35
- StandardRAG: 45.44
- HyperGraphRAG: 48.93
- TimeRAG: 48.21
- EEG-MedRAG: 53.16 (+7.72 vs. StandardRAG)
- EM:
- StandardRAG: 26.19
- EEG-MedRAG: 32.16 (+5.97)
- Domain-specific improvements >10 F1 points (e.g., Alzheimer’s 53.18→68.06)
- Similar performance improvements observed for Deepseek-r1 (+17.23 F1, +9.49 EM) and Gemini-2.5-flash (+5.35 F1).
- Ablation Study:
- Full F1: 53.16
- w/o CL: 49.32 (–3.84)
- w/o IL: 48.52 (–4.64)
- w/o EL: 48.26 (–4.90)
These findings indicate that all major components are essential for high performance, and the multi-layer hypergraph structure is critical for semantic, structural, and temporal integration.
6. Implementation and Public Resources
EEG-MedRAG is released as open-source software with all code and data available at https://github.com/yi9206413-boop/EEG-MedRAG under the MIT license (data: CC-BY 4.0).
- Codebase Organization:
/preprocess: EEG PAA segmentation and embedding/graph_build: Hypergraph (KGH/CGH) construction/retrieval: DTW-based EEG and hyperedge retrieval/generation: Prompt assembly and LLM interfaces/benchmark: Dataset loaders and evaluation scripts
- Dependencies:
Python 3.8+, PyTorch, Transformers, numpy, scipy, dtw-python, networkx, scikit-learn
- Workflow (Quick Start):
- Clone repository and install dependencies
- Download EEG data to
/data - Run EEG embedding script
- Build hypergraphs (KGH/CGH)
- Run retrieval and generation pipeline
This infrastructure provides a standardized and extensible platform for EEG-based, retrieval-augmented clinical reasoning research.
EEG-MedRAG’s principled integration of semantic knowledge, temporal dynamics, and clinical context within a hierarchical hypergraph framework advances the field of EEG interpretation and diagnostic QA, with robust empirical validation across multiple disorders and professional perspectives (Wang et al., 19 Aug 2025).