Skip to content

maroofiums/PDF-RAG-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDF RAG System

A Retrieval-Augmented Generation (RAG) application built with FastAPI, LangChain, ChromaDB, and Mistral AI. The system allows users to upload PDF documents, create vector embeddings, and ask questions grounded in the uploaded documents.

Features

  • Upload PDF documents through API
  • Automatic PDF parsing and text extraction
  • Intelligent text chunking
  • Vector embeddings using Mistral AI
  • ChromaDB vector database
  • MMR (Maximal Marginal Relevance) retrieval
  • Context-aware question answering
  • Source tracking and page references
  • FastAPI REST API
  • Interactive Swagger documentation

Tech Stack

Backend

  • Python
  • FastAPI
  • Pydantic

RAG Pipeline

  • LangChain
  • ChromaDB
  • Mistral AI
  • PyPDFLoader
  • RecursiveCharacterTextSplitter

Project Structure

PDF-RAG-System/
│
├── app/
│   ├── main.py
│   ├── rag.py
│   ├── schemas.py
│   ├── vector_stores.py
│   ├── ingest.py
│   └── __init__.py
│
├── data/
│   └── XXX.pdf
│
├── chroma-db/
│
├── .gitignore
├── LICENSE
├── requirements.txt
└── README.md

Installation

Clone Repository

git clone https://github.com/maroofiums/PDF-RAG-System.git
cd PDF-RAG-System

Create Virtual Environment

python -m venv .venv

Activate Environment

Windows:

.venv\Scripts\activate

Linux / Mac:

source .venv/bin/activate

Install Dependencies

pip install -r requirements.txt

Environment Variables

Create a .env file in the project root.

MISTRAL_API_KEY=your_api_key_here

Run Application

uvicorn app.main:app --reload

Application:

http://127.0.0.1:8000

Swagger Documentation:

http://127.0.0.1:8000/docs

API Endpoints

Home

GET /

Response:

{
  "message": "Welcome to PDF RAG System"
}

Upload PDF

POST /upload

Uploads a PDF file and automatically indexes it into the vector database.

Ask Questions

POST /ask

Request:

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

Response:

{
  "answer": "GRU is a type of recurrent neural network...",
  "sources": [
    {
      "source": "GRU.pdf",
      "page": 1
    }
  ]
}

How It Works

  1. User uploads a PDF.
  2. PDF is loaded using PyPDFLoader.
  3. Text is split into chunks.
  4. Chunks are converted into embeddings.
  5. Embeddings are stored in ChromaDB.
  6. User asks a question.
  7. Relevant chunks are retrieved using MMR.
  8. Retrieved context is passed to Mistral AI.
  9. Answer is generated strictly from document content.
  10. Sources and page numbers are returned with the answer.

Future Improvements

  • Multi-PDF support
  • Chat history memory
  • Hybrid search (BM25 + Vector Search)
  • Re-ranking models
  • Streaming responses
  • User authentication
  • React frontend
  • Docker deployment
  • Cloud deployment

Learning Outcomes

This project demonstrates:

  • Retrieval-Augmented Generation (RAG)
  • Vector Databases
  • Embeddings
  • FastAPI Development
  • REST API Design
  • Prompt Engineering
  • Document Question Answering
  • LangChain Fundamentals

About

Production-ready PDF RAG system built with FastAPI, LangChain, ChromaDB, and Mistral AI for document-grounded question answering.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages