Black Friday50% off your first month on any monthly plan with EARLY50 See plans
All 29 lessons
  1. Foundations: what RAG is and a working pipeline

    1. 1. Getting started: what RAG is and when to use it
    2. 2. Types of RAG: a map from naive to agentic
    3. 3. Lab: build the smallest RAG pipeline end to end
    4. 4. How embeddings and vector search find meaning
    5. 5. Document types: what each one breaks, and how to prepare it
  2. Better retrieval: chunking and search

    1. 6. Chunking documents so answers survive
    2. 7. Chunking strategies compared: which to use when
    3. 8. Keyword search vs vector search, and fusing both
    4. 9. Retrieval algorithms compared: which to use when
    5. 10. Reranking the top results before the model reads them
    6. 11. Rewriting the question before you search
  3. Answers you can trust, measure and debug

    1. 12. Lab: grounded answers with citations and refusals
    2. 13. Measuring a RAG system with an evaluation set
    3. 14. Lab: evaluation methods and frameworks: Ragas and DeepEval
    4. 15. Troubleshooting a RAG system, symptom by symptom
  4. Production in a company

    1. 16. Access control: only retrieve what the user may see
    2. 17. Defending against prompt injection in retrieved text
    3. 18. Running RAG in production: freshness, cost and monitoring
    4. 19. Real-world RAG: what worked, what failed, and why
  5. Agentic RAG

    1. 20. Lab: from a fixed pipeline to an agent with a search tool
    2. 21. Self-correcting retrieval: grade, retry, fall back
    3. 22. GraphRAG and routing across many sources
    4. 23. Lab: numbers, tables and financial documents
  6. Frameworks: LangChain, LangGraph and LangSmith

    1. 24. The RAG toolbox: what each library does and why you import it
    2. 25. The framework landscape: LangChain, LangGraph, LlamaIndex, Haystack
    3. 26. Lab: Ask Brightline in LangChain
    4. 27. Lab: agentic RAG as a LangGraph graph
    5. 28. Lab: tracing, evaluating and monitoring with LangSmith
    6. 29. Wrap-up: your production agentic RAG checklist
See the leaderboard

20 min

Document types: what each one breaks, and how to prepare it

See how PDFs, scans, tables, spreadsheets, slides, emails, code, contracts and web pages each break a naive pipeline, and fix each one.

By the end of this lesson you can

  • Name what each common document type breaks in a naive pipeline
  • Choose a parser or preparation step for PDFs, scans, tables, slides, email, code, contracts and web pages
  • Decide when to retrieve page images instead of extracted text

From earlier lessons · 1 of 2

Why must questions and documents use the same embedding model?

Pick one answer.

From earlier lessons · 2 of 2

Where is vector search weakest?

Pick one answer.

Brightline's travel policy is a two-column PDF. A plain text extractor reads it straight across the page, line by line. The result: "Hotels are capped at Meals are reimbursed $250 per night in up to $75 per day." Every chunk built from that text is wrong before chunking begins.

The decision before chunking

Lab 1 used clean one-paragraph strings. Real documents arrive as PDFs, scans, spreadsheets, slide decks, email threads and code. Each needs a parsing step that turns the file into clean text and structure. Get this wrong and no chunker, embedding or reranker can recover.

Microsoft's RAG guide makes document analysis the first phase of any RAG project. Before parsing anything, list what you can ignore (tables of contents, headers, footers, watermarks), and find multi-column layouts, tables, images and scans. It warns that multi-column content shouldn't be parsed the same way as single-column content.

[70]

The same table, two ways

An expense-limits table, first as a naive extractor flattens it, then as a layout-aware parser keeps it.

python
naive = "Expense Daily limit Receipt Meals $75 yes Hotel $250 yes Taxi $40 no Parking $25 no"
rows = [{"expense": "Meals", "limit": 75, "receipt": True},
{"expense": "Hotel", "limit": 250, "receipt": True},
{"expense": "Taxi", "limit": 40, "receipt": False},
{"expense": "Parking", "limit": 25, "receipt": False}]
def row_chunk(r): # one chunk per row, with the column names repeated
return f"Expense: {r['expense']}. Daily limit: ${r['limit']}. Receipt needed: {'yes' if r['receipt'] else 'no'}."
print(row_chunk(rows[2]))
Real output: Expense: Taxi. Daily limit: $40. Receipt needed: no.

Take a guess

Ask Brightline indexes the naive string as one chunk. An employee asks: "Do I need a receipt for a taxi?" What's the most likely outcome?

No pressure. Guess now, and the lesson will show you if you were right.

Ten document types: what breaks, and the fix

  1. Digital PDFs. Columns get merged, headers and footers repeat on every page, and tables split across pages. Fix: a layout-aware parser that detects reading order and tables, and drops headers and footers.
  2. Scans and photos. There's no text layer, so a plain extractor returns nothing, which is lesson 15's missing parking policy. Fix: OCR first, and check its quality, since poor scans give unusable text.
  3. Tables. Values lose their column names. Fix: keep table structure (HTML or Markdown), chunk one row per chunk with repeated headers, or load them as data.
  4. Spreadsheets and CSVs. They're data, not prose. Embedding numbers ranks them badly. Fix: load into a database or DataFrame and query it (lessons 22 and 23).
  5. Slides. Meaning lives in layout, arrows and pictures, with little text. Fix: parse with a slide-aware tool, or retrieve page images with a vision model (below).
  6. Images and charts. The text extractor sees nothing. Fix: have a vision model write a description, chunk it, and keep the image link in the chunk so the reader can see the original.
  7. Emails and chat threads. Quoted replies repeat earlier messages, and signatures add noise. Fix: strip quotes and signatures, and chunk by message or thread, with sender and date as metadata.
  8. Code. Line-based chunks cut functions in half. Fix: split along the syntax tree. The cAST study did this with tree-sitter and improved code retrieval and generation benchmarks.
  9. Long contracts. Definitions and cross-references ("as defined in Section 2.1") live far from where they're used. Fix: chunk by clause, attach the definitions a clause uses, and retrieve precise snippets so citations are possible, as LegalBench-RAG argues.
  10. Documents with many versions. Old versions keep answering. Fix: detect changes and deletions in the indexer. Azure's indexer guide warns that deletions aren't detected unless you set a soft-delete policy from the first run.

[70][71][72][73]

The parsers that do this work

Three widely used parsers handle most business documents:

  • Docling (IBM, open source, MIT licence) converts PDF, Word, PowerPoint, Excel, HTML, images and email. It uses layout analysis and a table-structure model, adds OCR for scans, and exports Markdown, HTML or JSON.
  • Unstructured splits a file into typed elements, such as Title, NarrativeText, Table, Image, Header and Footer, with the page number on each. Tables come with an HTML version. Its hi_res PDF strategy is the one that extracts tables.
  • Azure AI Document Intelligence's layout model outputs Markdown. Tables become HTML with merged cells kept, headers and footers become comments you can drop, and OCR covers hundreds of languages.

Parse once, keep the structured output, and chunk from that, never from raw extracted text.

[65][66][67][68]

When to skip text entirely

For slides, brochures and reports full of charts, extracted text loses most of the meaning. ColPali (Faysse et al., 2024) retrieves the page images themselves. A vision language model embeds each page screenshot as many small vectors, and matches them against the question.

On the authors' ViDoRe benchmark, ColPali scored 81.3 nDCG@5, against about 67 for text pipelines built on a parser plus OCR or captions. It also encoded pages faster: 0.39 seconds per page against 7.22. The cost is storage, about 257 KB per page. The answer step then needs a model that can read images.

[69]

Match

Match each Brightline file to its first preparation step

Pick an item on the left, then its match on the right.

Worth keeping

  1. Parsing comes before chunking, and errors here can't be fixed later.
  2. Keep structure: tables as rows with headers, code by syntax tree, contracts by clause.
  3. Spreadsheets and numeric tables are data; query them rather than embed them.
  4. For visual pages, retrieve the page image instead of extracted text.

The travel policy is now clean text with its headings intact. Next lesson cuts it into chunks, and finds the one boundary that splits a hotel rule from its exception.

Leaderboard

Loading…

50 XP for each lesson you finish, 10 for each right answer. Names show only for learners who turn on Show me on leaderboards.

Sources for this lesson (9)

Each fact in the lesson is marked with the number of the page it comes from.

  1. [65]Auer et al. (2024), Docling Technical Report
  2. [66]Docling documentation
  3. [67]Unstructured docs: Partitioning
  4. [68]Microsoft Learn: Document Intelligence layout model
  5. [69]Faysse et al. (2024), ColPali
  6. [70]Microsoft Learn: RAG preparation phase
  7. [71]cAST (2025): chunking code by abstract syntax tree
  8. [72]Pipitone and Alami (2024), LegalBench-RAG
  9. [73]Microsoft Learn: Changed and deleted blobs in indexing