One RAG Pipeline, Four Very Different PDFs: Same Four Bricks, Every Answer Typed and Cited

· Source: Towards Data Science · Field: Technology & Digital — Artificial Intelligence & Machine Learning, Software Development & Engineering · Depth: Intermediate, extended

Summary

A single, upgraded RAG pipeline ("pdf_qa" function) is presented, designed to process diverse PDF documents without code changes. It builds upon four "bricks": document parsing, question parsing, retrieval, and generation, each previously enhanced. The pipeline was tested on four distinct PDFs: "Attention Is All You Need" (research paper), NIST Cybersecurity Framework 2.0 (compliance document), "Retrieval-Augmented Generation" (research paper), and a World Bank "Commodity Markets Outlook" (report with broken TOC). For the "Attention" paper, it answered a listing question about positional encoding. For NIST CSF 2.0 and the RAG paper, it answered single-concept questions. Crucially, for the World Bank report with a degenerate TOC, the pipeline correctly declined to answer, returning "NA" with 0.0 confidence, demonstrating robustness against hallucination when context is insufficient. The pipeline incorporates two side channels: "parsing_summary" feeding question parsing, and a feedback loop from generation to retrieval. The article emphasizes the independence and typed contracts of each brick, allowing for modular upgrades.

Key takeaway

For AI Engineers building enterprise RAG systems, you should prioritize a modular, "brick-by-brick" architecture with explicit typed contracts. This approach ensures your pipeline can adapt to diverse document types and questions without code changes, significantly reducing maintenance. Implement robust context engineering, including TOC-aware retrieval and generation feedback, to prevent hallucinations and provide auditable, cited answers, even when source context is incomplete.

Key insights

A robust RAG pipeline uses independent, typed "bricks" and context engineering to handle diverse documents and prevent hallucinations.

Principles

Method

The "pdf_qa" function orchestrates four bricks: parsing (relational data), question parsing (structured brief), retrieval (keyword + TOC routing), and generation (typed, cited answer with quality indicators). It includes "parsing_summary" and a generation-to-retrieval feedback loop.

In practice

Topics

Code references

Best for: AI Engineer, Machine Learning Engineer, MLOps Engineer

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by Towards Data Science.