How priyank-mali/medical-chatbot works
Project type and purpose
• This is a Python-based question-answering “medical chatbot” service. It ingests PDF medical books, transforms them into embeddings stored in a local Chroma vector database, then answers user queries by retrieving relevant passages and calling an LLM (e.g. OpenAI).
• It is not a full MVC web app with a separate frontend codebase; it’s primarily a backend/chat microservice exposed via app.py (likely a FastAPI or Flask app), with helper modules for vectorization (vector.py) and the chat logic (chatbot.py), plus a Dockerfile for containerization.
File structure
• Top-level scripts
– app.py: entry point exposing HTTP endpoints (the “presentation layer”).
– chatbot.py: core logic for orchestrating retrieval + LLM calls (the “domain/service layer”).
– vector.py: embedding utilities for text/document vectorization.
• Data folders
– medical_books/: raw PDF sources.
– medical_chromadb/: persisted ChromaDB folder (SQLite file + binary index files).
• Infra/config
– Dockerfile: container definition.
– requirements.txt: Python dependencies (e.g. Chroma, OpenAI SDK, FastAPI/Flask).
Key insights from README
• Minimal README, but artifact names and file structure clearly point to a retrieval-augmented generation (RAG) pipeline specialized for medical text.
a. Main components
1. User Interface / Client (CLI or HTTP client)
2. API Layer (app.py)
3. Chatbot Service (chatbot.py)
4. Embedding Service (vector.py)
5. Vector Store (ChromaDB directory + SQLite)
6. External LLM Service (OpenAI)
7. Data Store (raw PDFs in medical_books/)
8. Container Environment (Docker)
b. Relationships & data flow
• User → HTTP POST /chat → API Layer (app.py)
• API Layer calls Chatbot Service
• Chatbot Service invokes Embedding Service to embed the query
• Embedding Service queries Vector Store for top-K passages
• Chatbot Service composes prompt with retrieved passages
• Chatbot Service calls External LLM API → receives answer
• API Layer returns answer to User
c. Architectural patterns / design principles
• Layered architecture: Presentation (app.py) → Domain/Service (chatbot.py) → Data/Storage (ChromaDB)
• Separation of concerns: embedding logic isolated in vector.py; business rules in chatbot.py; transport in app.py
• Containerized deployment for reproducibility (Dockerfile)
d. Key technologies & libraries
• Python 3.x, FastAPI or Flask
• ChromaDB (vector database, SQLite backend)
• OpenAI (LLM API)
• Docker