How malishilpa9119/health-care-chatbot works
Purpose and Runtime Entry Points
This repository is a document-grounded healthcare clinic chatbot. It answers clinic-policy and medical-document questions through a RAG workflow, while routing emergency, medication/dosage, and unsupported requests to safe responses.
• Web runtime: app.py
• Indexing/batch ingestion runtime: store_index.py
• Core application package: src/
Document Ingestion and Index Construction
Clinic and medical PDFs are the authoritative knowledge source. The indexing process loads PDFs, chunks their content, produces HuggingFace embeddings, and writes vectors to Pinecone. Re-indexing is required after document changes.
• Source corpus: data/HealthFirst_Clinic_Info.pdf, data/Medical_book.pdf
• Loading, splitting, and embedding utilities: src/helper.py
• Index build entry point: store_index.py
Retrieval Layer
The retrieval boundary converts a user question into grounded evidence from the vector store. It combines semantic Pinecone search with BM25 keyword retrieval, then applies cross-encoder re-ranking to prioritize the most relevant document chunks.
• Hybrid retrieval and re-ranking: src/retriever.py
• Retriever/tool implementation is consumed by the workflow: src/agent.py
• Persistent external retrieval service: Pinecone
LangGraph Conversation Workflow
The central control flow is a LangGraph agent pipeline:
1. Receive current user question plus multi-turn conversation context.
2. Apply safety guardrails.
3. Retrieve and rank document evidence when permitted.
4. Generate an answer constrained to retrieved content.
5. Use a fallback branch when evidence is absent or the request is unsafe/out of scope.
• Workflow nodes, routing, and agent state: src/agent.py
• Grounding and behavioral instructions: src/prompt.py
Generation, Safety, and Fallback Boundaries
Groq-hosted Llama 3.3 70B performs answer generation. Prompting and graph routing enforce the core product constraint: do not invent clinic or medical facts beyond supplied documents. Emergency and medication/dosage requests are safety boundaries rather than normal retrieval questions; unsupported requests receive a defined fallback.
• Agent orchestration and guardrail/fallback handling: src/agent.py
• System prompt contract: src/prompt.py
• External LLM provider: Groq; optional image-analysis provider: OpenAI
Flask Interface and Session Interaction
Flask exposes the chat application on the local web server and connects browser requests to the agent workflow. The HTML template provides the conversation interface, with static CSS for presentation. The application maintains multi-turn context so follow-up questions can depend on prior turns.
• HTTP application entry point: app.py
• Chat UI: templates/chat.html
• Client styling: static/style.css
Deployment and Dependencies
The runtime is Python, with container deployment support. Required credentials are environment-provided API keys for Pinecone and Groq; OpenAI is optional for image analysis. The architecture depends on LangChain/LangGraph for orchestration, Pinecone for vector persistence, HuggingFace embeddings for vectorization, and Flask for serving.
• Dependency declaration: requirements.txt
• Container runtime definition: Dockerfile
• Python runtime version declaration: runtime.txt
Main entry points: app.py Flask chat server · agent.py Grounded answer generation · retriever.py Hybrid retrieval · store_index.py Index build runtime
Components 17
Web interface
- Flask chat server · Serves chat requests and maintains multi-turn context.
app.py - Chat interface
templates/chat.html - Client styles
static/style.css
Conversation workflow
- LangGraph agent · Owns state, routing, safety handling, and fallback responses.
src/agent.py - Safety routing · Routes emergency, dosage, unsafe, and unsupported requests away from normal answering.
src/agent.py - Hybrid retrieval · Combines Pinecone semantic search, BM25, and cross-encoder reranking.
src/retriever.py - Grounding contract · Constrains answers to supplied document evidence.
src/prompt.py - Grounded answer generation
src/agent.py
Index construction
- Index build runtime · Rebuilds the vector index after corpus changes.
store_index.py - Clinic and medical PDFs
- Load, chunk, embed · Extracts PDF content, splits chunks, and creates HuggingFace embeddings.
src/helper.py
External services
- Pinecone · Persists document vectors and serves semantic search.
- Groq Llama 3.3 70B
- OpenAI image analysis
Other components
- Container deployment
Dockerfile - Python dependencies
requirements.txt - Python runtime version
runtime.txt
Connections 18
- Chat interface → Flask chat server: chat requests
- Client styles → Chat interface: styles
- Flask chat server → LangGraph agent: question + conversation context
- LangGraph agent → Safety routing: evaluate request
- Safety routing → Hybrid retrieval: permitted question
- Safety routing → Flask chat server: safe fallback
- Hybrid retrieval → Pinecone: semantic search
- Hybrid retrieval → Grounded answer generation: ranked evidence
- Grounding contract → Grounded answer generation: grounding instructions
- Grounded answer generation → Groq Llama 3.3 70B: generate answer
- Grounded answer generation → Flask chat server: grounded response
- Index build runtime → Clinic and medical PDFs: loads PDFs
- Index build runtime → Load, chunk, embed: uses
- Load, chunk, embed → Pinecone: writes embeddings
- Container deployment → Flask chat server: runs
- Python dependencies → Flask chat server: provides libraries
- Python runtime version → Container deployment: pins runtime
- LangGraph agent → OpenAI image analysis: optional image analysis