CoolFace
Apppublic

salvirezwan/Research-Paper-RAG-chatbot

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

Research Paper RAG Chatbot

An AI-powered agentic RAG (Retrieval-Augmented Generation) system for students and researchers. Upload research papers or fetch them live from arXiv, then query across them in natural language with cited, context-aware responses — streamed in real time.

Live Demo: Hugging Face Spaces


Features

  • —Upload PDFs — ingest your own research papers with a 4-step checkpointed pipeline
  • —Fetch from arXiv — download and index papers directly by arXiv ID
  • —Agentic RAG pipeline — LangGraph StateGraph with adaptive routing, document grading, and cited answer generation
  • —Real-time streaming — chat responses streamed via Server-Sent Events (SSE)
  • —Session isolation — each browser session has its own paper library and vector search scope
  • —PDF Viewer — read papers in-browser with page navigation

Architecture

RAG Pipeline (LangGraph StateGraph)

User Query → Router → [retrieve | live_fetch] → grade_docs → generator → citation → END
NodeFileDescription
Routernodes/router.pyLLM classifies query as "retrieve" or "live_fetch"
Retrievenodes/retrieve.pySearches local ChromaDB; scoped to session's papers
Live Fetchnodes/live_fetch.pyFetches from arXiv, indexes chunks
Grade Docsnodes/grade_docs.pyLLM grades each chunk as relevant/irrelevant
Generatornodes/generator.pyBuilds context, calls Groq LLM, returns cited answer
Citationnodes/citation.pyAppends formatted Sources block with arXiv/DOI links

Ingestion Pipeline (4-step, checkpointed)

PDF → Parse (PyMuPDF) → Clean → Chunk → Embed (BAAI/bge-base-en-v1.5) → ChromaDB

Each step is checkpointed in MongoDB. Retrying a failed ingestion skips already-completed steps.

Storage

StorePurpose
ChromaDBVector embeddings for semantic search
MongoDBPaper records, ingestion checkpoints, request logs
Local diskUploaded PDF files (uploads/documents/, uploads/arxiv/)

API Routes

EndpointDescription
POST /api/v1/chatSSE streaming chat
POST /api/v1/uploadUpload a PDF
GET /api/v1/papersList papers (session-scoped)
DELETE /api/v1/papers/{id}Delete a paper
POST /api/v1/papers/fetch/arxiv/{id}Fetch & index an arXiv paper
GET /api/v1/uploads/{id}/viewServe PDF for viewer
GET /api/v1/healthHealth check

Quick Start (Local)

Prerequisites

  • —Python 3.11+
  • —MongoDB running on localhost:27017
  • —uv (recommended) or pip

1. Clone the repo

bash
git clone https://github.com/salvirezwan/Research-Paper-RAG-chatbot.git
cd "Research-Paper-RAG-chatbot/Academic Research RAG"

2. Install dependencies

bash
# Using uv (recommended)
pip install uv
uv sync

# Or using pip
pip install -r requirements.txt

3. Configure environment

bash
cp .env.example .env

Edit .env:

env
GROQ_API_KEY=your_groq_api_key_here
MONGODB_URL=mongodb://localhost:27017
MONGODB_DATABASE_NAME=academic_research_rag
CHROMA_PERSIST_PATH=./data/chroma_db
CHROMA_COLLECTION_NAME=research_papers
GROQ_MODEL=llama-3.3-70b-versatile
EMBED_MODEL_NAME=BAAI/bge-base-en-v1.5
UPLOAD_DIR=uploads/documents
Get a free Groq API key at console.groq.com

4. Run

bash
# Option A — dev shortcut (Windows, opens two terminals)
.\dev.bat

# Option B — manual
python -m uvicorn backend.main:app --host 0.0.0.0 --port 8000 --reload
streamlit run frontend/app.py
  • —Backend: http://localhost:8000
  • —Frontend: http://localhost:8501
  • —API Docs: http://localhost:8000/docs

Docker (Full Stack)

bash
docker compose -f docker/docker-compose.yml up --build
  • —Frontend: http://localhost:8501
  • —Backend: http://localhost:8000

Hugging Face Spaces Deployment

The app runs as a single Docker container on a free HF Space (2 vCPU / 16 GB RAM).

Process layout

supervisord (PID 1)
├── nginx        → port 7860  (reverse proxy)
│   ├── /api/*  → 127.0.0.1:8000  (FastAPI)
│   └── /*      → 127.0.0.1:8501  (Streamlit)
├── uvicorn      → port 8000
└── streamlit    → port 8501

Ephemeral storage

Since HF Spaces has no persistent disk, the app uses:

  • —ChromaDB EphemeralClient (in-memory vectors)
  • —mongomock-motor AsyncMongoMockClient (in-memory MongoDB)
  • —/tmp/uploads/ for uploaded files
All data is lost on restart — expected behaviour for the free tier.

Deploy your own

  1. 1.Create a new Space at huggingface.co → Docker SDK
  2. 2.Push this repo to the Space's git remote
  3. 3.Space Settings → Secrets: add GROQ_API_KEY
  4. 4.Space Settings → Variables: add APP_PUBLIC_URL = https://<your-username>-<your-space-name>.hf.space
  5. 5.First startup takes ~5 min (downloads the ~450 MB embedding model)

Environment Variables

VariableDefaultDescription
GROQ_API_KEY—Required. Groq API key
MONGODB_URLmongodb://localhost:27017MongoDB connection string
MONGODB_DATABASE_NAMEacademic_research_ragDatabase name
CHROMA_PERSIST_PATH./data/chroma_dbChromaDB storage path
CHROMA_COLLECTION_NAMEresearch_papersChromaDB collection
GROQ_MODELllama-3.3-70b-versatileGroq model ID
EMBED_MODEL_NAMEBAAI/bge-base-en-v1.5HuggingFace embedding model
UPLOAD_DIRuploads/documentsPDF upload directory
APP_PUBLIC_URL``Public base URL (required for HF Spaces)

Tech Stack

LayerTechnology
LLMGroq API (LLaMA-3.3-70B)
OrchestrationLangGraph
BackendFastAPI, Python 3.11
FrontendStreamlit
Vector StoreChromaDB
EmbeddingsBAAI/bge-base-en-v1.5 (HuggingFace)
DatabaseMongoDB (Motor async)
PDF ParsingPyMuPDF, Unstructured
DeploymentDocker, nginx, supervisord, Hugging Face Spaces
Paper SourcesarXiv API