Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RAG API

A Retrieval-Augmented Generation API built with FastAPI, ChromaDB, and Google Gemini.

What it does

Upload PDF documents, ask questions in natural language, get answers grounded in your documents, with source citations showing exactly which page and document the answer came from.

Tech Stack

  • FastAPI : REST API framework
  • PyMuPDF : PDF text extraction
  • LangChain Text Splitters : Recursive character chunking
  • ChromaDB : Vector store (persistent)
  • Google Gemini : Embeddings (gemini-embedding-001) and generation (gemini-2.5-flash)

Setup

Prerequisites

Local Setup

git clone <your-repo-url>
cd rag-api
python -m venv venv
venv\Scripts\activate  # Windows
pip install -r requirements.txt

Create a .env file:

GEMINI_API_KEY=your_api_key_here

Run the server:

cd app
uvicorn main:app --reload

Visit http://localhost:8000/docs for the interactive API.

Docker Setup

docker-compose up --build

Visit http://localhost:8000/docs

API Endpoints

Endpoint Method Description
/upload POST Upload a PDF document
/query POST Ask a question, get answer + sources
/documents GET List all uploaded documents
/health GET Health check

Usage

Upload a document:

curl -X POST http://localhost:8000/upload \
  -F "file=@your_document.pdf"

Ask a question:

curl -X POST http://localhost:8000/query \
  -H "Content-Type: application/json" \
  -d '{"question": "What is the main topic of the document?"}'

Response includes answer + sources:

{
  "answer": "The document covers...",
  "sources": [
    {
      "filename": "document.pdf",
      "page": 3,
      "relevance_score": 0.87,
      "excerpt": "..."
    }
  ]
}

Pipeline Overview

Ingestion: PDF → Text Extraction → Chunking (500 tokens, 50 overlap) → Embedding → ChromaDB

Query: Question → Embedding → Semantic Search (top-5) → Prompt Construction → Gemini → Answer + Sources

AWS EC2 Deployment

  1. Launch EC2 instance (t3.small, Ubuntu 22.04)
  2. Open port 8000 in security group
  3. Install Docker:
sudo apt update && sudo apt install -y docker.io docker-compose
sudo systemctl start docker
  1. Clone repo and deploy:
git clone <your-repo-url>
cd rag-api
echo "GEMINI_API_KEY=your_key" > .env
docker-compose up -d

API will be available at http://<ec2-public-ip>:8000

Live Demo

http://13.233.253.36:8000

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages