Back to home

Overview

I built a RAG (Retrieval-Augmented Generation) chat system for the pharmaceutical industry that goes beyond text-only responses. It interprets domain queries and responds with precise answers plus dynamically generated charts (bar graphs, trend lines, scatter plots) synthesized from proprietary pharmaceutical data.


The standout piece was shipping an automated chart generation pipeline before ChatGPT had its own chart rendering. The system analyzes structured data from the retrieval step, decides whether a visual would help, and generates the right chart type with proper labels, scales, and annotations.


By grounding responses in curated pharmaceutical knowledge bases instead of relying on general-purpose LLM knowledge, accuracy on domain-specific queries went way up. That matters a lot in pharma, where precision affects patient outcomes and regulatory compliance.

Key Features

Tech Stack

Python
Backend for the RAG pipeline, embedding generation, retrieval logic, and chart rendering
React
Chat interface with streaming responses, interactive chart components, and conversation history
LLM
Custom prompting strategies tuned for pharmaceutical domain accuracy and structured output generation
RAG
Vector search, hybrid retrieval, re-ranking, and context window management for domain-grounded responses
Chart Generation
Analyzes query results, picks the right chart type, and renders clean visuals with proper statistical formatting
FastAPI
API layer handling chat sessions, streaming responses, file uploads, and external pharmaceutical data source integration

Architecture

Pipeline architecture: query analysis classifies intent and extracts entities. Retrieval queries multiple vector stores and structured databases in parallel, then re-ranking picks the most relevant context. Generation runs two parallel paths: text generation for the narrative answer, and chart analysis that decides if a visualization is warranted and produces chart specs. Both paths merge at response assembly, which interleaves text and charts into a single answer streamed to the frontend.

Challenges & Solutions

Achieving domain accuracy above general-purpose LLMs

Pharma queries need exact terminology, precise numbers, and regulatory awareness that general-purpose LLMs often get wrong. I built a multi-stage verification pipeline: retrieved context is validated against structured databases for factual consistency, numerical claims are cross-referenced with source data, and the final response goes through a domain-specific layer that flags potential inaccuracies. This cut hallucination rates significantly compared to direct LLM responses.

Automated chart type selection and generation

Deciding when a chart actually helps, and which type fits the data, requires understanding both the data structure and what the user is trying to learn. I built a classification system that looks at the data shape (time series, categorical comparison, distribution, correlation) and the query intent to pick the right visualization. The pipeline handles edge cases like sparse data, outliers, and mixed scales, producing clean charts with proper annotations instead of misleading visuals.