**Upgrading Each Brick of the Enterprise RAG Pipeline**
This article, the first of two parts, upgrades each “brick” of a four‑brick enterprise Retrieval‑Augmented Generation (RAG) pipeline—document parsing, question parsing, retrieval, and generation—on the same paper and question used in a minimal baseline. The second part (to follow) composes the upgraded bricks into a single pipeline and tests them on real enterprise documents.
What each brick now delivers:
– Document parsing returns a small relational set (line‑level, page‑level, and TOC tables) plus a `parsing_summary` with document type, language, and a short summary.
– Question parsing turns noisy user input into a typed `ParsedQuestion` with corrected keywords, an inferred answer shape, a retrieval query, and a generation brief.
– Retrieval reads the document’s own table of contents via a small LLM to pick relevant sections, then merges those with keyword‑based page retrieval, avoiding a flat vector search.
– Generation returns a typed answer (e.g., a `ListAnswer` when the question asks for options), with one citable span per item and four context‑quality indicators.
The running example is the public 15‑page arXiv paper “Attention Is All You Need.” The question (“What are the options for positional encoding?”) arrives with two typos. The upgraded pipeline corrects the keywords using an expert vocabulary, retrieves the correct sections via the TOC, and returns a typed list of options, each with verbatim quotes and line ranges, plus confidence, completeness, structure, and context flags.
**How the baseline breaks and how each upgrade fixes it**
1. **Document parsing**: The baseline flattens the PDF into a single list of lines, losing sections, pages, tables, and structure. The upgrade preserves lines, pages, and a native TOC, enabling section‑aware retrieval and proper citations.
2. **Question parsing**: Baseline keyword extraction fails on typos and lacks vocabulary expansion. The upgrade corrects typos in one call, extracts content keywords, expands them with domain terms, and produces a typed brief for downstream bricks.
3. **Retrieval**: Baseline keyword matching on pages ignores structure. The upgrade first uses the TOC—LLM‑driven section selection—then merges with keyword pages and sizes context around the identified section or line window.
4. **Generation**: Baseline returns a raw string, forcing the caller to re‑parse lists and citations. The upgrade produces a typed schema with one citable span per list item and quality indicators that let downstream systems decide whether to ship the answer or retry.
**Key technical outcomes**
– The `parse_pdf` step outputs `line_df`, `page_df`, `toc_df`, and `parsing_summary`, a reusable relational core for all later bricks.
– `parse_question` uses an expert `concept_keywords_df` to expand terms and emits a `RetrievalQuery` and `GenerationBrief`.
– Retrieval combines a cheap keyword detector with an LLM TOC router, then sizes context (whole section or line window) based on the inferred answer shape.
– Generation consumes a typed brief and filtered lines to produce a `ListAnswer` or single answer with per‑item evidence spans and four quality signals.
The four upgrades are independent and can be adopted incrementally from the minimal RAG baseline. The resulting pipeline emits an auditable chain from question to citation, turning opaque failures (typos, broken TOCs, flattened lists) into visible, addressable signals. The next part will compose these bricks into a single call and run the assembled pipeline on multiple real documents.
*Source: “III of Enterprise Document Intelligence, a series that builds an enterprise RAG system from four bricks: document parsing, question parsing, retrieval, and generation.”*



