Skip to main content
QUICK REVIEW

[Paper Review] Retrieval augmented text-to-SQL generation for epidemiological question answering using electronic health records

Angelo Ziletti, Leonardo D'Ambrosi|arXiv (Cornell University)|Mar 14, 2024
Topic ModelingComputer Science3 citations
TL;DR

This paper presents a retrieval-augmented generation (RAG)-enhanced text-to-SQL framework for epidemiological question answering over electronic health records (EHR) and claims data using the OMOP Common Data Model. By integrating medical coding and RAG with domain-specific, manually curated question-SQL pairs, the approach significantly improves SQL generation accuracy and executability over standard prompting, especially with large language models like GPT-4 Turbo and Mistral-m.

ABSTRACT

Electronic health records (EHR) and claims data are rich sources of real-world data that reflect patient health status and healthcare utilization. Querying these databases to answer epidemiological questions is challenging due to the intricacy of medical terminology and the need for complex SQL queries. Here, we introduce an end-to-end methodology that combines text-to-SQL generation with retrieval augmented generation (RAG) to answer epidemiological questions using EHR and claims data. We show that our approach, which integrates a medical coding step into the text-to-SQL process, significantly improves the performance over simple prompting. Our findings indicate that although current language models are not yet sufficiently accurate for unsupervised use, RAG offers a promising direction for improving their capabilities, as shown in a realistic industry setting.

Motivation & Objective

  • Address the challenge of answering complex epidemiological questions in real-world data (RWD) databases, which require precise SQL queries and deep understanding of clinical terminology.
  • Overcome limitations of standard prompting in text-to-SQL generation for EHR data, where current LLMs lack sufficient accuracy for unsupervised use.
  • Develop a scalable, end-to-end methodology that integrates medical coding and retrieval-augmented generation (RAG) to improve semantic understanding and query accuracy.
  • Create and release a high-quality, domain-specific dataset of 306 manually annotated question-SQL pairs aligned with the OMOP-CDM for reproducible research in biomedical text-to-SQL.
  • Demonstrate that RAG significantly enhances performance across multiple top-tier LLMs, even in data-scarce, industry-relevant settings.

Proposed method

  • Employ a two-stage LLM prompting pipeline: first, generate a SQL query with placeholders for medical entities (e.g., [condition@disphagia]), then map these to standardized clinical ontology terms using a medical coding step.
  • Use the proposed dataset of question-SQL pairs as an external knowledge base for retrieval-augmented generation (RAG), retrieving relevant examples to condition the LLM’s SQL generation.
  • Integrate retrieved examples into the prompt context to improve few-shot generalization, with retrieval based on semantic similarity to the input question.
  • Execute the generated, ontology-mapped SQL queries on an OMOP-CDM-compliant database to retrieve real-world data, enabling downstream answer generation via additional LLM prompting.
  • Leverage the Observational Medical Outcomes Partnership Common Data Model (OMOP-CDM) to ensure interoperability and standardization across diverse EHR and claims databases.
  • Evaluate performance using both execution accuracy (correctness of query output) and exact match accuracy, comparing RAG with static prompting and zero-shot baselines.
Figure 1: From a question in natural language to an answer in natural language using electronic health record or claims databases: end-to-end workflow.
Figure 1: From a question in natural language to an answer in natural language using electronic health record or claims databases: end-to-end workflow.

Experimental results

Research questions

  • RQ1Can retrieval-augmented generation (RAG) significantly improve the accuracy and executability of text-to-SQL generation for epidemiological questions in EHR and claims data compared to standard prompting?
  • RQ2How does integrating a medical coding step—mapping natural language medical entities to standardized ontology terms—impact the performance of text-to-SQL models in clinical data querying?
  • RQ3To what extent does the inclusion of relevant, semantically retrieved examples from a domain-specific dataset improve few-shot generalization in low-resource biomedical text-to-SQL scenarios?
  • RQ4How do different large language models (LLMs), including proprietary (e.g., GPT-4 Turbo) and open-source (e.g., Mistral-m, Mixtral) models, perform under RAG versus prompting baselines in this biomedical setting?
  • RQ5What is the optimal amount of retrieved context (e.g., top-1, top-5) for RAG in this task, and does adding more examples lead to diminishing returns or performance degradation?

Key findings

  • RAG significantly improves both execution accuracy and exact match accuracy across all evaluated LLMs compared to static prompting, with the largest gains observed in GPT-4 Turbo and Mistral-m.
  • GPT-4 Turbo achieves the highest overall performance, outperforming GPT-3.5 Turbo and other models, with a 25.6% execution accuracy improvement over prompting when using RAG-top5.
  • The inclusion of even a single relevant example (RAG-top1) leads to substantial performance gains, but adding more examples (RAG-top5) yields diminishing returns, with some models showing slight performance decline.
  • Mistral-m and GPT-4 Turbo show marked improvements with RAG, suggesting stronger few-shot learning capabilities in complex biomedical contexts compared to Claude 2.1 and GeminiPro.
  • The RAG-oracle scenario (where the correct SQL is provided as context) reveals that GPT-3.5 Turbo outperforms GPT-4 Turbo in exact copying tasks, indicating that GPT-4 Turbo’s deliberative behavior can hinder tasks requiring precise replication.
  • The dataset of 306 manually curated, OMOP-CDM-compliant question-SQL pairs exhibits high complexity, with 53 queries requiring more than two levels of nesting and an average of 6.4 logical conditions per query.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.