Skip to content

inv-fourier-transform/MedTrace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

MedTrace

๐Ÿ”ฌ MedTrace: Connecting the dots across PubMed

RAG-powered biomedical literature analysis with contradiction detection and evidence synthesis.

LangChain FAISS Groq HuggingFace Streamlit PubMed

RAG Contradiction Detection Evaluation

MedTrace retrieves, analyzes, and synthesizes peer-reviewed biomedical literature from PubMed, automatically detecting conflicting evidence and providing quality metrics for AI-generated responses.


๐Ÿ“– Description

๐Ÿ”น What it does

Connects to the PubMed database via NCBI E-utilities API to fetch peer-reviewed articles, chunks and embeds them into a FAISS vectorstore, then answers queries with automatically detected evidence contradictions and quality metrics.

๐Ÿ”น What problem it solves

Eliminates manual literature review burden while providing critical analysis of conflicting study findingsโ€”something standard RAG systems ignore. Users get not just answers, but insight into the strength and consistency of the underlying evidence.

๐Ÿ”น Key Differentiators

Unlike standard RAG systems that present retrieved text blindly, MedTrace:

  • Detects contradictions across multiple studies and synthesizes conflicting evidence
  • Scores response quality using LLM-as-judge evaluation (relevance, groundedness, confidence)
  • Surfaces evidence distribution (Supporting/Opposing/Neutral) transparently

โœจ Key Features

Feature Description
๐Ÿ” PubMed Integration Direct API access to 39M+ peer-reviewed biomedical articles
โšก Contradiction Detection LLM-based stance classification identifies conflicting study conclusions
๐Ÿ“Š Quality Metrics Real-time evaluation dashboard (Relevance, Groundedness, Confidence)
๐Ÿง  Evidence Synthesis Automatic summarization of opposing viewpoints when contradictions detected
๐Ÿ”— Source Transparency Every claim linked to PubMed source with stance classification

๐Ÿ“‚ Folder Structure

MedTrace/
โ”œโ”€ artifacts/
โ”‚  โ”œโ”€ screenshots/           # UI screenshots and demo images
โ”‚  โ””โ”€ *.txt                  # Documentation and reference files
โ”‚
โ”œโ”€ core/                     # Backend processing modules
โ”‚  โ”œโ”€ __init__.py           # Package exports
โ”‚  โ”œโ”€ config.py             # Environment configuration and path resolution
โ”‚  โ”œโ”€ pubmed_fetcher.py     # NCBI E-utilities API integration for article retrieval
โ”‚  โ”œโ”€ chunker.py            # Recursive character text splitting with overlap
โ”‚  โ”œโ”€ embeddings.py         # SentenceTransformer wrapper with fallback mechanisms
โ”‚  โ”œโ”€ vector_store.py       # FAISS index creation and persistence
โ”‚  โ”œโ”€ query_engine.py       # Retrieval and LLM response generation
โ”‚  โ”œโ”€ contradiction_detector.py  # Stance analysis and conflict detection
โ”‚  โ””โ”€ evaluation.py         # LLM-as-judge metrics (relevance, groundedness)
โ”‚
โ”œโ”€ frontend/
โ”‚  โ””โ”€ app.py                # Streamlit UI with real-time metrics dashboard
โ”‚
โ”œโ”€ .env                     # Environment variables (API keys, paths) - not committed
โ”œโ”€ .gitignore              # Git exclusion rules
โ”œโ”€ requirements.txt        # Python dependencies
โ””โ”€ README.MD               # This file

โš ๏ธ Prerequisites: Create a .env file in the root directory with:

  • GROQ_API_KEY
  • VECTOR_DIR
  • GROQ_MODEL
  • EMBEDDING_MODEL

๐Ÿ› ๏ธ Setup Instructions

1๏ธโƒฃ Clone the Repository

git clone https://github.com/inv-fourier-transform/med-trace.git
cd MedTrace

2๏ธโƒฃ Create a Virtual Environment

python -m venv .venv

Activate the Virtual Environment

Windows:

.venv\Scripts\activate

macOS/Linux:

source .venv/bin/activate

3๏ธโƒฃ Install Dependencies

pip install -r requirements.txt

4๏ธโƒฃ Configure Environment Variables

Create a .env file in the project root and add your required API keys.

โ–ถ๏ธ Execution

Streamlit UI (Recommended)

streamlit run frontend/app.py

Workflow:

  1. Enter a biomedical topic (e.g., "ketogenic diet")
  2. Select number of articles to ingest (10โ€“299)
  3. Click "Ingest Articles" to fetch, chunk, and embed
  4. Ask questions and view contradiction analysis with quality metrics

CLI Mode

python main.py

๐Ÿš€ The 2 New Features

1. โšก Contradiction Detection & Evidence Synthesis

Standard RAG systems retrieve documents without analyzing agreement. MedTrace adds LLM-based stance analysis:

  • Classifies stance: Each study labeled as Supporting, Opposing, or Neutral
  • Detects conflicts: Identifies when evidence contradicts (e.g., 3 studies show benefits, 2 show no effect)
  • Synthesizes conflicts: Generates balanced explanation of contradictions (study design differences, populations, protocols)

Screenshots

1. Streamlit Frontend Interface

Streamlit UI

2. Results

Topic 1: "Hydroxychloroquine"

Query: Evidence for and against the usage of HCQ for treatment of Covid-19

Topic_1 Query_1_Topic_Evidence_Distribution_And_Answer Query_1_RAG_Eval_Metrics Query_1_Answer_Sources Query_1_Answer_Sources

Topic 2: "Tylenol and autism"

Query: Does Tylenol consumption in lactating women lead to autism in newborns?

Topic_2 Query_2_Topic_Evidence_Distribution_And_Answer Query_2_RAG_Eval_Metrics_And_Sources

Example Output

Evidence Distribution: โœ… 3 Supporting | โŒ 2 Opposing | โš–๏ธ 1 Neutral

โš ๏ธ Contradictory Evidence Detected

Evidence Synthesis:
While three RCTs demonstrate cardiovascular benefits of intermittent fasting,
two recent meta-analyses found no significant effect when controlling for 
caloric deficit. Differences stem from intervention duration protocols.

๐ŸŽฅ Demo Video

Watch the demo

The demo video can be viewed by downloading it. It's just 14 MB in size!

FYI, Miss K, a metaphor for someone๐Ÿค”, is endorsing my product!


2. ๐Ÿ“Š RAG Evaluation Metrics Dashboard

Every response includes LLM-as-judge quality metrics:

Metric Description
Relevance Retrieved articles match the query specificity
Groundedness Answer is factually supported by sources
Confidence Citation density and specificity
Overall Aggregate quality score

Indicators:
๐ŸŸข High (โ‰ฅ80%) | ๐ŸŸก Medium (60โ€“79%) | ๐Ÿ”ด Low (<60%)


๐Ÿ› ๏ธ Technologies Used

  • Python 3.10+ โ€“ Core language
  • LangChain โ€“ RAG orchestration
  • FAISS โ€“ Vector similarity search
  • Sentence-Transformers โ€“ BGE embeddings
  • Groq โ€“ High-speed LLM inference
  • Streamlit โ€“ Web interface
  • PubMed E-utilities API โ€“ Literature source

๐Ÿ”ฎ Roadmap

  • Multi-query Retrieval โ€“ Decompose complex questions into sub-queries
  • Citation Network Analysis โ€“ Map relationships between studies
  • Export Functionality โ€“ Generate PDF reports with citations

๐Ÿ™ Credits

  • NLM/NCBI for PubMed database and E-utilities API
  • BAAI for BGE embedding models
  • LangChain and Streamlit communities

โš ๏ธ Disclaimer

Content sourced from PubMed/NLM. For informational purposes only โ€” not for diagnosis or treatment decisions. Always consult healthcare providers for medical advice. Evidence metrics are algorithmic estimates and should not replace reading primary sources.


๐Ÿ“Œ Quick Tips

  • Specific queries work best โ€“ Ask precise clinical questions
  • Check evidence distribution โ€“ Review Supporting/Opposing badges
  • Monitor metrics โ€“ Low groundedness indicates weak source support

MedTrace: Where AI meets evidence-based medicine.

About

MedTrace is a PubMed-powered RAG application that retrieves, embeds, and analyzes biomedical literature, adding a contradiction detection layer to highlight supporting vs. opposing evidence and an LLM-as-a-judge evaluation module to score response relevance, groundedness, and confidence.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages