A production-ready Retrieval-Augmented Generation (RAG) system that allows users to upload PDF documents, automatically index and embed their content, and ask natural language questions to retrieve precise answers based only on the uploaded documents.
This project implements a complete dual-service architecture: a fast and robust FastAPI backend API that handles PDF parsing, semantic chunking, database storage, and retrieval-augmented generation, coupled with an interactive Streamlit frontend for user-friendly document management and Q&A.
The application is built using modern AI and web technologies:
- Frontend: Streamlit – Provides a clean, interactive user interface for uploading PDFs and asking questions.
- Backend API: FastAPI – High-performance asynchronous API framework to handle uploads, retrieval pipelines, and model calls.
- LLM Orchestration: LangChain – Powers the ingestion pipeline, text splitting, prompt management, and LLM chains.
- Vector Database: Chroma DB – High-performance, developer-friendly vector store for saving and querying document chunk embeddings.
- Text Embeddings: Hugging Face (
sentence-transformers/all-MiniLM-L6-v2) – Embeds text chunks locally into 384-dimensional vectors. - Large Language Model (LLM): Groq API – Utilizes the state-of-the-art Llama 3.3 70B Versatile model for high-accuracy, low-latency responses.
- PDF Processing:
PyPDFLoader– Parses text from uploaded PDF documents. - Containerization: Docker – Package the FastAPI backend service for seamless deployments.
rag-qa-system/
│
├── data/ # Local folder where uploaded PDFs are stored (git-ignored)
├── chroma_db/ # SQLite/ChromaDB vector persistence directory (git-ignored)
│
├── src/ # Source Code
│ ├── __init__.py # Package initialization & path resolution
│ ├── app.py # Streamlit Frontend UI
│ ├── main.py # FastAPI Backend API Server
│ ├── ingest.py # PDF Document Ingestion & Chunking Logic
│ ├── embed_store.py # Embedding Generation & ChromaDB Storage
│ ├── retrieve.py # Vector Store Loading & Similarity Search
│ └── generate.py # LLM Invocation & Context-based Q&A Generation
│
├── tests/ # Unit and integration tests folder
├── Dockerfile # Docker container configuration for backend service
├── .dockerignore # Docker build exclusion patterns
├── .gitignore # Git exclusion rules
├── .env.example # Template for environment configuration
├── requirements.txt # Python dependencies list
└── README.md # Detailed project documentation
The RAG pipeline operates in two distinct phases:
graph TD
A[Upload PDF via Streamlit UI] --> B[FastAPI Endpoint: /upload]
B --> C[Save PDF to data/ folder]
C --> D[Load & Extract Text via PyPDFLoader]
D --> E[Chunk Text recursively chunk_size=1000, overlap=200]
E --> F[Generate Embeddings via sentence-transformers]
F --> G[Save Vectors and Metadata to ChromaDB]
graph TD
A[User enters query in UI] --> B[FastAPI Endpoint: /ask?query=...]
B --> C[Generate Query Embedding]
C --> D[Query ChromaDB for Top-4 similar chunks]
D --> E[Construct Prompt with Context + Query]
E --> F[Send to Groq Llama 3.3 70B]
F --> G[Retrieve Answer]
G --> H[Return Answer to Streamlit UI]
Follow these steps to run the project locally.
Ensure you have the following installed:
- Python 3.11 or higher
- A Groq API Key (Get one from Groq Console)
git clone https://github.com/vivekducs/docs-rag.git
cd docs-ragOn Windows (PowerShell):
python -m venv .venv
.venv\Scripts\Activate.ps1On macOS/Linux:
python3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txtCreate a .env file in the root directory:
cp .env.example .envOpen the .env file and enter your API keys:
GROQ_API_KEY=your_groq_api_key_hereTo run the application, you need to start both the Backend (FastAPI) and the Frontend (Streamlit).
Start the FastAPI server on port 8000:
uvicorn src.main:app --reload --host 127.0.0.1 --port 8000- The interactive API documentation will be available at: http://127.0.0.1:8000/docs
Open a new terminal window, activate the virtual environment, and run:
streamlit run src/app.py- The UI will open automatically in your browser at: http://localhost:8501
You can containerize the backend API using Docker:
docker build -t rag-qa-system .Pass the environment variables file .env during execution:
docker run -d -p 8000:8000 --env-file .env --name rag-backend rag-qa-systemThe FastAPI service will be running on http://localhost:8000.