Care operations · Research feature

DR.EHR: Dense Retrieval for Electronic Health Record with Knowledge Injection and Synthetic Data

The study introduces DR.EHR, a dense retrieval model trained on MIMIC-IV discharge summaries using a two-stage pipeline.

Adapted from research by Zhengyun Zhao, Huaiyuan Ying, Yue Zhong and colleagues.

arXiv preprint revision · 2025-07-24 · Attribution & reuse
In this article
Editorial illustration of linked workflow.

Editor’s introduction

The study introduces DR.EHR, a dense retrieval model trained on MIMIC-IV discharge summaries using a two-stage pipeline. The first stage injects medical knowledge from a biomedical knowledge graph, while the second stage uses large language models to generate synthetic training data. The models were evaluated on the CliniQ benchmark, which includes 16.5k patient note chunks and over 1k queries covering diseases, procedures, and drugs. DR.EHR significantly outperforms prior dense retrievers, especially in complex semantic matches like abbreviation resolution and implication. Performance differences are more evident in multi-patient retrieval due to the model’s ability to capture nuanced medical representations. The results demonstrate strong performance across query types and retrieval settings, with the larger 7B-parameter variant showing greater advantage in complex tasks.

Introduction

Electronic Health Records (EHRs) hold significant value in various clinical practices, and EHR retrieval plays a crucial role in enabling physicians to utilize EHRs more efficiently. This step is essential in a wide range of clinical tasks, including patient cohort selection, EHR Question Answering (QA), and patient chart review.

Despite the critical importance of this field, its development has not progressed at a commensurate pace. Most existing EHR retrieval systems, whether in academic research or deployed in real-world hospitals, still rely on exact match methods, which inevitably suffer from the semantic gap issue. A recent EHR retrieval benchmark, CliniQ, which separately evaluates various matching types, quantitatively demonstrates that exact match methods struggle with semantic matches, even when augmented by query expansion using a Knowledge Graph (KG).

Recently, Dense Retrieval (DR), which leverages Pre-trained Language Models (PLMs) to generate dense text representations for retrieval, has garnered increasing research interest. Owing to its inherent ability to capture semantics and large-scale contrastive learning, DR models have the potential to bridge the semantic gap and have exhibited strong zero-shot capabilities. In the context of EHR retrieval, general-domain models such as bge and NV-Embed serve as strong baselines, but they leave significant room for improvement due to insufficient medical knowledge. Biomedical-domain models, including MedCPT and BMRetriever, perform suboptimally despite ample knowledge, likely due to the mismatch between their training corpora and clinical notes. Thus, there is a pressing need for an EHR dense retriever specifically designed for the task with comprehensive medical knowledge.

However, the development of an EHR retriever has been severely limited by the lack of training data. The required query-document relevant pairs were traditionally accessible only through manual annotation. The prohibitive costs of such annotations inevitably constrain the dataset scale to only dozens of queries, and the resulting models perform barely on par with BM25. There have been attempts to generate large-scale relevance judgments automatically using string match algorithms or Large Language Models (LLMs). The increase in dataset scale leads to significant improvements in model performance. Yet, the queries used in these works are still provided by human experts or fixed vocabularies, limiting the scale and diversity of the training data. Consequently, the models lack generalizability and are only effective for specific diseases or even particular queries.

We train two variants of DR.EHR, with 110M and 7B parameters, respectively, using contrastive learning with in-batch negatives. On CliniQ, DR.EHR-small significantly outperforms all existing dense retrievers including 7B models, while our 7B variant demonstrates further improvement, achieving state-of-the-art results on the benchmark. Detailed analysis demonstrates that the superiority of DR.EHR is substantial and consistent across different match types and query types. Specifically, it achieves near-perfect performance on string matching and exhibits notable improvements on the most challenging semantic matching, such as implication and abbreviation matching. Through extensive ablation studies, we validate the effectiveness of each component in the training pipeline, further substantiating the model’s enhanced medical knowledge. Though our models are trained exclusively on single-entity queries, they demonstrate strong generalizability over natural language questions including complex ones containing multiple entities.

EHR retrieval

Most EHR retrieval methods rely on exact matches and heavily leverage biomedical KGs. One popular approach to utilizing KGs for EHR retrieval is to identify medical entities in the EHRs and then match these entities with user queries. Other systems use KGs for query expansion. By incorporating synonyms, abbreviations, and related concepts of user queries, these methods can significantly improve the recall rate. However, these methods are limited to exact matching and fixed vocabularies, and therefore struggle to process complex EHRs.

Constrained by the shortage of training data, only a limited number of studies have explored the application of supervised learning and language models in this field. A cited study employed string matching to annotate the training data on imaging reports, and trained a dense retriever based on SentenceBERT. Despite its superiority on the leave-out test set, only hundreds of queries were incorporated, all focused on searching for diseases and anatomical findings in imaging reports. Recently, trained the Onco-Retriever series using a private dataset and annotations based on GPT-3.5, with model parameter sizes of 500M and 2B. On the manually annotated test set, Onco-Retriever outperformed the properitary model developed by OpenAI and SFR-Embedding-Mistral. Yet, they only used 13 queries related to oncology, severely limiting the model’s range of application. Clearly, there is a lack of an EHR retriever that can effectively address the semantic match challenge and be applied to a wide range of queries.

Knowledge injection

Knowledge injection has been widely adopted as an effective approach to enriching the models’ knowledge in the biomedical domain, primarily through KGs. Knowledge injection can be performed either during the pre-training phase or during fine-tuning for downstream tasks. utilized UMLS, the most widely used biomedical KG, and introduced UmlsBERT. By enhancing the model with semantic types of the entities and an additional prediction task for related entities, UmlsBERT demonstrated improvements across a variety of clinical tasks. Others focus on obtaining better entity representations via knowledge injection and language models. CODER employed contrastive learning on terms and relation triplets from UMLS to improve term normalization, significantly outperforming existing medical embeddings. Similarly, introduced SapBERT, which used metric learning to cluster synonyms and achieved state-of-the-art results in medical entity linking tasks.

Knowledge injection has also been applied to dense retrieval. fed an additional entity embedding sequence into the BERT model and used an entity similarity loss to inject knowledge into the model. The resulting model, ELK, outperformed general domain retrievers in zero-shot biomedical retrieval tasks by a large margin.

Synthetic data for retrieval

Synthesizing data for retrieval may be traced back to Doc2Query, which was further expanded by. The idea behind these methods was to generate pseudo queries for documents as document expansion. With the rapid development of dense retrieval, training data soon became a scare resource, and research on synthetic data for retrieval turned to generate relevant queries from documents for model training. utilized the FLAN model to generate pseudo queries for each of the BEIR datasets. leveraged proprietary LLMs to generate diverse synthetic data across hundreds of thousands of tasks and 93 languages. In the biomedical domain, also relied on proprietary LLMs and generated synthetic data for biomedicine. So far, there has been no attempt to apply synthetic data for EHR retrieval.

Stage I: Knowledge injection pre-training

In the first stage, we aim to enrich the model’s medical knowledge through contrastive learning. For each note chunk used as an anchor, we first identify all entity mentions from it that are indexed in BIOS, the largest biomedical KG to date11 1 We also tried UMLS, which yielded suboptimal results., as the initial positive sample set. We only consider entities of specific semantic types to minimize noise included in the training data. The list of incorporated semantic types can be found in Appendix A. Then, to further enhance the model’s abilities to identify abbreviations, we prompt Llama-3.1-8B-Instruct to perform abbreviation reduction, and include the full names of the abbreviations appearing in the note as additional positive samples. We conduct several cleaning steps to remove any noise generated by LLM and to ensure that the cleaned full names appear in BIOS. The prompt used for abbreviation reduction and the detailed cleaning process are described in Appendix B.

Finally, as the core step to inject knowledge from the KG, we look up each positive entity in BIOS and incorporate their synonyms, hypernyms (“is a” relationship), and related entities (other relationships such as “may treat” and “may cause”, full list in Appendix A) into the positive sample set. We do not include hyponyms (“reverse is a” relationship) since the information contained in the note is insufficient to deduce the hyponyms, and they will not be considered relevant in the downstream retrieval task.

Stage II: Synthetic data fine-tuning

In the second stage, we aim to fine-tune the model to optimize for the downstream EHR retrieval task using synthetic data. Following CliniQ, we also focus on the task of entity retrieval, and consider three types of query entities: diseases, clinical procedures, and drugs. We use Llama-3.1-8B-Instruct to generate various types of entities separately and combine them as the positive samples. For better semantic matching capabilities, we prompt the LLM to generate entities that are either explicitly mentioned in or can be implicitly inferred from each note chunk. The prompts used are provided in Appendix C.

To understand the quality of LLM synthetic data, we conduct a manual evaluation of 50 randomly sampled note chunks containing 831 LLM-generated entities. This analysis revealed that 709 entities (85%) are clinically validated by an M.D. candidate, demonstrating reasonable reliability of the data. Most errors we identify are irrelevant medical entities with no explicit patterns.

Model training

We train two models of different sizes: DR.EHR-small, a BERT-based encoder with 110M parameters, initialized from bge-base-en-v1.5; and DR.EHR-large, a 7B decoder using the Mistral architecture, initialized from NV-Embed-v2. These initialization choices are due to the superior performance of these models within their respective parameter sizes. No middle-sized models are included since they generally perform worse than bge-base.

Model training

In our experiments, the maximum token length is set to 512 for note chunks and 16 for entities. To facilitate batch training, we up-sample or down-sample the positive entities of each chunk to a fixed number. We employ distinct data allocation strategies for the two models across two training stages, due to the different GPU memory requirements of the models and the varying dataset scales for each stage. DR.EHR-large is trained with less data due to the higher GPU memory constraints. The hyperparameters and details in the training process are presented in Appendix D.

Model evaluation

We mainly evaluate our models on CliniQ, the only publicly available EHR retrieval benchmark of large scale. CliniQ is constructed with 1k patient summaries from MIMIC-III, split into 16.5k chunks of 100 words each. It contains over 1k queries of three types: diseases, clinical procedures, and drugs, collected from structured codes in MIMIC and annotated by GPT-4o. It incorporates two retrieval settings: Single-Patient retrieval where models are tasked with ranking the chunks of a single patient note given a query, and Multi-Patient retrieval, where model are required to retrieve relevant chunks from the entire set of 16.5k chunks. On Single-Patient Retrieval, models are evaluated with Mean Reciprocal Rank (MRR), Normalized Discounted Cumulative Gain (NDCG), and Mean Average Precision (MAP). On Multi-Patient Retrieval, models are evaluated with MRR, NDCG at 10, and recall at 100. CliniQ provides additional semantic match assessment by further classifying the relevance judgments into various categories under the Single-Patient Retrieval setting. With this comprehensive benchmark, we are able to assess the performance of DR.EHR under various clinical scenarios.

In addition to CliniQ, which comprises only entity-based queries, we evaluate our models by adapting existing EHR QA datasets into a retrieval framework to demonstrate our models’ generalizability on natural language queries. However, since these datasets are not rigorous retrieval benchmarks that have undergone peer reviews, we only present them as a supplement to our main experiments in Appendix E. To briefly summarize, we employ the Single-Patient Retrieval setting and split the notes into chunks. For each QA dataset question, the models are tasked with ranking the chunk containing the correct answer highest among all chunks from that patient’s note, assessed using MRR.

Main results

The performance difference between the two variants of the DR.EHR models is more pronounced in the Multi-Patient Retrieval setting, likely due to its inherently greater complexity. With its larger parameter size and higher-dimensional embeddings, DR.EHR-large captures more nuanced medical knowledge and produces more discriminative representations. However, this advantage may be less noticeable in the Single-Patient setting, where the task is comparatively simpler with only 16.6 chunks per query to be ranked.

Semantic match assessment

In terms of semantic matches, DR.EHR-small outperforms its initialization model by more than 10% across all categories, with a notable improvement of over 26% in abbreviation matching. These substantial gains underscore the effectiveness of the proposed pipeline. Through extensive knowledge injection and synthesized data tailored for this task, the models have learned to capture deep semantic associations between terms and to represent them effectively in their embeddings. The two proposed models of distinct parameter sizes do not show noticeable difference under the Single-Patient Retrieval setting.

Ablation study

We conduct three ablation studies using DR.EHR-small. First, we ablate the stage I training and present the results in Tables 3 and 4. The results demonstrate that the knowledge injection phase significantly contributes to the final performance of DR.EHR, particularly on Recall@100 for Multi-Patient Retrieval. Detailed analysis of different match types reveals that this contribution is primarily attributed to semantic matches. The knowledge injection phase improves model performance by approxiamately 5% across all semantic match types.

Generalizability assessment

The training pipeline and prior evaluations on CliniQ focus exclusively on single-entity queries. To assess the generalizability of our models, we conduct additional experiments on adapted EHR QA datasets featuring natural language questions, including a dedicated subset comprising exclusively complex, multi-entity queries. The results in Appendix E reveal that DR.EHR maintains substantial advantages over baseline models across most evaluated datasets. This indicates strong generalization capability to unseen query types, even when trained exclusively on entity-based queries.

Conclusion

In this paper, we propose a two-stage training pipeline specifically designed for the task of EHR retrieval. The first stage employs KGs for knowledge injection while the second stage fine-tunes the model for the retrieval task with LLM synthetic data. Using this pipeline, we develop and release DR.EHR, a state-of-the-art EHR retriever available in two model sizes. Extensive experiments demonstrate that DR.EHR significantly outperforms baseline models across various settings, match types, and query types. Notably, our models overcome challenges faced by traditional dense retrievers and exhibit exceptional capabilities in both string matching and semantic matching. Supplementary experiments further verify the models’ generalizability to complex natural language queries.

Limitations

This study has several limitations. First, the evaluation of our model mainly focus on CliniQ, specifically the task of entity retrieval. Due to the lack of other public EHR retrieval benchmarks, we utilize EHR QA datasets to illustrate the generalizability of our models. However, these datasets are not rigorous retrieval benchmarks, and we call for future efforts to construct richer and more diverse public benchmarks. Second, the quality of LLM synthetic data could be improved, as pointed out by our manual inspection. Nevertheless, removing the noises involves differentiating between relevant and irrelevant medical entities and generally requires more advanced LLMs, which is computationally intensive and exceeds our current resource constraints given the enormous scale of our data. Third, while hard negatives are known to significantly enhance model performance, particularly during task-specific fine-tuning, the design of synthetic hard negative data is non-trivial. We leave this challenge for future research.