# AI Document Summarizer System | 30 Days of Building AI Systems, Day 10

> Build an AI document summarizer: extraction, section-aware map-reduce summaries, page citations, Q&A, and how to evaluate faithfulness and coverage.

Source: https://codeitronics.com/blogs/ai-systems-day-10-document-summarizer (published 2026-11-28)

Yesterday we built a code reviewer that reads diffs in context. Today we build an AI document summarizer: a system that reads whole documents (PDFs, Word files, slides, web pages, emails) and turns them into executive summaries, key points, and answers you can trust. It shares parts with Day 2's document chat, but the core problem is different, and that difference shapes the design.

![AI Document Summarizer System — CodeITronics infographic](https://pub-206c6a53642c4bdb86310f0393204592.r2.dev/blogs/series/30-days-of-building-ai-systems/55-ai-systems-day-10-document-summarizer.png)

*Save this sheet. The rest of this note walks through it section by section.*

## Table of Contents

* [What We Are Building](#what-we-are-building)
* [System Architecture](#system-architecture)
* [Key Components](#key-components)
* [Data Flow Step by Step](#data-flow-step-by-step)
* [A Minimal Tech Stack](#a-minimal-tech-stack)
* [Example Input and Output](#example-input-and-output)
* [Production Concerns](#production-concerns)
* [Extensions Worth Adding](#extensions-worth-adding)
* [Key Takeaways](#key-takeaways)
* [FAQs](#faqs)
* [Up Next](#up-next)

## What We Are Building

The summarizer supports multiple document types, extracts and understands content, generates summaries, extracts key points and insights, answers questions, supports chat, and exports summaries.

Here's the difference from document chat. Chat answers a specific question, so it retrieves a few relevant chunks and ignores the rest. A summary has to account for the *whole* document. You can't retrieve your way to a good summary, because the parts that matter aren't known in advance. That pushes the design toward strategies that read everything once and compress it in stages.

Users include researchers and students, consultants, legal and compliance teams, market and competitive intelligence analysts, support teams summarizing tickets, and anyone running a knowledge base.

## System Architecture

```
document sources (PDF, DOCX, TXT, PPTX, web, email)
  -> text extraction (parser, OCR fallback)
  -> text processing: clean, normalize, split by structure
  -> AI understanding: per-section summaries
  -> summarization: combine into executive summary + key points
  -> Q&A path: embed chunks, retrieve, answer (Day 2 pattern)
  -> output & share: PDF, DOCX, Markdown, link
```

There are two paths over the same extracted text. The summary path reads everything. The Q\&A path uses retrieval, because a follow-up question is exactly the job retrieval is good at.

## Key Components

| Component        | Job                                                    |
| ---------------- | ------------------------------------------------------ |
| Document loader  | Read each format, preserving headings and page numbers |
| OCR              | Tesseract, Azure OCR, or AWS Textract for scans        |
| Text splitter    | Split by sections first, then by size                  |
| Embeddings model | For the Q\&A path                                      |
| Vector store     | Pinecone, Chroma, or Weaviate                          |
| LLM              | Summarize, extract, and answer                         |
| Retriever        | Fetch chunks for questions                             |
| Summarizer       | Orchestrates the summarization strategy                |
| QA engine        | Answers questions with citations                       |
| Export           | PDF, DOCX, Markdown                                    |

## Data Flow Step by Step

1. The user uploads or connects a document.
2. The system extracts and processes the text, keeping section and page structure.
3. The summarizer reads the content and builds per-section summaries.
4. Section summaries combine into an executive summary, key points, and tags.
5. The user asks follow-up questions or requests specific information.
6. The system answers from retrieved chunks, with page citations.
7. The user exports or shares the results.

### Choosing a Summarization Strategy

| Strategy                 | How it works                                                 | When to use                                       |
| ------------------------ | ------------------------------------------------------------ | ------------------------------------------------- |
| Stuff                    | Whole document in one prompt                                 | Short documents that fit comfortably in context   |
| Map-reduce               | Summarize sections in parallel, then summarize the summaries | Long documents and fast parallel processing       |
| Refine                   | Walk sections in order, updating a running summary           | Narratives where order matters                    |
| Long-context single pass | One call with a large context window                         | Medium documents when the model handles them well |

Map-reduce is the dependable default for long documents, and it's simple to build:

```python
from concurrent.futures import ThreadPoolExecutor

MAP_PROMPT = ("Summarize this section in 3-5 bullet points. Keep exact figures and "
              "cite the page as (p. N). Section {title}, pages {pages}:\n\n{text}")
REDUCE_PROMPT = ("Combine these section summaries into: an executive summary "
                 "(one paragraph), 5-7 key points with page citations, and 3-5 tags. "
                 "Use only facts present below.\n\n{summaries}")

def summarize(sections):
    with ThreadPoolExecutor(max_workers=8) as pool:
        partials = list(pool.map(lambda s: llm(MAP_PROMPT.format(**s)), sections))
    return llm(REDUCE_PROMPT.format(summaries="\n\n".join(partials)))
```

Two details carry the quality. Splitting by real sections, not fixed character counts, keeps each summary coherent. And carrying page citations through the map step means the final key points can still point back to the source.

## A Minimal Tech Stack

| Layer               | Choice                                         |
| ------------------- | ---------------------------------------------- |
| Frontend            | Next.js, React, Tailwind                       |
| Backend             | Python with FastAPI                            |
| LLM                 | A current OpenAI GPT or Anthropic Claude model |
| Embeddings          | OpenAI text-embedding-3-large                  |
| Vector DB           | Pinecone, Chroma, or Weaviate                  |
| Document processing | LangChain or LlamaIndex loaders                |
| OCR                 | Tesseract, Azure OCR, AWS Textract             |
| Database            | PostgreSQL or MongoDB                          |
| Storage             | AWS S3 or Google Cloud Storage                 |
| Deployment          | Docker on AWS, frontend on Vercel              |

## Example Input and Output

The sheet's input is a 24-page research paper PDF. The output:

* **Executive summary.** The paper presents a deep learning approach that improves image classification accuracy using a new attention mechanism.
* **Key points.** It proposes a novel attention mechanism, reports an accuracy improvement over baselines, was tested on three benchmark datasets, and outperforms existing models.
* **Tags.** Deep learning, attention, computer vision.
* **Export.** PDF, DOCX, Markdown, or a share link.

The numbers in a summary like this are where readers place the most trust and where summarizers slip most often. A figure like an accuracy gain should be quoted exactly from the paper, with its page, and with the comparison it refers to. "Improved accuracy by X%" means nothing without "compared to what, on which dataset."

## Production Concerns

### Evaluation

Summaries are hard to score automatically, so check them on two separate axes. Faithfulness asks whether every claim in the summary is supported by the document. An LLM judge can check claim by claim against the cited pages. Coverage asks whether the summary includes what an expert would consider the main points. Have a domain expert write reference key points for 20 to 30 documents and check recall against those.

### Cost

Map-reduce reads every token once in the map step, so cost scales with document length. Cache summaries by document hash so re-opening a document is free. Use a smaller model for the map step and a stronger one for the reduce step, where synthesis happens.

### Failure Modes

* **Lost in the middle.** Single-pass summaries of long documents tend to over-weight the beginning and end. Map-reduce over sections avoids most of this.
* **Number drift.** Figures get rounded, swapped, or attached to the wrong comparison. Require exact quoting with page citations and verify numbers against the source text.
* **Bad extraction.** Two-column PDFs, tables, and slide decks come out scrambled. Use layout-aware parsers and look at the extracted text before blaming the summary.
* **Wrong level of detail.** An executive wants five lines, and an analyst wants the methodology. Offer summary presets by audience instead of one generic summary.
* **Confidential documents.** Contracts and internal reports go to a model provider. Check retention terms, and offer a private deployment option where it matters.

## Extensions Worth Adding

From the sheet: multi-language support, audio and video transcription, auto-tagging and classification, collaboration and shared workspaces, plagiarism detection, integration with productivity tools, and a browser extension or API. Audio and video transcription connects directly back to Day 4: a transcript is just another document to summarize.

## Key Takeaways

* Summarization must cover the whole document, so retrieval alone won't do it. Use map-reduce or refine for long inputs.
* Split by real document structure, and carry page citations through every stage.
* Evaluate faithfulness and coverage separately, and verify every number against the source.
* Reuse the Day 2 retrieval path for follow-up questions on the same document.

## FAQs

### If the model has a huge context window, why not just paste the whole document?

For short and medium documents, a single pass often works well. For long ones, quality tends to drop on material in the middle, and costs rise on every re-run. Map-reduce stays dependable as documents grow.

### How is this different from the Day 2 document chat?

Chat retrieves a few chunks to answer a specific question. The summarizer has to read everything to compress it. This system includes a Q\&A path built the Day 2 way for follow-ups.

### How long should a summary be?

Let the reader decide. Offer presets like a one-paragraph executive summary, a key points list, or a detailed section-by-section summary, and keep the same citations across all of them.

## Up Next

Tomorrow is Day 11, the AI Meeting Assistant System. Instead of processing a recording afterwards like Day 4, it joins calls live as a bot, transcribes and labels speakers in real time, answers questions about the meeting, and syncs action items to your CRM and task tools. If your team needs document summarization built on your own content, [talk to us](/contact).
