πππ ππ¨π« ππ’ππ π§π¨π¬ππ’π ππππ¬π¨π§π’π§π ππ¨π« ππ₯π’π§π’πππ₯ ππ¨πππ¬ (ππ’ππππ)
Empowering clinicians with grounded, real-time insights.
π§ Project Overview and Motivation
In the high-stakes environment of healthcare, quick access to reliable and up-to-date clinical knowledge is vital. While Large Language Models (LLMs) like GPT or LLaMA are powerful, their knowledge is static and confined to their training data. This limitation can result in outdated information or hallucinated content β especially dangerous in clinical settings.
Our project, DiReCT (Diagnostic Reasoning for Clinical Notes), aims to solve this using Retrieval-Augmented Generation (RAG). DiReCT brings together cutting-edge components like LangChain, FAISS, and Bio_ClinicalBERT to enable contextually aware, evidence-grounded diagnostic support for clinicians.
Get Waghib Ahmadβs stories inΒ yourΒ inbox
Join Medium for free to get updates fromΒ thisΒ writer.
Hosted on Hugging Face Spaces with a Streamlit frontend and powered by Groqβs ultra-fast LLaMA 3.3 70B model, DiReCT is a fully functional clinical assistant AI prototype for the future of decision support.+-
βοΈ Methodology
1. Data Collection and Preprocessing
We used both diagnosis flowcharts and patient case notes from the publicly available MIMIC-IV-Ext dataset. These documents were processed and loaded using Python scripts that:
- Parse JSON files for structured flowcharts
- Extract relevant fields from patient cases
- Format all information into a consistent schema
def load_clinical_data():
# Load diagnosis flowcharts and patient case notes
# Returns a list of Document objects2. Embeddings and Vector Store
To semantically represent medical documents, we used Bio_ClinicalBERT via HuggingFace:
embeddings = HuggingFaceEmbeddings(
model_name="emilyalsentzer/Bio_ClinicalBERT",
model_kwargs={"device": "cuda"}
)Documents were chunked and embedded into a FAISS vector store:
def build_vectorstore():
# Chunk documents, embed, and return FAISS vectorstore3. RAG Pipeline
The RAG system works by retrieving relevant clinical information and passing it along with the user query to a powerful LLM.
def run_rag_chat(query, vectorstore):
# Uses LangChain to retrieve and generate responseπ How DiReCT Works
- Query Input β Clinician enters a diagnostic question.
- Retrieval β LangChain + FAISS search MIMIC-IV clinical notes using Bio_ClinicalBERT embeddings.
- Prompt Building β Top results are merged with the query.
- Generation β Prompt is sent to Groq-hosted LLaMA 3.3 70B.
- Response β Result shown via a Streamlit app on Hugging Face Spaces.
4. Evaluation
To measure reliability and accuracy, we added basic evaluation metrics:
- Hit Rate: Measures overlap between expected and retrieved documents
- Faithfulness: Cosine similarity between context and generated answer
def evaluate_rag_response(response, embeddings):
# Computes hit rate and faithfulness scoresπ Key Challenges
- Data Parsing: Clinical notes are often unstructured. Structuring patient data and flowcharts in a consistent way required significant cleaning.
- Prompt Engineering: Getting the LLaMA model to produce medically sound, structured responses required prompt tuning.
- Evaluation: Designing automatic evaluation for RAG systems β especially in clinical NLP β is non-trivial and required customized metrics.
π Findings and Lessons Learned
- Bio_ClinicalBERT significantly improves retrieval relevance compared to generic embeddings.
- FAISS + LangChain provided a scalable and modular foundation for RAG pipelines.
- Hosting on Hugging Face Spaces with Groq makes it feasible to deliver near real-time results with powerful LLMs.
- Clinical RAG systems benefit greatly from hybrid datasets (structured + unstructured) to provide contextual reasoning.
π Try It Out
- Live Demo on Hugging Face Spaces: DiReCT Demo
- Full Source Code: GitHub Repository
We hope DiReCT inspires future applications in clinical NLP, decision support systems, and real-world AI for medicine.
#RAG #LLM #LangChain #Groq #BioClinicalBERT #MIMICIV #ClinicalAI #Streamlit #AIinMedicine #OpenSource #MedicalNLP #DiReCT







