Skip to content

Latest commit

ย 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿฉบ Medical RAG Chatbot

A lightweight Retrieval-Augmented Generation (RAG) chatbot for querying medical documents. Upload one or more PDF files, extract and split their content, create embeddings, store them in a FAISS vector index, retrieve the most relevant document context, and generate an answer using an LLM.

โš ๏ธ Disclaimer: This project is intended for informational and educational purposes only. It is not a medical device and does not provide medical advice, diagnosis, or treatment. Always consult a qualified healthcare professional for medical decisions.

๐Ÿšง Project Status: Working prototype | PDF-based RAG pipeline | FAISS semantic retrieval | Streamlit interface


๐ŸŽฅ Demo

Core Workflow

PDF Upload โ†’ Text Extraction โ†’ Chunking โ†’ Embeddings โ†’ FAISS Vector Store โ†’ Similarity Retrieval โ†’ Context โ†’ LLM โ†’ Answer


โœจ Features

  • ๐Ÿ“„ PDF Upload โ€” Upload one or multiple medical PDF documents through the Streamlit interface
  • ๐Ÿ” Semantic Retrieval โ€” Retrieve relevant document chunks using FAISS similarity search
  • ๐Ÿค– Context-Grounded Answers โ€” Generate responses using retrieved content from uploaded documents
  • โšก Real-Time Indexing โ€” Extract, chunk, embed, and index uploaded documents during the session
  • ๐Ÿง  RAG Pipeline โ€” Combines document retrieval with LLM-based generation
  • ๐Ÿ‘€ Retrieved Context Viewer โ€” Inspect the document chunks retrieved for a query
  • ๐Ÿ–ฅ๏ธ Streamlit UI โ€” Clean interactive interface with sidebar document upload
  • ๐Ÿ” Environment-Based Secrets โ€” API credentials are loaded through .env
  • ๐Ÿ“š Multi-Document Support โ€” Query information across multiple uploaded PDFs

๐Ÿ› ๏ธ Tech Stack

Layer Technology
Programming Language Python
UI Streamlit
RAG Framework LangChain
Vector Store FAISS
LLM Integration EURI API
Text Splitting RecursiveCharacterTextSplitter
PDF Processing PyPDF2 / pdfplumber
Environment Management python-dotenv

๐Ÿ—๏ธ Architecture

                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚   User Uploads PDF  โ”‚
                 โ”‚     (Streamlit)     โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                            โ”‚
                            โ–ผ
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚   PDF Text          โ”‚
                 โ”‚   Extraction        โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                            โ”‚
                            โ–ผ
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚   Text Chunking     โ”‚
                 โ”‚  1000 / 200 overlap โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                            โ”‚
                            โ–ผ
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚    Embeddings       โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                            โ”‚
                            โ–ผ
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚   FAISS Vector      โ”‚
                 โ”‚      Index          โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                            โ”‚
                     User Question
                            โ”‚
                            โ–ผ
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚ Similarity Search   โ”‚
                 โ”‚      (Top-K)        โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                            โ”‚
                            โ–ผ
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚ Retrieved Context   โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                            โ”‚
                            โ–ผ
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚   LLM Generation    โ”‚
                 โ”‚      (EURI)         โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                            โ”‚
                            โ–ผ
                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                 โ”‚   Final Answer      โ”‚
                 โ”‚     (Streamlit)     โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

RAG Flow

  1. The user uploads one or more PDF documents.
  2. Text is extracted from the uploaded files.
  3. Documents are divided into overlapping chunks.
  4. Chunks are converted into vector embeddings.
  5. Embeddings are stored in an in-memory FAISS index.
  6. The user enters a question.
  7. FAISS performs semantic similarity search to retrieve relevant chunks.
  8. Retrieved content is supplied to the LLM as context.
  9. The LLM generates a response based on the retrieved document context.
  10. The application displays both the answer and the retrieved context.

๐Ÿ’ก Why RAG?

Traditional LLM applications rely primarily on the model's pretrained knowledge. That approach makes it difficult to query information contained in user-provided documents.

This project uses Retrieval-Augmented Generation to connect an LLM with external document knowledge.

RAG provides the ability to:

  • ๐Ÿ“š Retrieve relevant information from uploaded documents
  • ๐Ÿ”Ž Perform semantic search rather than relying only on keywords
  • ๐Ÿง  Give the LLM additional context at inference time
  • ๐Ÿ“„ Query private or domain-specific documents
  • ๐Ÿ‘€ Inspect the retrieved context used to generate an answer
  • ๐Ÿ”„ Update the knowledge available to the application by uploading new documents

๐Ÿง  Technical Highlights

  • End-to-end Retrieval-Augmented Generation pipeline
  • PDF text extraction and preprocessing
  • Recursive document chunking
  • Embedding-based semantic retrieval
  • FAISS vector similarity search
  • Context injection into an LLM prompt
  • Streamlit-based interactive frontend
  • Multiple PDF document handling
  • Runtime FAISS index construction
  • Environment-variable based API authentication
  • Retrieved-context inspection for improved transparency

๐Ÿš€ Getting Started

Prerequisites

Make sure you have:

  • Python 3.9 or higher
  • An EURI API key
  • Git installed on your system

1. Clone the Repository

git clone https://github.com/VENKATRAM027/Medical-RAG-Chatbot.git
cd Medical-RAG-Chatbot

2. Create a Virtual Environment

Windows

python -m venv venv
venv\Scripts\activate

macOS / Linux

python3 -m venv venv
source venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Configure Environment Variables

Create a .env file in the project root.

EURI_API_KEY=your_actual_api_key_here

You can also copy the provided example configuration:

cp .env.example .env

Then edit .env and add your API key.

๐Ÿ” Security: Never commit your .env file or expose your API key publicly. The repository should contain only .env.example with placeholder values.


5. Run the Application

streamlit run main.py

The application will normally be available at:

http://localhost:8501

๐Ÿ“ Project Structure

Medical-RAG-Chatbot/
โ”‚
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ chat_utils.py
โ”‚   โ”œโ”€โ”€ config.py
โ”‚   โ”œโ”€โ”€ pdf_utils.py
โ”‚   โ”œโ”€โ”€ ui.py
โ”‚   โ””โ”€โ”€ vectorstore_utils.py
โ”‚
โ”œโ”€โ”€ assets/
โ”‚   โ”œโ”€โ”€ demo.gif
โ”‚   โ”œโ”€โ”€ chatbot-ui.png
โ”‚   โ”œโ”€โ”€ retrieved-context.png
โ”‚   โ””โ”€โ”€ architecture.png
โ”‚
โ”œโ”€โ”€ main.py
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ .env.example
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ LICENSE
โ””โ”€โ”€ README.md

Main Components

File Purpose
main.py Application entry point and overall orchestration
app/chat_utils.py LLM initialization and response generation
app/config.py Environment variable and application configuration
app/pdf_utils.py PDF text extraction and processing
app/ui.py Streamlit UI components
app/vectorstore_utils.py FAISS index creation and similarity search
requirements.txt Python package dependencies
.env.example Environment-variable template

โš™๏ธ Configuration

Important parameters can be configured in the application code.

Parameter Location Default Description
chunk_size main.py 1000 Maximum number of characters per chunk
chunk_overlap main.py 200 Number of overlapping characters between chunks
EURI_API_KEY .env โ€” Authentication key for EURI API

Retrieval depth and LLM-related parameters can be adjusted in the corresponding files under app/.


๐Ÿ–ผ๏ธ Screenshots

Chatbot Interface

Retrieved Context

RAG Architecture


๐Ÿ’ฌ Usage

1. Upload Documents

Upload one or more medical PDF documents using the sidebar.

The application extracts the text, splits it into chunks, creates embeddings, and builds the FAISS index.

2. Ask a Question

Enter a question related to the uploaded documents.

Example:

What are the contraindications mentioned in the uploaded document?

3. Retrieve Relevant Context

The application performs semantic similarity search and retrieves the most relevant document chunks.

4. Generate the Answer

The retrieved chunks are passed to the LLM as contextual information.

5. Inspect the Retrieval

Use View Retrieved Context to inspect the document content retrieved for the query.


๐Ÿ”ฌ Example RAG Pipeline

Medical PDF
     โ†“
Text Extraction
     โ†“
Recursive Chunking
     โ†“
Embedding Generation
     โ†“
FAISS Vector Index
     โ†“
User Query
     โ†“
Query Embedding
     โ†“
Similarity Search
     โ†“
Top Relevant Chunks
     โ†“
Context Injection
     โ†“
EURI LLM
     โ†“
Generated Response

๐Ÿ“Š Current Limitations

This project is currently designed as a lightweight prototype and has some limitations:

  • FAISS indices are created in memory during the session
  • Documents may need to be re-indexed after restarting the application
  • Source-level citations such as PDF filename and page number are not yet implemented
  • Retrieval quality depends on document quality, chunking strategy, embeddings, and retrieval parameters
  • LLM responses may still contain inaccuracies
  • The system should not be used for real-world diagnosis or treatment decisions

๐Ÿ”ฎ Future Improvements

  • Persistent FAISS Index โ€” Save and reload vector indices between sessions
  • Source Citations โ€” Display PDF filename and page number for retrieved chunks
  • Improved Retrieval โ€” Experiment with hybrid search, reranking, and better retrieval strategies
  • Chat History โ€” Support multi-turn conversations with conversation context
  • Multi-Model Support โ€” Add configurable LLM providers such as EURI, OpenAI, or local models
  • Document Preview โ€” Preview uploaded PDFs inside the application
  • Metadata Filtering โ€” Filter retrieval results by document or other metadata
  • Evaluation Pipeline โ€” Measure retrieval and answer quality using RAG evaluation metrics
  • Docker Support โ€” Containerized deployment for easier setup
  • Cloud Deployment โ€” Deploy the application for public demonstration

๐ŸŽฏ Learning Outcomes

Through this project, I gained hands-on experience with:

  • Retrieval-Augmented Generation
  • Vector databases and similarity search
  • FAISS
  • Document preprocessing
  • Embeddings
  • LangChain
  • LLM integration
  • Prompt construction
  • Streamlit application development
  • Environment-variable based secret management
  • Building an end-to-end GenAI application

๐Ÿ›ก๏ธ Responsible AI & Medical Safety

This application is a technical demonstration of RAG and document-based question answering.

It should not be treated as:

  • A medical diagnosis system
  • A clinical decision-support system
  • A substitute for a doctor
  • A source of personalized medical treatment
  • A validated medical device

Always verify important medical information with qualified healthcare professionals and authoritative medical sources.


๐Ÿค Contributing

Contributions, suggestions, and improvements are welcome.

Contribution Workflow

# Fork the repository

git clone https://github.com/VENKATRAM027/Medical-RAG-Chatbot.git

cd Medical-RAG-Chatbot

git checkout -b feature/your-feature

# Make your changes

git add .

git commit -m "Add your feature"

git push origin feature/your-feature

Then open a Pull Request on GitHub.


๐Ÿ“œ License

This project is licensed under the MIT License.

See the LICENSE file for more information.


๐Ÿ™ Acknowledgments

  • LangChain โ€” RAG and LLM application framework
  • FAISS โ€” Efficient vector similarity search
  • Streamlit โ€” Interactive Python web application framework
  • EURI โ€” LLM API integration

๐Ÿ‘จโ€๐Ÿ’ป Author

Venkatram

GitHub: @VENKATRAM027

Project: Medical RAG Chatbot


โญ If you found this project useful, consider giving it a star!

Built with Python โ€ข LangChain โ€ข FAISS โ€ข Streamlit โ€ข Generative AI

About

Medical document Q&A chatbot using Retrieval-Augmented Generation (RAG), FAISS vector search, LangChain, Streamlit, and EURI LLM API.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages