Databricks - Gen AI Engineer Associate Study Guide

    2: Data Preparation

    This chapter covers the data side of a Databricks RAG pipeline: deciding which source documents earn a place in the index, picking the right Python extractor for each file format, applying a chunking strategy that respects both document structure and model context windows, writing chunked text into Delta Lake tables in Unity Catalog, and quantifying retrieval quality with the right metrics. It then progresses to advanced chunking patterns and re-ranking as the final lever for precision.

    Learning Objectives

    By the end of this chapter, you will be able to:

    • Apply a chunking strategy for a given document structure and model constraints
    • Filter extraneous content in source documents that degrades quality of a RAG application
    • Choose the appropriate Python package to extract document content from provided source data and format
    • Define operations and sequence to write given chunked text into Delta Lake tables in Unity Catalog
    • Identify needed source documents that provide necessary knowledge and quality for a given RAG application
    • Use tools and metrics to evaluate retrieval performance
    • Design retrieval systems using advanced chunking strategies
    • Explain the role of re-ranking in the information retrieval process

    Executive Summary

    • Source selection determines the ceiling of a RAG system; no chunking, embedding, or re-ranking trick rescues a corpus that lacks the answer.
    • Chunking is a joint decision across document structure, embedding model context length, generator context budget, and retrieval top-k.
    • Cleaning and filtering happen before chunking so token budgets are spent on signal, not navigation HTML or repeated footers.
    • Delta Lake tables in Unity Catalog hold both the raw extraction layer and the chunked-with-embeddings layer, and Mosaic AI Vector Search reads from the chunked Delta table through Change Data Feed.
    • Retrieval is measured with recall@k, precision@k, MRR, and nDCG against a curated evaluation set; re-ranking improves precision at small k once recall is already adequate.

    Assumptions

    • The reader has practitioner experience with Python, PySpark, Delta Lake, and the Mosaic AI Vector Search APIs covered in Chapter 1.
    • Examples assume a Unity Catalog metastore is attached to the workspace and a catalog and schema already exist for the RAG application.
    • Identifiers in code samples follow the pattern catalog.schema.table and use fictional names (acme_rag.bronze.docs_raw, acme_rag.silver.chunks, etc.).
    • All terms defined in Chapter 1 are reused without re-definition; only new terms introduced here are defined on first use.

    Sections in this chapter

    1. Free
    2. Free with account
    3. Free with account
    4. Free with account
    5. Free with account
    6. Free with account
    7. Free with account
    8. Free with account
    9. Free with account