A retrieval-augmented generation (RAG) system for answering questions over a corpus of financial/enterprise PDF documents, with grounded, citation-backed answers that deep-link back to the exact source page.
Currently indexed with a set of Reliance Industries Ltd. filings (annual reports, board statements, financial disclosures).
Ingestion (POST /ingest):
PDF → Docling parse (layout + OCR) → hierarchical chunker → chunk summarizer
→ dual embedding (BGE-M3: content + summary) → Qdrant (named vectors)
Query (POST /query, POST /query/stream):
query → hybrid retrieval (dense-text + dense-summary + BM25, RRF-fused)
→ BGE cross-encoder reranking
→ citation assignment
→ context assembly (token-budgeted)
→ LLM generation
→ citation validation (rejects hallucinated citations)
Every citation carries the exact source text it was grounded on and a link to the original PDF, opened at the correct page (#page=N).
| Layer | Technology |
|---|---|
| API | FastAPI + Uvicorn |
| Document parsing | Docling (layout analysis + RapidOCR) |
| Embeddings | BAAI/bge-m3 (dense, 1024-dim, dual named vectors) |
| Vector store | Qdrant (HNSW + INT8 scalar quantization) |
| Sparse retrieval | BM25 (rank-bm25) |
| Reranking | BAAI/bge-reranker-v2-m3 (cross-encoder) |
| Generation | Ollama (OpenAI-compatible local endpoint) |
| Frontend | React 19 + Vite |
backend/
ingestion/ Docling parsing, document registry (SHA-256 dedup)
chunking/ hierarchical chunker + chunk summarizer
embeddings/ BGE-M3 embedder + embedding pipeline
vectorstore/ Qdrant client, collection management, indexing
retrieval/ dense / BM25 / hybrid (RRF) retrievers
reranking/ BGE cross-encoder reranker
context/ token-budgeted context assembly
citations/ citation assignment + hallucination validation
generation/ prompt building + LLM client
api/ FastAPI app, routers (query, ingest)
frontend/ React chat UI
scripts/ start_qdrant.sh, start_api.sh, download_tax_docs.py
data/ tax_docs (raw PDFs), documents (permanent citation source
store), bm25_index, document_registry.json
Prerequisites: Python 3.12+, Node.js, Ollama, a Qdrant binary (or Docker).
git clone <this repo>
cd ProductionGradeRAG
python3 -m venv venv && source venv/bin/activate
pip install -r requirements.txt
cp .env.example .env # adjust as needed# 1. Qdrant
bash scripts/start_qdrant.sh
# 2. Ollama
ollama serve
ollama pull qwen3:8b # or whichever GENERATION_MODEL you set in .env
# 3. API
source venv/bin/activate
bash scripts/start_api.shCheck it's up: curl localhost:8080/health
cd frontend
npm install
npm run devcurl -F file=@path/to/document.pdf http://localhost:8080/ingest
curl -X POST http://localhost:8080/ingest/rebuild-bm25 # after all uploads| Endpoint | Description |
|---|---|
POST /ingest |
Upload a PDF/DOCX/PPTX → parse, chunk, embed, index (dedup-aware) |
POST /ingest/rebuild-bm25 |
Rebuild the sparse BM25 index from Qdrant |
POST /query |
Ask a question, get a grounded answer with citations |
POST /query/stream |
Same, streamed via SSE |
GET /documents |
List indexed documents |
DELETE /documents/{name} |
Deregister a document (vectors remain until re-indexed) |
POST /reindex?document_name=X |
Force re-indexing on next upload |
GET /documents/{name}/file |
Serve the original source PDF for a citation link |
GET /health |
Service health (Qdrant + LLM connectivity, chunk/doc counts) |
Interactive docs: http://localhost:8080/docs
This is a working prototype, not a hardened production deployment:
- CPU-only by default (
EMBEDDING_DEVICE/RERANKER_DEVICE=cpuin.env) — generation and embedding are noticeably slower without a dedicated GPU. - Single-worker API server — one request is processed at a time; a long-running ingest or generation call blocks other requests, including
/health. - No authentication — JWT auth code exists under
backend/auth/but is not wired into the API. Endpoints are open. - Partial infrastructure —
infrastructure/docker/docker-compose.ymldefines Postgres, MinIO, OpenSearch, and Langfuse services for a larger production setup, but none of them are currently connected to the live pipeline (Qdrant + local file storage + in-memory BM25 are what's actually used).