SM3-Text-to-Query: Synthetic Multi-Model Medical Text-to-Query Benchmark

Sithursan Sivasubramaniam, Cedric Osei-Akoto, Yi Zhang, Kurt Stockinger, Jonathan Fuerst · DOI

Abstract

Electronic health records (EHRs) are stored in various database systems with different database models on heterogeneous storage architectures, such as relational databases, document stores, or graph databases. These different database models have a big impact on query complexity and performance. While this has been a known fact in database research, its implications for the growing number of Text-to-Query systems have surprisingly not been investigated so far. In this paper, we present SM3-Text-to-Query, the first multi-model medical Text-to-Query benchmark based on synthetic patient data from Synthea, following the SNOMED-CT taxonomy—a widely used knowledge graph ontology covering medical terminology. SM3-Text-to-Query provides data representations for relational databases (PostgreSQL), document stores (MongoDB), and graph databases (Neo4j and GraphDB (RDF)), allowing the evaluation across four popular query languages, namely SQL, MQL, Cypher, and SPARQL. We systematically and manually develop 408 template questions, which we augment to construct a benchmark of 10K diverse natural language question/query pairs for these four query languages (40K pairs overall). On our dataset, we evaluate several common in-context-learning (ICL) approaches for a set of representative closed and open-source LLMs. Our evaluation sheds light on the trade-offs between database models and query languages for different ICL strategies and LLMs. Last, SM3-Text-to-Query is easily extendable to additional query languages or real, standard-based patient databases.

Introduction

In the world of Electronic Health Records (EHRs), data is rarely stored in a single format. Depending on the clinical use case, hospitals may utilize relational databases (PostgreSQL), document stores (MongoDB) for flexibility, or graph databases (Neo4j/RDF) to map the intricate relationships between patients, diseases, and treatments.

While "Text-to-SQL" research has advanced rapidly, most existing systems are optimized for relational structures. However, the underlying database model fundamentally changes query complexity—affecting nesting depth, the number of joins, and token length. SM3-Text-to-Query addresses this gap by providing a standardized way to measure how Large Language Models (LLMs) handle these different logical structures when the underlying medical information is identical.

The SM3-Text-to-Query Benchmark

The researchers developed a systematic pipeline to create a "future-proof" benchmark using synthetic patient records from Synthea. To ensure real-world relevance, the data follows the SNOMED-CT taxonomy, a global standard for medical terminology.

Comparison of a single medical question translated into SQL, MongoDB (MQL), Cypher, and SPARQL, highlighting differences in query complexity.

As illustrated in Figure 1, the benchmark provides a "four-way" parallel translation for the same natural language questions. This allows for a direct comparison of how different database paradigms—relational, document, and graph—impact the resulting query structure. For example, a query that is compact in Cypher may become highly nested in MQL or verbose in SPARQL.

Methodology and Evaluation

The benchmark consists of 40,000 natural language/query pairs (10,000 for each of the four languages). The authors evaluated several representative LLMs, including Llama 3, GPT-3.5, and Gemini 1.0 Pro, using various In-Context Learning (ICL) strategies. A key component of their approach was the use of a BM25 retriever to select "few-shot" examples that were linguistically similar to the user's question, which proved essential for the more complex query languages.

Key Insights

The "SQL Bias"

LLMs demonstrate a significant proficiency in SQL compared to other languages. GPT-3.5 reached 88.55% execution accuracy in SQL using similarity-based few-shots. In contrast, without few-shot examples, most models scored <4% on SPARQL. This disparity is largely attributed to the volume of SQL-related training data available compared to more specialized languages like SPARQL or Cypher.

Structural Trade-offs

The study found that the database model itself dictates the difficulty of the translation task:

  • Cypher (Graph): Generally the most compact queries with the fewest tokens.
  • MQL (Document): Involved the most nesting. LLMs struggled more with MQL's nesting than they did with SQL's joins.
  • SPARQL (RDF): The most verbose language, requiring explicit schema and ontology information in the prompt to achieve high accuracy.

The Importance of Retrieval-Augmented Prompting

Using a BM25 retriever to pick few-shot examples boosted performance by over 50 percentage points for SPARQL and MQL. This suggests that for "low-resource" query languages, providing structural context is more important than the model's internal reasoning capabilities alone.

Conclusion

SM3-Text-to-Query reveals that while LLMs are powerful, their effectiveness in medical informatics is heavily dependent on the underlying database architecture. By providing a multi-model benchmark, this research highlights the need for model-specific prompt optimization and better support for non-relational data structures in healthcare AI. Future work will aim to include temporal reasoning and transition from synthetic to real-world clinical datasets.

Summary updated

BibTeX
@inproceedings{sivasubramaniam2024sm,
  author = {Sithursan Sivasubramaniam and Cedric Osei-Akoto and Yi Zhang and Kurt Stockinger and Jonathan Fuerst},
  title = {{SM3-Text-to-Query: Synthetic Multi-Model Medical Text-to-Query Benchmark}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
}
Figure