SR Logo/AI Engineering
Generative AICOMPLETED

MedBot: AI Medical Knowledge Assistant & RAG Pipeline

Grounded retrieval-augmented generation pipeline indexing medical documents in Pinecone vector database with LangChain orchestration, OpenRouter, and FastAPI.

CategoryGenerative AI
Statuscompleted System
Core Tooling
LangChainPineconeFastAPIFlaskOpenRouterHugging FacePython

01. Problem & Operational Context

Medical Q&A systems require strictly factual, grounded information retrieval from complex medical literature; naive language models hallucinate terminology, dosages, and clinical guidelines without verifiable passage grounding.

02. Technical Approach

Architected an end-to-end RAG pipeline using LangChain to process medical literature into semantic embeddings, index vectors in Pinecone, retrieve relevant clinical passages, and pass context to LLMs via OpenRouter for verifiable response generation.

03. System Architecture & Pipeline

End-to-End System Pipeline & Computation Flow

Document ingestion and semantic retrieval system coupling dense vector indexing with verified passage extraction.

STEP 01PyPDF / LangChain
Medical PDF Ingestion & Chunking

Document parsing, recursive text splitting, and clinical header preservation.

STEP 02Hugging Face / Pinecone
Semantic Vector Embedding

Generating high-dimensional embeddings and indexing into Pinecone vector database with metadata tags.

STEP 03Pinecone Vector DB
Context Retrieval & Filtering

Cosine similarity vector search extracting top-k most relevant passages for the clinical query.

STEP 04OpenRouter / FastAPI
Grounded Response Generation

Passing verified retrieved passages to LLMs (via OpenRouter) with prompt guards to ensure grounded answers.

04. Key Implementation Details

  • Engineered an end-to-end RAG pipeline processing complex medical PDFs into semantically coherent embedding chunks.
  • Indexed embeddings in Pinecone for low-latency vector-based semantic retrieval.
  • Used LangChain to orchestrate context retrieval chains and deliver grounded passages to LLMs.
  • Exposed chatbot functionality through FastAPI and Flask backend APIs for reliable downstream client consumption.

05. Architectural Tradeoffs & Decisions

Decision: Selected Pinecone managed vector database with metadata filtering over local vector files.
Justification

Guarantees reliable cloud indexing, fast HNSW similarity search, and easy horizontal scaling as document collections expand.

Alternative Considered

In-memory flat vector search which became a memory bottleneck during multi-document ingestion.

06. Engineering Challenges & Failures

Challenge: Dense medical terminology and abbreviations causing semantic vector retrieval misses.
Solution: Configured domain-tailored chunk overlap and recursive character splitting to preserve clinical context boundaries.
Challenge: Model hallucination when queries lacked direct matches in indexed documents.
Solution: Implemented strict prompt grounding templates instructing the model to declare absence of source context rather than guess.

07. Evaluation & Observations

Evaluation Methodology:

Evaluated response groundedness, context relevance, and factual clarity on medical literature Q&A queries.

Key Empirical Finding:

Contextual prompt constraints ensured the assistant quoted exact source sections for critical medical facts.

Verified Artifacts
architectureMedBot RAG Architecture

Flowchart showing PDF ingestion, Pinecone vector indexing, LangChain orchestration, and FastAPI endpoints.