Secure Retrieval-Augmented Generation in ECG Using ML based Lightweight LLMs
Keywords:
ECG Classification, GPT, GANs, LLM, Model Interpretability, Arrhythmia DetectionAbstract
This project introduces a framework for appropriately adapting and adjusting machine learning (ML) techniques used to construct electrocardiogram (ECG)-based schemes. With more qualified training data given to corresponding machine learning schemes, the precision on ML-based ECG mechanisms are increased in consequence. In the proposed framework four new measure metrics are introduced to evaluate the quality of the ML training and testing data, all proposed mechanisms, metrics, and sample data with demonstrations using various ML techniques, is developed. For developing ML based ECG. The system uses retrieval-augmented generation (RAG) to provide a lightweight LLM with relevant cardiology knowledge at inference time, enabling it to diagnose cardiac conditions from ECG data without task-specific training. We extend the original methodology by deploying a small, open-source LLM (Versatile--Llama 3B) locally using the Ollama platform, ensuring patient data never leaves the premises. The proposed system aims to replicate these benefits in a secure environment. We detail the existing solutions, the proposed architecture, its advantages in privacy and cost, system requirements, and a comprehensive methodology. The outcome is an on-premise ECG diagnostic assistant that leverages both the efficiency of a small LLM and the accuracy of domain-specific retrieval, demonstrating a feasible path toward AI-assisted cardiac diagnosis without compromising data security
Downloads
Metrics
References
Yu et al., 2023: Han Yu, Peikun Guo, & Akane Sano. “Zero-Shot ECG Diagnosis with Large Language Models and Retrieval-Augmented Generation.” Proc. of Machine Learning for Health (ML4H) 2023, PMLR 225:650–663, 2023.
Li et al., 2023: Jun Li, Che Liu, Sibo Cheng, Rossella Arcucci, & Shenda Hong. “Frozen Language Model Helps ECG Zero-Shot Learning.” arXiv preprint arXiv:2303.12311, 2023.
Lewis et al., 2020: Patrick Lewis et al. “Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks.” Advances in Neural Information Processing Systems, 33:9459–9474, 2020.
Singhal et al., 2023: Karan Singhal et al. “Towards Expert-Level Medical Question Answering with Large Language Models.” arXiv preprint arXiv:2305.09617, 2023.
Liu et al., 2021: Xinwen Liu, Huan Wang, Zongjin Li, & Lang Qin. “Deep learning in ECG diagnosis: A review.” Knowledge-Based Systems, 227:107187, 2021.
Touvron et al., 2023: Hugo Touvron et al. “Llama 2: Open foundation and fine-tuned chat models.” arXiv preprint arXiv:2307.09288, 2023.
Ollama, 2025: Ollama – Run large language models locally. (Website, ollama.com) ollama.com
Cherny, 2023: Yoni Cherny. “How to Run Open-Source LLM Models Locally with Ollama.” Medium (CyberArk Engineering), July 2023.medium.com
VersatileLlama Model Card, 2023: QuantFactory. “VersatileLlama-Llama-3.2-3B-Instruct-Abliterated.” (Model Card on HuggingFace) huggingface.co
Wagner et al., 2020: Patrick Wagner et al. “PTB-XL, a large publicly available electrocardiography dataset.” Scientific Data, 7(1):154, 2020.
Penzel et al., 2000: Thomas Penzel et al. “The apnea-ECG database.” Computers in Cardiology 2000, 27:255–258, IEEE, 2000.
Downloads
Published
How to Cite
Issue
Section
License

This work is licensed under a Creative Commons Attribution 4.0 International License.
You are free to:
- Share — copy and redistribute the material in any medium or format
- Adapt — remix, transform, and build upon the material for any purpose, even commercially.
Terms:
- Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.