Medical RAG system — generative AI

Medical RAG system — generative AI


AI
RAG
Healthcare
OCR
MCP
Vector search
PythonFastAPIpgvectorQdrantFastMCPGroq CloudLlama 3.3 70BClaude Haiku 4.5OCRReactDocker

Instances

  • chat.imane.ai — live
  • chat.afred.ai — second instance, DNS record still to be published

Features

The interface, named Imane — intelligent medical assistant, exposes the RAG through five entry points:

  • Chat: natural-language questions about medication, symptoms, prevention and first aid. Every answer is structured (pharmacology, dosage, contraindications, monitoring) and comes with a Sources tab citing the documents queried — BDPM, the French public medication database, is flagged explicitly.
  • Compare: comparison of two to five medications along a chosen aspect (side effects, interactions…). The generated synthesis contrasts mechanisms of action, safety profiles, contraindications, liver and kidney toxicity, drug interactions, required monitoring, then a clinical conclusion.
  • Medications, Interactions and Statistics: direct browsing of the indexed corpus.

The guiding principle is traceability: no answer is returned without the sources backing it — a precondition for an assistant operating on a medical domain.

Goal

Let a corpus of clinical documents be queried in natural language, without the practitioner needing to know how those documents are structured.

What I built

  • Vector indexing through pgvector, then Qdrant, comparing both approaches.
  • Multi-model generation: Llama 3.3 70B served by Groq Cloud and Claude Haiku 4.5, routed per query. Average latency is tracked per model, the gap between the two being close to a factor of five.
  • Automated OCR extraction from PDF and JPG prescriptions.
  • An MCP server (FastMCP) with its API documentation, making the RAG directly consumable by AI agents — not only through the web UI.

Back office: governance and observability

A medical domain rules out shipping an assistant without a safety net. That is what the Medical RAG back office is for:

  • Governance: answers can be flagged and enter a review queue (to review, reviewed & resolved). Queries that returned no document at all are isolated as suspicious — the textbook symptom of a fabricated answer.
  • Observability: query volume, success rate, average and maximum latency, cache hit rate, error log. Per-model tracking supports the trade-off between cost, latency and quality.
  • Real usage: most queried medications and operation breakdown (medication query, query with no documents, query with generation), which show where the corpus falls short.
  • Role-based API keys: client access separate from the healthcare professional role, with an expiry date — the RAG is consumed by third-party applications as much as by the web interface.

Stack

Python, FastAPI, pgvector, Qdrant, Groq Cloud (Llama 3.3 70B), Claude Haiku 4.5, OCR, React, Docker.

The assistant

Imane assistant home screen: four entry points — medication, symptoms, prevention, emergencies Four doors to frame the question before it is even asked.

Answer about Doliprane: “Medical answer” and “Sources (5)” tabs, a badge for the queried source BDPM, and pharmacology, dosage and contraindication sections The answer is structured by section and the queried source is named — here BDPM. The Sources tab lists the documents backing the answer: without them the tool would not be usable.

Comparison screen: two to five medications and an aspect to compare Comparator: from two to five medications, along a chosen aspect — side effects, interactions, contraindications.

Back office

Dashboard: query volume, success rate, average latency, most queried medications, governance queue and per-model latency Per-model tracking is the most useful part: at comparable quality, the latency gap between the two models in use reaches a factor of five.

Analytics: queries per day, operation breakdown, average response time and cache hit rate Operations are split between medication query, query with no documents and query with generation — the second category flags gaps in the corpus.

API key management: “API client” and “healthcare professional” roles, status and expiry date Role-based API keys with expiry: the RAG is consumed by third-party applications as much as by the web interface.