Introduction
Electronic Health Records (EHRs) are plagued by "note bloat"—a dense accumulation of redundant templates and copy-pasted text. For clinicians and AI systems, extracting specific insights from these records is akin to finding a needle in a haystack. While modern Large Language Models (LLMs) now support "long-context windows" exceeding 128,000 tokens, they often suffer from the "lost-in-the-middle" effect, where accuracy drops when the answer is buried deep within the text. Furthermore, processing massive contexts is computationally expensive and slow. This study investigates whether Retrieval-Augmented Generation (RAG)—selecting only the most relevant snippets—can provide a more efficient and accurate alternative for complex clinical reasoning.
Methods
The researchers developed a RAG pipeline and compared its performance against two baselines: Recent Notes (providing the most recent 3k to 8k tokens) and Long-Context (providing up to 128k tokens of the full record).
As shown in Figure 1, the RAG process involves breaking clinical notes into 128-token chunks and converting them into mathematical vectors using the BGE-en-large-v1.5 embedding model. Relevant chunks are retrieved via cosine similarity to construct an assembled prompt. The study evaluated three models: GPT-4o-mini, o4-mini, and DeepSeek-R1.
Datasets and Tasks
The study utilized a private dataset of 200 inpatient hospitalizations from a US academic hospital system. These records covered entire hospital stays, providing a more comprehensive view than ICU-specific datasets like MIMIC. Three distinct tasks were evaluated:
- Imaging Procedures: Extracting a list of diagnostic tests (e.g., X-rays, CTs).
- Antibiotic Timelines: Tracking the temporal start and stop points of antibiotic administration.
- Diagnosis Generation: Identifying the most significant diagnoses relevant to the hospitalization.
Key Results and Insights
The evaluation revealed that RAG is an efficiency powerhouse, particularly for extractive tasks. For imaging procedures, RAG achieved a 3.75-fold to 5.5-fold performance gain over using an equivalent amount of "recent notes."
The "Recent Notes" Trap
In clinical settings, the most recent note is often prioritized, but it is not always sufficient. RAG consistently outperformed the "recent notes" baseline because it could retrieve "ground truth" information from early in a hospitalization that was never repeated in later documentation.
Task-Dependent Success
RAG excelled in "shallow" extraction and longitudinal tracking. However, for high-level "Diagnosis Generation," performance was relatively consistent across all methods, with F1 scores hovering around 0.35–0.40. This suggests that identifying "key" diagnoses remains a complex reasoning challenge that is less sensitive to the specific retrieval strategy.
Near-Parity with Full Context
Crucially, RAG with just 60 chunks (approximately 8k tokens) performed nearly as well as feeding the model the full 128k tokens. This represents a significant reduction in token usage—and thus cost and latency—without a substantial loss in reasoning quality.
Limitations and Conclusion
The study's primary limitation is the use of a private dataset, which restricts external replication. Additionally, error analysis showed that in 22.4% of cases, the necessary information was missing from the notes entirely (e.g., due to patient transfers). Future research may explore "Agentic RAG," where the LLM dynamically determines what information it needs to retrieve.
Even as LLM context windows expand to millions of tokens, RAG remains a "smarter" way to handle the messy, redundant world of medical records. By curating input to include only the most relevant data, RAG enables smaller, faster models to achieve performance levels comparable to full-context processing.
Summary updated