Skip to content
ApaulgithubPublic

About

An automated framework for temporal multimodal medical retrieval augmented generation.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

TM²-RAG: Temporal Multimodal Medical Retrieval-Augmented Generation

MasterHead

Welcome to the TM²-RAG repository. This project implements a comprehensive, multimodal, and time-aware retrieval-augmented generation pipeline tailored for longitudinal clinical data (such as chest X-rays and their corresponding radiology reports).

This guide will walk you through the end-to-end process of running the full TM²-RAG system pipeline, starting from raw data ingestion all the way to interactive inference via our Streamlit application.

This work is accepted at FIRE 2026: 18th meeting of the Forum for Information Retrieval Evaluation. The full paper link will be available soon.

Prerequisites

Before running the pipeline, ensure you have the required datasets available (e.g., MIMIC-CXR) and all necessary Python dependencies installed in your environment. You should configure the data paths in src/config.py appropriately to match your local setup.

Pipeline Execution Steps

The system processes data in a sequence of defined phases. Run the following Python scripts in order from the root of the workspace.

Phase 1: Data Indexing and Filtering

First, we build a master index linking patients, studies, images, and reports, and then filter it down to patients that possess longitudinal (temporal) data.

  1. Phase 1A: Build Master Index Run the master index builder to map out the entire dataset structure.

    python src/data/build_master_index.py
  2. Phase 1B: Filter Temporal Patients Filter the master index to retain only the patients with multiple studies over time.

    python src/data/filter_temporal_patients.py

Phase 2: NLP and Vision Feature Extraction

In this phase, we extract structured sections from the radiology reports, detect temporal language, and process visual features.

  1. Phase 2 (2A, 2B, 2C): Extract All Features This orchestrator script runs report parsing (2A) and temporal change detection (2B) to extract comprehensive NLP features from the reports.
    python src/nlp/extract_all_features.py

Phase 3: Temporal Trajectory Construction

Next, we reconstruct the longitudinal patient timelines by building trajectories, analyzing transitions, and defining dynamic windows.

  1. Phase 3A: Trajectory Builder Construct temporal patient trajectories from their historical studies.

    python src/temporal/trajectory_builder.py
  2. Phase 3B: Transition Analyzer Analyze the transitions and changes between consecutive studies.

    python src/temporal/transition_analyzer.py
  3. Phase 3C: Dynamic Windowing Create dynamic temporal windows for each patient's trajectory to optimize context retrieval.

    python src/temporal/dynamic_window.py

Phase 4: Dense Embeddings Generation

We now embed the reports and temporal trajectories into a dense vector space for semantic retrieval.

  1. Phase 4A: Report Embeddings Generate embeddings for the individual reports.

    python src/embeddings/report_embedder.py
  2. Phase 4B: Trajectory and Window Embeddings Generate embeddings that capture the longitudinal temporal trajectories and dynamic windows.

    python src/embeddings/trajectory_embedder.py

Phase 5 & 6: Image Embeddings and Vector Store Compilation

We process visual inputs (specifically handling multiple views like AP and LV) and finally compile our embeddings into vector databases.

  1. Phase 5: Dual Image Embeddings Extract offline features for the dual-view chest X-rays.

    python src/embeddings/dual_image_embedder.py
  2. Phase 6: Build Vector Stores Compile all the extracted embeddings into efficient vector stores for fast similarity search.

    python src/embeddings/vector_store.py

Phase 7: Multimodal Fusion Index

  1. Phase 7: Fused Vector Store (View-Aware) Fuse the text and image embeddings to build the ultimate cross-modal, view-aware fused vector store using BiomedCLIP.
    python src/fusion/build_fusion_index.py

Running the TM²-RAG Application

Once the entire offline data pipeline is executed and all indices and vector stores are built, you can run the interactive Chatbot interface. The application relies on Phase 5A (Query Processor) and Phase 5B (Time-Aware Retriever) at runtime to fetch the most relevant context for generation.

To start the Streamlit application:

streamlit run app.py

This will launch a web interface where you can input real-time text and multimodal chest X-rays, query the system, perform longitudinal trajectory analysis, and generate explainable clinical findings.

TM²-RAG Demo


Author

About

An automated framework for temporal multimodal medical retrieval augmented generation.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages