Document Intelligence: Retrieval-Augmented Generation Over Large PDF Collections
Built a RAG platform that turns large PDF collections into a queryable knowledge base — semantic retrieval over PostgreSQL and pgvector, page-level citations behind every generated claim, and structured report export to Word and PDF.
Retrieval-augmented generation
Citation tracking
Semantic search at scale
Including right-to-left scripts
The Challenge
Organisations sitting on hundreds or thousands of PDFs generally cannot search them in any useful way:
- Collections run to hundreds of documents — far too many to read manually under any deadline
- Keyword search misses anything phrased differently to the query; full-text search returns whole documents when the answer was one paragraph
- Every generated claim needed a verifiable, page-level citation back to its source document
- Separate workspaces needed genuine data isolation, with no cross-workspace retrieval
- Document sets spanned multiple languages, including right-to-left scripts, without a separate pipeline per language
- Output had to leave the system as Word and PDF documents, not as chat transcripts
The Solution
I designed and built a two-pipeline RAG system — ingestion runs once per document, query runs per question — so re-indexing and model changes stay independent of each other:
Layout-Aware Ingestion
PDF extraction that preserves multi-column layouts and tables, with chunk boundaries tuned so splits do not land mid-table or mid-clause.
Vector Search & Retrieval
Chunks are embedded and stored in PostgreSQL with pgvector, retrieved by semantic similarity with reranking applied before anything reaches the model.
Citation-Preserving Generation
Page provenance is attached at ingestion and carried through retrieval, so citations are a property of the pipeline rather than something the model is asked to produce.
Structured Report Output
LlamaIndex orchestrates GPT-4 to produce a fixed report shape rather than free-form answers, making results comparable across queries.
Workspace Isolation
Multi-tenant by design — each workspace has its own document set and index, with retrieval scoped so nothing crosses the boundary.
Export & Distribution
Reports export to Word and PDF with formatting and citations intact, ready to circulate without reformatting.
Results
The platform turns an unsearchable document pile into a system that answers questions with evidence attached:
Query hundreds of documents and receive a structured report in minutes
Every claim links back to a specific page in a specific source document
Generation routed through a LiteLLM proxy, so swapping models is a config change
One pipeline handles document sets spanning several languages and scripts
Technology Stack
Frontend
- • React
Backend
- • FastAPI
- • Python
AI & ML
- • GPT-4
- • LlamaIndex
- • Haystack 2.x
- • LiteLLM
Database & Infrastructure
- • PostgreSQL
- • pgvector
- • Docker
Need something similar?
I build custom platforms, automation systems, and data solutions. Let's discuss your project.