Skip to content

About

Production hybrid-search RAG (Qdrant + BM25 + reranking) over 10k+ enterprise docs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

ProductionGradeRAG

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).

How it works

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).

Tech stack

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

Project structure

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

Setup

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

Running (3 terminals)

# 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.sh

Check it's up: curl localhost:8080/health

Frontend

cd frontend
npm install
npm run dev

Ingesting documents

curl -F file=@path/to/document.pdf http://localhost:8080/ingest
curl -X POST http://localhost:8080/ingest/rebuild-bm25   # after all uploads

API reference

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

Current limitations

This is a working prototype, not a hardened production deployment:

  • CPU-only by default (EMBEDDING_DEVICE/RERANKER_DEVICE=cpu in .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.yml defines 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).

About

Production hybrid-search RAG (Qdrant + BM25 + reranking) over 10k+ enterprise docs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages