Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clinical Decision Support System (CDSS) — PharmaRAG

A Python Retrieval-Augmented Generation (RAG) pipeline with a Streamlit Web UI for real-time drug safety alerts: side effects, drug-drug interactions, and contraindications — grounded in FDA and NLM data.

Powered by Groq API (Lightning fast Llama 3 models) — 100% Free and open-source models.

Features

  • Web UI: Interactive clinical query interface built with Streamlit.
  • Fast Extraction: Uses llama-3.1-8b-instant to instantly parse clinical entities.
  • Live Database Retrieval: Queries NLM RxNorm, OpenFDA, and RxNav APIs in real-time.
  • Clinical Synthesis: Uses llama-3.3-70b-versatile to synthesize retrieved facts into a comprehensive alert.

Architecture

Doctor Query (NL via Web UI or CLI)
     │
     ▼
[Stage 2] Entity Extraction       ← Groq (Llama 3 8B), temp=0, JSON output
     │ proposed_drug, current_meds, conditions
     ▼
[Stage 3] Drug Normalization      ← RxNorm API → RxCUI codes
     │
     ▼
[Stage 4] Parallel Retrieval      ← asyncio.gather()
  ├── OpenFDA (adverse_reactions + contraindications)
  └── RxNav DDI API (interaction pairs with severity)
     │
     ▼
[Stage 5] Context Assembly        ← build_synthesis_prompt()
     │
     ▼
[Stage 6] LLM Synthesis           ← Groq (Llama 3 70B), temp=0, strict system prompt
     │
     ▼
[Stage 7] ClinicalAlert output    ← structured Pydantic model (rendered in Streamlit)

Data Sources

Source Purpose API
RxNorm (NLM) Drug name normalization rxnav.nlm.nih.gov/REST
OpenFDA Side effects + contraindications api.fda.gov/drug/label.json
RxNav DDI Drug-drug interactions rxnav.nlm.nih.gov/REST/interaction

All sources are free and require no API key for standard usage.

Setup

  1. Clone and Install:
git clone https://github.com/yourusername/PharmaRAG.git
cd PharmaRAG
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install groq streamlit
  1. API Keys: Get a free Groq API key at console.groq.com/keys. Create a .env file in the root directory:
GROQ_API_KEY=your_groq_api_key_here

Quick Start (Web UI)

The easiest way to use the system is via the included Streamlit UI:

source venv/bin/activate
streamlit run app.py

This will open http://localhost:8501 in your browser.

File Structure

PharmaRAG/
├── app.py                   # Streamlit Web UI
├── pipeline.py              # Main orchestrator (entry point for CLI)
├── requirements.txt         # Project dependencies
├── core/
│   └── models.py            # Pydantic data models for all stages
├── api/
│   └── medical_db.py        # RxNorm, OpenFDA, RxNav API clients
├── prompts/
│   └── templates.py         # All prompt templates + context assembly
└── utils/
    └── guardrails.py        # Post-generation validation layer

Key Safety Design Decisions

  1. Temperature = 0 (always): Both LLM calls are hardcoded to temperature=0. Clinical outputs must be deterministic and reproducible.
  2. Retrieval-only system prompt: The synthesis system prompt explicitly forbids drawing on training knowledge. Every claim must cite a retrieved source.
  3. No dosing data: This pipeline intentionally has no dosing information.

Regulatory Note

This system is designed as a Clinical Decision Support (CDS) tool. Depending on your jurisdiction and use case, it may be subject to FDA 21 CFR Part 820, CE marking, or equivalent medical device regulations. Consult a regulatory specialist before clinical deployment.

About

A Python Retrieval-Augmented Generation (RAG) pipeline with a Streamlit Web UI for real-time drug safety alerts: side effects, drug-drug interactions, and contraindications — grounded in FDA and NLM data. Powered by Groq API (Lightning fast Llama 3 models) — 100% Free and open-source models.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages