A Retrieval-Augmented Generation (RAG) system designed to answer clinical questions based on MIMIC-IV data, using LangChain, LLaMA 2, BioBERT embeddings, and Pinecone for retrieval. Guardrails are enforced using Natural Language Inference (NLI) to reduce hallucinations.
This project builds an intelligent clinical QA system powered by LLaMA and LangChain. It uses:
- MIMIC-IV data via Pinecone + BioBERT retriever
- Advanced prompt-based LLaMA2 for generation
- NLI-based guardrails to reduce hallucinations
- External search fallback (via SerpAPI)
- Context-Aware Retrieval: Uses BioBERT + Pinecone to pull semantically relevant patient notes from MIMIC-IV.
- LLaMA 2 QA Model: Generates grounded, clinical answers using a structured prompt.
- Model-Based Guardrails (NLI):
- Applies a pre-trained RoBERTa NLI model to detect hallucinated or unfaithful outputs.
- LangChain Framework: Modular, production-ready RAG pipeline.
- Gradio Interface: Simple UI for clinicians, students, or researchers to interact with.
[Clinical Query]
↓
[Pinecone + BioBERT Retriever]
↓
[Prompt Template]
↓
[LLaMA 2 Generation]
↓
[NLI Guardrails (RoBERTa-MedNLI)]
↓
[Fallback: SerpAPI for Web Answers]
↓
[Gradio UI]
- Clone the repo and install dependencies:
pip install -r requirements.txt- Set your
.envvariables:
PINECONE_API_KEY=your_key
SERPAPI_API_KEY=your_key
- Launch the app:
python caremind_agent.py