Skip to content

Latest commit

Β 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🩺 Medical AI Assistant

A Retrieval-Augmented Generation (RAG) based Medical AI Assistant that allows users to upload medical PDF documents, index them into a vector database, and ask natural language questions to retrieve accurate answers grounded in the uploaded content.

The system combines document retrieval, semantic search, vector embeddings, and Large Language Models (LLMs) to provide context-aware responses from medical documents.


πŸš€ Features

  • Upload one or multiple PDF medical documents
  • Automatic document chunking and preprocessing
  • Generate vector embeddings using Google's Embedding Models
  • Store embeddings in Pinecone Vector Database
  • Semantic similarity search for relevant document retrieval
  • AI-powered question answering using LLMs
  • FastAPI backend
  • Streamlit frontend
  • Scalable Retrieval-Augmented Generation (RAG) architecture

πŸ“Œ Project Architecture

User Uploads PDF
        β”‚
        β–Ό
Document Loader (PyPDF)
        β”‚
        β–Ό
Text Chunking
(Chunk Size + Chunk Overlap)
        β”‚
        β–Ό
Google Embedding Model
(gemini-embedding-001)
        β”‚
        β–Ό
Vector Embeddings
        β”‚
        β–Ό
Pinecone Vector Database
        β”‚
        β–Ό
────────────────────────────
User Asks Question
────────────────────────────
        β”‚
        β–Ό
Question Embedding
        β”‚
        β–Ό
Similarity Search in Pinecone
        β”‚
        β–Ό
Relevant Document Chunks
        β”‚
        β–Ό
LLM (Groq / Llama)
        β”‚
        β–Ό
Generated Answer
        β”‚
        β–Ό
User Interface

🧠 How RAG Works in This Project

1. Document Upload

Users upload medical PDF documents through the API or Streamlit interface.

2. Document Chunking

Documents are split into smaller chunks to improve retrieval quality.

Configuration:

chunk_size = 500
chunk_overlap = 100

3. Embedding Generation

Each chunk is converted into a numerical vector representation using Google's Embedding Model.

Current Model:

gemini-embedding-001

These embeddings capture semantic meaning rather than simple keyword matching.

4. Vector Storage

Generated embeddings are stored in Pinecone.

Benefits:

  • Fast similarity search
  • Scalable storage
  • Cloud-hosted vector database
  • Suitable for production deployment

5. User Query Processing

When a user asks a question:

  1. The question is converted into an embedding.
  2. Pinecone retrieves the most similar document chunks.
  3. Retrieved chunks become the context for the LLM.

6. Answer Generation

The LLM receives:

  • User question
  • Retrieved context
  • Prompt instructions

The model generates a grounded answer based on the uploaded medical documents.


πŸ—οΈ Technology Stack

Backend

  • FastAPI
  • Python
  • LangChain

Frontend

  • Streamlit

Embedding Model

  • Google Generative AI
  • gemini-embedding-001

Vector Database

  • Pinecone

Large Language Model

  • Groq Hosted Llama Models

Examples:

  • Llama 3.3 70B Versatile
  • Llama 3.1 8B Instant

πŸ“‚ Project Structure

Medical_AI_Assistant/
β”‚
β”œβ”€β”€ client/
β”‚   β”œβ”€β”€ app.py
β”‚   └── ...
β”‚
β”œβ”€β”€ server/
β”‚   β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ main.py
β”‚   └── ...
β”‚
β”œβ”€β”€ uploaded_docs/
β”‚
β”œβ”€β”€ .env
β”œβ”€β”€ requirements.txt
└── README.md

βš™οΈ Installation

1. Clone Repository

git clone <repository-url>
cd Medical_AI_Assistant

2. Create Virtual Environment

python -m venv .venv

3. Activate Virtual Environment

Windows

.venv\Scripts\activate

Linux / Mac

source .venv/bin/activate

4. Install Dependencies

pip install -r requirements.txt

πŸ”‘ Environment Variables

Create a .env file in the root directory.

GOOGLE_API_KEY=your_google_api_key

PINECONE_API_KEY=your_pinecone_api_key

GROQ_API_KEY=your_groq_api_key

▢️ Running the Backend

Navigate to the server directory:

cd server

Start FastAPI:

uvicorn main:app --reload

Backend will run on:

http://localhost:8000

▢️ Running the Frontend

Navigate to the client directory:

cd client

Start Streamlit:

streamlit run app.py

Frontend will run on:

http://localhost:8501

πŸ“‘ API Endpoints

Upload PDF Documents

POST

/upload-pdfs/

Uploads and indexes PDF documents into Pinecone.

Example Response

{
  "message": "Documents uploaded and indexed successfully"
}

Ask Questions

POST

/ask/

Request

{
  "question": "What is diabetes?"
}

Response

{
  "answer": "Diabetes is a chronic condition..."
}

πŸ§ͺ Testing

Upload PDFs

Upload one or more medical PDF files through:

  • Swagger UI
  • Postman
  • Streamlit Interface

Ask Questions

After indexing documents:

What is diabetes?

What are the symptoms of hypertension?

What treatment options are available?

The assistant retrieves relevant information from the uploaded documents and generates context-aware answers.


πŸ“Έ Application Screenshots

Upload Documents

Upload Documents

Upload Documents Response


Ask Questions

Ask Question

Ask Question Response


Streamlit Application

Streamlit UI


About

Medical AI Assistant: is a RAG-based application that lets users upload medical PDFs and ask questions, using Google Embeddings, Pinecone, and LLMs to deliver context-aware answers.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages