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.
- 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
- Python
- FastAPI
- Pydantic
- LangChain
- ChromaDB
- Mistral AI
- PyPDFLoader
- RecursiveCharacterTextSplitter
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
git clone https://github.com/maroofiums/PDF-RAG-System.git
cd PDF-RAG-Systempython -m venv .venvWindows:
.venv\Scripts\activateLinux / Mac:
source .venv/bin/activatepip install -r requirements.txtCreate a .env file in the project root.
MISTRAL_API_KEY=your_api_key_hereuvicorn app.main:app --reloadApplication:
http://127.0.0.1:8000
Swagger Documentation:
http://127.0.0.1:8000/docs
GET /Response:
{
"message": "Welcome to PDF RAG System"
}POST /uploadUploads a PDF file and automatically indexes it into the vector database.
POST /askRequest:
{
"question": "What is GRU?"
}Response:
{
"answer": "GRU is a type of recurrent neural network...",
"sources": [
{
"source": "GRU.pdf",
"page": 1
}
]
}- User uploads a PDF.
- PDF is loaded using PyPDFLoader.
- Text is split into chunks.
- Chunks are converted into embeddings.
- Embeddings are stored in ChromaDB.
- User asks a question.
- Relevant chunks are retrieved using MMR.
- Retrieved context is passed to Mistral AI.
- Answer is generated strictly from document content.
- Sources and page numbers are returned with the answer.
- Multi-PDF support
- Chat history memory
- Hybrid search (BM25 + Vector Search)
- Re-ranking models
- Streaming responses
- User authentication
- React frontend
- Docker deployment
- Cloud deployment
This project demonstrates:
- Retrieval-Augmented Generation (RAG)
- Vector Databases
- Embeddings
- FastAPI Development
- REST API Design
- Prompt Engineering
- Document Question Answering
- LangChain Fundamentals