Skip to content

param20h/PDF-Assistant-RAG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“„ RAG PDF Assistant

A Retrieval-Augmented Generation (RAG) document assistant built with Flask, Pinecone, Gemini Embeddings, Groq API, and Google Gemini. Upload PDFs, DOCX, TXT, or MD files and intuitively chat with them using modern AI models.


πŸš€ Features

  • πŸ“‚ Multi-format Uploads: Support for PDF, DOCX, TXT, and Markdown files.
  • πŸ’¬ Interactive Chat: Query and chat with your documents using AI.
  • πŸ” RAG-based Retrieval: Fast and accurate semantic search using Pinecone vector database.
  • 🧠 Multiple LLM Support: Powered by Groq API (Llama 3) and Google Gemini.
  • πŸ” Robust Authentication: Supports Google OAuth as well as standard Email/Password login.
  • πŸ–ΌοΈ User Profiles: Custom profile picture uploads & Google profile pic sync.
  • πŸ‘€ Data Isolation: Per-user namespaces in Pinecone for complete privacy.
  • πŸ›‘οΈ Admin Dashboard: Admin panel to monitor users and uploaded files.
  • πŸ—‘οΈ Data Management: Intuitive UI to delete files and clear vector stores.
  • πŸ“± Responsive UI: Minimal and modern front-end for seamless user experience.
  • ☁️ Lightweight & Cloud-Native: Zero local ML models β€” all embeddings and LLM calls are cloud-based API calls, requiring minimal server RAM.

πŸ› οΈ Tech Stack

Layer Technology
Backend Flask (Python)
Authentication Flask-Login + Flask-Dance (Google OAuth)
Embeddings Google Gemini (gemini-embedding-001)
Vector Store Pinecone (Serverless)
LLMs Groq API (Llama 3.3 70B) & Google Gemini
User Database MongoDB Atlas
Frontend HTML, CSS, Vanilla JS

πŸ“ Project Structure

RAG_App/
β”œβ”€β”€ app.py                  # Main Flask application & routes
β”œβ”€β”€ models.py               # MongoDB user model & encrypted key storage
β”œβ”€β”€ config.py               # Configuration & env variables
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ render.yaml             # Render deployment blueprint
β”œβ”€β”€ Dockerfile              # Docker containerization
β”œβ”€β”€ .env.example            # Environment variable template
β”œβ”€β”€ rag/
β”‚   β”œβ”€β”€ chunker.py          # Document parsing & chunking logic
β”‚   β”œβ”€β”€ embeddings.py       # Gemini embeddings + Pinecone upsert
β”‚   β”œβ”€β”€ retriever.py        # Pinecone semantic search & retrieval
β”‚   └── generator.py        # LLM integration for answer generation
β”œβ”€β”€ templates/
β”‚   β”œβ”€β”€ index.html          # File management & upload dashboard
β”‚   β”œβ”€β”€ chat.html           # RAG chat interface
β”‚   β”œβ”€β”€ login.html          # User login page
β”‚   β”œβ”€β”€ register.html       # User registration page
β”‚   β”œβ”€β”€ admin.html          # Admin dashboard
β”‚   └── profile.html        # User profile & API key settings
β”œβ”€β”€ static/                 # Static assets (CSS, JS, profile_pics)
β”œβ”€β”€ uploads/                # User-uploaded files (isolated per user)
└── .github/workflows/
    β”œβ”€β”€ devsecops.yml       # Security scanning pipeline
    └── deploy.yml          # Docker build & GHCR push pipeline

βš™οΈ Setup & Installation

1. Clone the Repository

git clone https://github.com/param20h/PDF-Assistant-RAG.git
cd PDF-Assistant-RAG

2. Create and Activate Virtual Environment

python -m venv .venv

# Windows
.venv\Scripts\activate

# Linux/Mac
source .venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Configure Environment Variables

Create a .env file using the template:

cp .env.example .env

Fill in the required server-side variables:

SECRET_KEY=<your-secret-key>
ENCRYPTION_KEY=<your-fernet-key>
MONGO_URI=<your-mongodb-atlas-uri>
GOOGLE_CLIENT_ID=<your-google-client-id>
GOOGLE_CLIENT_SECRET=<your-google-client-secret>

Generate keys:

# SECRET_KEY
python -c "import secrets; print(secrets.token_hex(32))"
# ENCRYPTION_KEY
python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"

5. Run the Application

python app.py

6. Access in Browser

Visit http://localhost:5000 in your web browser.


πŸ”‘ User Setup (Per-User API Keys)

After registering/logging in, each user must add their own API keys on the Profile page:

Service Required? Where to Get Notes
Gemini API Key βœ… Required aistudio.google.com Free β€” used for embeddings & chat
Pinecone API Key βœ… Required app.pinecone.io Free tier available
Pinecone Index Name βœ… Required Pinecone Dashboard Create: dim 3072, metric cosine
Groq API Key Optional console.groq.com For Llama 3 chat generation

🌲 Pinecone Index Setup

  1. Create a free account at pinecone.io
  2. Create a Serverless index with:
    • Dimension: 3072
    • Metric: cosine
  3. Copy your API key and index name into the Profile page

🌐 Google OAuth Setup

  1. Go to Google Cloud Console β†’ console.cloud.google.com
  2. Create a new project and navigate to APIs & Services β†’ Credentials
  3. Click Create Credentials β†’ OAuth Client ID
  4. Set the Authorized redirect URI to: http://localhost:5000/login/google/authorized
  5. Copy your Client ID and Client Secret into the .env file

πŸ”„ How It Works (The RAG Pipeline)

  1. Upload: User uploads a document (PDF, DOCX, TXT, or MD).
  2. Chunking: The document is parsed and split into manageable textual chunks.
  3. Embedding: Chunks are converted to 3072-dimensional vectors using gemini-embedding-001.
  4. Vector Storage: Vectors are stored in the user's Pinecone namespace.
  5. Querying: The user submits a question.
  6. Retrieval: Pinecone retrieves the most semantically relevant chunks.
  7. Generation: The retrieved context is passed to the selected LLM (Groq or Gemini) to generate an accurate, grounded answer.

πŸš€ Deployment

Deploy to Render (Recommended β€” Free)

  1. Push your code to GitHub
  2. Go to Render β†’ New β†’ Web Service
  3. Connect your GitHub repository
  4. Render auto-detects render.yaml and configures everything
  5. Add environment variables: SECRET_KEY, ENCRYPTION_KEY, MONGO_URI, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET
  6. Update Google OAuth redirect URI to: https://your-app.onrender.com/login/google/authorized
  7. Deploy!

Deploy with Docker

docker build -t rag-app .
docker run -p 5000:5000 --env-file .env rag-app

πŸ” DevSecOps Pipeline

Tool Purpose
GitHub Actions CI/CD Pipeline
Bandit SAST β€” Python security vulnerability scanning
Gitleaks Hardcoded secret and credential detection
Trivy Container and dependency vulnerability checking
Snyk Advanced dependency vulnerability scanning
OWASP ZAP DAST β€” Dynamic web security scanning
SonarCloud Overall code quality and security analysis
GHCR Docker image hosting via GitHub Container Registry

πŸ‘¨β€πŸ’» Author

  • Name: Paramjit Singh (param20h)

πŸ“„ License

This project is licensed under the MIT License. Check the LICENSE file for more details.


⭐ Show Some Support!

If you found this project helpful or inspiring, please give it a ⭐!

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors