Skip to content
← All work

2026

ClinicalRAG

Answers questions using an indexed set of clinical guidelines. Each sentence links back to its source, and unsupported questions return a refusal.

Role
Sole engineer
Stack
Python, LangGraph, FastAPI, ChromaDB, ONNX, Groq, React, Docker
ClinicalRAG query console showing an answer, grounding score, and supporting guideline sources

The problem

A retrieval system can still produce an answer that is not supported by what it retrieved. For clinical questions, showing the source is only useful if the answer itself stays within that source.

ClinicalRAG answers from a fixed set of ingested guidelines and tracks source support at the sentence level. Questions outside the domain or without enough supporting evidence return a refusal. It is an educational project and has not been clinically validated.

How a query is handled

  1. Physician console

    React. Sends the question, collection and source limit.

  2. Query API

    FastAPI, POST /api/v1/query, with rate limiting, request IDs and typed models.

  3. Guard

    Checks whether the question is in-domain before retrieval.

    Off-topic: return a refusal with reason off_topic.

  4. Decompose

    Splits compound questions using a term lexicon. No model call.

  5. Retrieve

    Multi-query ChromaDB search over MiniLM embeddings, deterministic rerank, merge cap.

  6. Grade relevance

    llama-3.1-8b-instant keeps chunks that can support the question.

    No relevant chunks: skip generation and refuse.

  7. Generate

    llama-3.3-70b-versatile, or an extractive answer in mock mode.

  8. Evaluate grounding

    Checks sentence attribution, citation coverage and dosages against the retrieved sources.

    Unsupported dosage: refuse.

  9. Respond and audit

    Returns the answer, citations and any refusal reason. A SHA-256 hash of the query is written to the audit log.

The query is checked, retrieved against the corpus, graded for relevance, and either answered with citations or refused.

When it refuses

  • The question falls outside the clinical domain.
  • Retrieval does not return evidence relevant enough to answer it.
  • The generated answer contains a dosage unsupported by the retrieved sources.

What you see

  • Public demo: ONNX MiniLM retrieval with deterministic extractive responses.
  • An answer with supporting citations, or a refusal with its reason.
  • A grounding score for the generated answer.
  • A deterministic mock mode for running tests without an API key.

Limits

  • Educational software, not a medical device or clinically validated system.
  • The demo uses a small guideline corpus.
  • The refusal checks cover specific failure modes and do not establish that an answer is clinically correct.