Retrieval-augmented in-context learning for multimodal large language models in disease classification

Rui Zhang, PhD, Facmi, Famia, Fiahsi, Zaifu Zhan, Shuang Zhou, Xiaoshan Zhou, Yongkang Xiao, Jun Wang, Jiawen Deng, He Zhu, Yu Hou, Rui Zhang · DOI

Introduction

In-context learning (ICL) has emerged as a powerful paradigm for Large Language Models (LLMs), allowing them to perform new tasks by observing a few examples within the prompt. However, Multimodal Large Language Models (MLLMs) face significant challenges in this area, particularly the "context window" bottleneck. Fitting multiple complex medical examples—comprising both high-resolution imagery and detailed clinical notes—into a single prompt often leads to memory issues or a loss of focus by the model.

Statement of Significance summarizing the problem and the proposed RAICL solution.

Furthermore, most existing ICL implementations rely on random example selection. In medical diagnostics, this is suboptimal; a model classifying a lung nodule gains little from seeing an unrelated example of a bone fracture. The challenge lies in dynamically identifying the most relevant historical cases to serve as informative "demonstrations" for a specific patient query.

The RAICL Framework

To address these limitations, the authors propose RAICL (Retrieval-Augmented In-Context Learning), a framework that integrates Retrieval-Augmented Generation (RAG) with ICL. RAICL dynamically selects the most relevant demonstration cases based on the specific characteristics of the input query.

The RAICL framework architecture, illustrating the flow from query embedding to similarity-based ranking and conversational prompting.

The framework operates through four primary stages:

  1. Embedding Generation: Input queries (image and text) are converted into mathematical vectors using specialized encoders like ResNet for images and BERT-based models (e.g., BioBERT, ClinicalBERT) for text.
  2. Similarity-Based Retrieval: The system searches a database of annotated medical cases to find "nearest neighbors" using metrics such as Euclidean distance or Cosine similarity.
  3. Conversational Prompting: Instead of a static list, RAICL constructs a "fake" dialogue. It presents retrieved cases as a series of interactions where a user provides data and an assistant provides the correct diagnosis, effectively teaching the MLLM the required reasoning style and output format.
  4. Inference: The MLLM (e.g., Qwen-2.5-VL, LLaVA, or Gemma) processes the new query, leveraging the highly relevant context provided by the retrieved examples.

Experimental Evaluation

The framework was rigorously tested on two distinct multimodal medical datasets:

  • TCGA (The Cancer Genome Atlas): High-resolution histopathology slides and pathology reports for five cancer types.
  • IU Chest X-ray: Radiographs paired with radiology reports covering various thoracic conditions like pneumonia and cardiomegaly.

Key Findings

  • Modality Sensitivity: The optimal retrieval strategy varies by medical specialty. For pathology (TCGA), text-based similarity (clinical notes) was more effective. In contrast, for radiology (IU Chest X-ray), visual similarity (the X-ray images) provided a stronger retrieval signal.
  • Multimodal Synergy: While text often provides a strong baseline, the highest accuracy was consistently achieved by integrating both image and text modalities, demonstrating their complementary nature.
  • Distance Metrics: Interestingly, Euclidean distance outperformed the industry-standard Cosine similarity in raw accuracy, though Cosine similarity proved better for maintaining performance across rare diseases (Macro-F1).

Results and Impact

RAICL demonstrated substantial performance gains over baseline models without any fine-tuning. On the TCGA dataset, accuracy rose from 0.7854 to 0.8368, with a dramatic increase in Macro-F1 for the Qwen model (from 0.1191 to 0.8454). Similar improvements were observed in the IU Chest X-ray dataset, where accuracy increased from 0.7924 to 0.8658. These results were consistent across different MLLM architectures, highlighting the framework's robustness.

Conclusion and Future Work

The RAICL framework proves that the quality of context is as critical as model architecture in medical AI. By providing a tailored "cheat sheet" of relevant historical cases, RAICL significantly enhances diagnostic accuracy. Future research will focus on optimizing the computational overhead of multi-round prompts and extending the framework to handle 3D medical volumes and time-series data.

Summary updated

Abstract

Objectives: We aim to dynamically retrieve informative demonstrations, enhancing in-context learning in multimodal large language models (MLLMs) for disease classification. Methods: We propose a Retrieval-Augmented In-Context Learning (RAICL) framework, which integrates retrieval-augmented generation (RAG) and in-context learning (ICL) to adaptively select demonstrations with similar disease patterns, enabling more effective ICL in MLLMs. Specifically, RAICL examines embeddings from diverse encoders, including ResNet, BERT, BioBERT, and ClinicalBERT, to retrieve appropriate demonstrations, and constructs conversational prompts optimized for ICL. We evaluated the framework on two real-world multi-modal datasets (TCGA and IU Chest X-ray), assessing its performance across multiple MLLMs (Qwen, Llava, Gemma), embedding strategies, similarity metrics, and varying numbers of demonstrations. Results: RAICL consistently improved classification performance. Accuracy increased from 0.7854 to 0.8368 on TCGA and from 0.7924 to 0.8658 on IU Chest X-ray. Multi-modal inputs outperformed single-modal ones, with text-only inputs being stronger than images alone. The richness of information embedded in each modality will determine which embedding model can be used to get better results. Few-shot experiments showed that increasing the number of retrieved examples further enhanced performance. Across different similarity metrics, Euclidean distance achieved the highest accuracy while cosine similarity yielded better macro-F1 scores. RAICL demonstrated consistent improvements across various MLLMs, confirming its robustness and versatility. Conclusions: RAICL provides an efficient and scalable approach to enhance in-context learning in MLLMs for multimodal disease classification.
BibTeX
@article{fiahsi2026retrieval,
  author = {Rui Zhang, PhD, FACMI, FAMIA, FIAHSI and Zaifu Zhan and Shuang Zhou and Xiaoshan Zhou and Yongkang Xiao and Jun Wang and Jiawen Deng and He Zhu and Yu Hou and Rui Zhang},
  title = {{Retrieval-augmented in-context learning for multimodal large language models in disease classification}},
  journal = {Journal of Biomedical Informatics},
  year = {2026},
  doi = {10.1016/j.jbi.2026.105017},
}
Figure