CertSafari
    Databricks Certified Generative AI Engineer Associate· Lessons

    Domain 2 · Lesson 10/56

    Writing chunked text to Delta tables in Unity Catalog

    Define operations and sequence to write given chunked text into Delta Lake tables in Unity Catalog

    18 min read
    1.75% of exam
    8 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Design a chunk table row with a stable primary key, the chunk text, source identifiers and metadata, and explain what each field does downstream
    • Create the chunk table as a managed Delta table under a three-level catalog.schema.table name with the required privileges
    • Choose between overwrite, append and MERGE for a first load and for re-ingested documents
    • Enable Change Data Feed so a Delta Sync index can follow the chunk table, and put the whole write sequence in order

    Key concept

    Chunk table as a Delta Sync source — The chunk table is a managed Unity Catalog Delta table with one row per chunk. Each row is identified by a unique primary-key column, and Change Data Feed is turned on so that an index can pick up inserts, updates and deletes incrementally instead of re-reading the whole table.

    1.Where the chunk write sits in a RAG data pipeline

    The chunk table is the handoff point between data preparation and retrieval. Upstream, raw documents are ingested, parsed and split into chunks. Downstream, those chunks are embedded and indexed for similarity search. The pipeline lists chunking and then indexing and storage as separate steps. A Delta table in Unity Catalog sits between them: the chunker writes to it, and the index reads from it.

    How you split the text is a separate decision, covered under chunking strategy. This lesson starts from a DataFrame of chunks that already exists. The question here is what each row must contain, where the table lives, which write operation to use on each run, and which table property lets an index keep up with changes.

    The full sequence for turning parsed PDFs into a queryable index looks like this:

    1. Split the parsed text into chunks and give each chunk a unique identifier plus its source metadata.
    2. Write the chunk records to a managed Delta table with a three-level catalog.schema.table name, including the primary-key column.
    3. Enable Change Data Feed on that table with delta.enableChangeDataFeed = true.
    4. Create an AI Search endpoint and a Delta Sync index that points at the table and names the primary key and the embedding source column.

    Step 4 is the subject of creating a Delta Sync index. The first three steps are what decide whether step 4 works. Databricks AI Search is the product formerly called Databricks Vector Search, and it accepts Delta Lake tables, streaming tables and Iceberg v3 managed tables as sources.

    Checkpoint 1 of 9· Put it in order

    Put these RAG data-pipeline stages in order, from raw PDFs to a searchable index.

    1. 1.Ingest the raw source documents into a target table
    2. 2.Convert the chunks to embeddings and index them for similarity search
    3. 3.Split the parsed text into chunks and write them to the Unity Catalog Delta table
    4. 4.Parse the raw documents to extract clean text

    Checkpoint 2 of 9· Exam question

    An engineer has parsed raw PDF documents into plain text and needs to end up with a queryable AI Search index built on chunks stored in Unity Catalog. Order the following operations into the correct sequence.(Select 4)

    0 of 4 selected

    Sources12

    2.What a chunk row must hold

    A chunk row needs five kinds of field, and each one is there for something that happens later. A typical row has chunk_id, document_id, chunk_index, chunk_text and source_uri, plus any extra metadata.

    • A stable primary key (chunk_id). The index uses it to identify each row. It must be unique and must come out the same every time the same chunk is produced. A value built from the document ID and chunk position meets both conditions. A random UUID created on each run does not.
    • The chunk text (chunk_text). This is the embedding source column. The index embeds it and returns it to the retriever.
    • The source document ID and path (document_id, source_uri). With these, an answer can cite where it came from, and a re-ingestion run can find every existing chunk of one document.
    • Position (chunk_index). This keeps the chunk's order within its document. It also makes the primary key deterministic, because the same document position always produces the same ID.
    • Metadata such as title, section or date. You can filter on these fields at query time.

    Metadata has to be stored with the chunk itself, not kept somewhere else. Storing metadata next to the chunk improves retrieval accuracy, and it lets you combine vector similarity with keyword filtering in hybrid search. The index can only filter on columns it has, and by default it syncs every column of the source table. The primary key column and the embedding source column are always included.

    The stable key also protects against a quieter failure: redundant chunks. If the same document gets chunked twice and each copy gets a fresh ID, both copies stay in the table. Duplicate chunks in the final index make the application perform worse. A deterministic key is what lets a later write recognise a chunk it has already stored.

    Checkpoint 3 of 9· Check yourself

    A chunker gives every chunk a fresh random UUID as its chunk_id each time it runs. A later run chunks the same PDF again and writes the result to the chunk table. What happens?

    Sources13

    3.Creating the chunk table as a managed table in Unity Catalog

    Create the chunk table as a Unity Catalog managed Delta table. Managed tables are the default and recommended table type. Unity Catalog handles their storage and optimisation, and they cost less to store and query than external tables. Delta is also the default format: Databricks creates a Delta Lake table unless you write USING iceberg.

    Always use the full name. Every read and write against a managed table must use the three-level catalog.schema.table name. Path-based access is not supported, because it bypasses Unity Catalog access controls. Two shortcuts fail for this reason. One is writing Parquet files into a volume and registering an external table on top. The other is calling saveAsTable("chunks") with no catalog or schema.

    Creating the table takes three privileges, granted on the table's parents:

    • USE CATALOG on the parent catalog.
    • USE SCHEMA on the parent schema.
    • CREATE TABLE on the parent schema.

    The index also needs CREATE TABLE on whichever schema it will be created in.

    You can create the table empty before the first load, and doing so lets you set its properties up front. The DeltaTableBuilder API supports Delta-specific options such as table properties, which saveAsTable() does not offer. That makes it a natural place to declare the chunk table's columns together with its properties.

    Create an empty managed Delta table with a three-level name and a table propertypython
    from delta.tables import DeltaTable
    
    DeltaTable.create(spark) \
      .tableName("<catalog-name>.<schema-name>.<table-name>") \
      .addColumn("<column-name>", "<data-type>") \
      .property("<key>", "<value>") \
      .execute()

    Checkpoint 4 of 9· Fill the gap

    This builder call creates the empty chunk table as a Unity Catalog managed Delta table before the first load. Which builder method belongs in the blank?

    from delta.tables import DeltaTable
    
    DeltaTable.create(spark) \
      . ? ("<catalog-name>.<schema-name>.<table-name>") \
      .addColumn("<column-name>", "<data-type>") \
      .property("<key>", "<value>") \
      .execute()

    Sources42

    4.First load versus re-ingestion: overwrite, append and MERGE

    Delta tables offer three write operations, and each one fits a different run of the pipeline. Overwrite replaces all the data in the table. Append adds rows. MERGE (an upsert) updates the rows that match a key and inserts the rows that don't.

    Delta write operations for a chunk table
    OperationWhat it doesWhen it fits a chunk table
    mode("overwrite")Replaces all the data in the tableA deliberate full rebuild, for example after changing chunk size. It rewrites every row, even unchanged ones.
    mode("append")Adds new rows without checking for duplicatesThe first load into an empty table, or a batch you know contains only new documents
    MERGE INTO / DeltaTable.mergeUpdates matched rows and inserts unmatched ones, keyed on a conditionEvery run after the first, when some documents may already be in the table

    Append is right for the first load and wrong for re-ingestion. On an empty table, df.write.format("delta").mode("append").saveAsTable("catalog.schema.chunks") is a correct way to land the chunks. Once a document can come back, though, every append adds another copy. MERGE keyed on the chunk ID fixes this. A chunk that already exists is updated in place, and a new chunk is inserted. Delta allows only one source row to match a given target row, so the key must be unique within each incoming batch too.

    Upsert on a key column: update rows that match, insert rows that don'tsql
    MERGE INTO workspace.default.people_10k AS people_10k
    USING workspace.default.people_10k_updates AS people_10k_updates
    ON people_10k.id = people_10k_updates.id
    WHEN MATCHED THEN
      UPDATE SET *
    WHEN NOT MATCHED THEN
      INSERT *;

    For a chunk table, swap id for the chunk ID. UPDATE SET * and INSERT * only work when the source and target have the same columns. If they don't, the query throws an analysis error, so build the chunk DataFrame to match the table's schema exactly.

    A document that gets shorter leaves stale chunks behind. Say a manual used to produce 12 chunks and now produces 9. A plain MERGE updates chunks 0 through 8 and leaves the old 9, 10 and 11 in the table, where the retriever can still return outdated text. The WHEN NOT MATCHED BY SOURCE clause can delete target rows that have no matching source row.

    MERGE that also deletes target rows missing from the sourcepython
    (targetDF.alias("target")
      .merge(sourceDF.alias("source"), "source.key = target.key")
      .whenMatchedUpdateAll()
      .whenNotMatchedInsertAll()
      .whenNotMatchedBySourceDelete()
      .execute()
    )

    Never run that delete without a condition. A re-ingestion batch usually holds only the documents that changed, so an unconditioned WHEN NOT MATCHED BY SOURCE DELETE would remove the chunks of every other document. Limit the delete to the document IDs in the current batch. Databricks recommends adding a condition anyway, so that the merge does not rewrite the entire target table.

    Checkpoint 5 of 9· Match them up

    Match each Delta write operation to the pipeline run where it fits the chunk table

    Tap a term, then the definition that fits it.

    Checkpoint 6 of 9· Check yourself

    Your nightly re-ingestion batch holds the re-chunked versions of 5 edited manuals. The chunk table holds chunks for 200 manuals. To clear out stale chunks, you add an unconditioned whenNotMatchedBySourceDelete() to the MERGE keyed on chunk_id. What does the MERGE do?

    Sources56

    5.Enabling Change Data Feed so a Delta Sync index can follow the table

    A Delta Sync index updates itself by reading the changes made to its source table, so that table must have a change data feed. Delta Sync indexes on standard endpoints refuse a source table without one. A typical error says the table cannot be synced incrementally, and the fix is a single table property.

    Turn on Change Data Feed for an existing Delta tablesql
    ALTER TABLE myDeltaTable
      SET TBLPROPERTIES (delta.enableChangeDataFeed = true)

    Run it on the chunk table by its full name, for example ALTER TABLE catalog.schema.chunks SET TBLPROPERTIES (delta.enableChangeDataFeed = true), before you create the index. You can also set the same property when you create the table, using the builder's .property() call. Tables with row tracking enabled get a change data feed automatically, but setting delta.enableChangeDataFeed yourself is the standard step. With the feed in place, each MERGE from the previous section reaches the index as row-level inserts, updates and deletes, keyed on the primary-key column.

    The other prerequisites for an AI Search index have nothing to do with how the table was filled:

    • A Unity Catalog-enabled workspace.
    • Serverless compute enabled.
    • CREATE TABLE on the schema where the index will be created.

    Neither SQL warehouses nor Z-ordering appear among those requirements. How the rows arrived doesn't matter either. A streaming write to a Delta table is an ordinary way to fill it (by default a stream appends new records), so Auto Loader is no more a problem than a batch write. When index creation fails on a table that otherwise looks correct, check whether Change Data Feed is enabled before anything else.

    Checkpoint 7 of 9· Check yourself

    An Auto Loader stream fills a managed chunk table, main.rag.chunks, which has a unique chunk_id column. Creating a Delta Sync index on it fails with an error saying the table cannot be synced incrementally. A colleague blames the streaming write. What should you do?

    Checkpoint 8 of 9· Exam question

    A generative AI engineer has produced a Spark DataFrame of chunked text records, each with document_id, chunk_index, chunk_text, and source_uri columns. The chunks need to land in Unity Catalog in a form that a Delta Sync Index can later consume. Which operation correctly persists the data for this purpose?

    Checkpoint 9 of 9· Exam question

    A team created an AI Search endpoint and attempted to create a Delta Sync Index pointing at catalog.schema.chunks, but index creation fails with an error stating the source table cannot be synced incrementally. What is the most likely cause and correct fix?

    Sources278

    Practise it for real

    Build a chunk table that a Delta Sync index can follow, then re-ingest a document without creating duplicates.

    1. 1.Create an empty managed table with CREATE TABLE <catalog-name>.<schema-name>.chunks and columns for the chunk ID, document ID, chunk index, chunk text and source URI.

      Why: A managed table must be addressed by its three-level name, and the schema fixes the columns that MERGE will later match against.

      You should see: The table appears in Catalog Explorer under your catalog and schema with no rows.

    2. 2.Load the first batch of chunks with df.write.mode("append").saveAsTable("<catalog-name>.<schema-name>.chunks").

      Why: On an empty table there is nothing to duplicate, so a plain append is enough for the first load.

      You should see: SELECT COUNT(*) returns the number of chunks in the DataFrame, and every chunk ID appears once.

    3. 3.Run ALTER TABLE <catalog-name>.<schema-name>.chunks SET TBLPROPERTIES (delta.enableChangeDataFeed = true).

      Why: Delta Sync indexes on standard endpoints need the source table to have a change data feed.

      You should see: SHOW TBLPROPERTIES on the table lists delta.enableChangeDataFeed as true.

    4. 4.Re-chunk one document, register the result as a view, and MERGE it into the table ON the chunk ID with WHEN MATCHED THEN UPDATE SET * and WHEN NOT MATCHED THEN INSERT *.

      Why: MERGE updates the chunks that already exist and inserts the new ones, where an append would add a second copy.

      You should see: Grouping by chunk ID shows a count of 1 for every ID, and the edited chunk text has replaced the old text.

    Stuck? Get a nudge

    If a chunk ID shows a count of 2 after step 4, check whether the incoming batch itself contained that ID twice. Only one source row may match a given target row.

    Sources

    (8)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Chunking: Break down the parsed data into smaller, manageable chunks for efficient retrieval.”
      ↩︎ Where the chunk write sits in a RAG data pipeline
      “Indexing and storage: Create efficient vector indices for optimized search performance.”
      ↩︎ Where the chunk write sits in a RAG data pipeline
      “Storing metadata alongside chunked documents or their corresponding embeddings is essential for optimal performance.”
      ↩︎ What a chunk row must hold
      “combining vector similarity search with keyword-based filtering, can enhance relevance”
      ↩︎ What a chunk row must hold
      “you can end up with highly redundant chunks in your final index that can decrease the performance of your application.”
      ↩︎ What a chunk row must hold
      “Embedding: Convert the chunked text data into a numerical vector representation that captures its semantic meaning.”
      ↩︎ Checkpoint
    2. 2.
      “Databricks AI Search was formerly known as Databricks Vector Search.”
      ↩︎ Where the chunk write sits in a RAG data pipeline
      “Supported source types include Delta Lake tables, streaming tables, or managed tables using Iceberg v3 or above.”
      ↩︎ Where the chunk write sits in a RAG data pipeline
      “To create an AI Search index, you must have CREATE TABLE privileges on the catalog schema where the index will be created.”
      ↩︎ Creating the chunk table as a managed table in Unity Catalog
      “For standard endpoints, the source table must use a change data feed.”
      ↩︎ Enabling Change Data Feed so a Delta Sync index can follow the table
      “Tables with row tracking enabled use a change data feed automatically, without requiring manual configuration.”
      ↩︎ Enabling Change Data Feed so a Delta Sync index can follow the table
      “For standard endpoints, the source table must use a change data feed.”
      ↩︎ Key concept
      “For standard endpoints, the source table must use a change data feed.”
      ↩︎ Exam trap 3
    3. 3.
      “The primary key column and embedding source column or embedding vector column are always synced.”
      ↩︎ What a chunk row must hold
    4. 4.
      “Unity Catalog managed tables are the default and recommended table type in Databricks for Delta Lake and Apache Iceberg.”
      ↩︎ Creating the chunk table as a managed table in Unity Catalog
      “Otherwise, Databricks creates a Delta Lake table by default.”
      ↩︎ Creating the chunk table as a managed table in Unity Catalog
      “All reads and writes to managed tables must use table names and catalog and schema names where they exist.”
      ↩︎ Creating the chunk table as a managed table in Unity Catalog
      “CREATE TABLE on the table's parent schema.”
      ↩︎ Creating the chunk table as a managed table in Unity Catalog
      “use the DeltaTableBuilder API for Delta-specific options like generated columns and table properties”
      ↩︎ Creating the chunk table as a managed table in Unity Catalog
      “All reads and writes to managed tables must use table names and catalog and schema names where they exist.”
      ↩︎ Exam trap 1
    5. 5.
      “To replace all the data in a table, use the overwrite mode.”
      ↩︎ First load versus re-ingestion: overwrite, append and MERGE
      “Unlike upserting, writing to a table does not check for duplicate records.”
      ↩︎ First load versus re-ingestion: overwrite, append and MERGE
      “If the target table does not have the same columns, the query throws an analysis error.”
      ↩︎ First load versus re-ingestion: overwrite, append and MERGE
      “Unlike upserting, writing to a table does not check for duplicate records.”
      ↩︎ Exam trap 2
    6. 6.
      “Only a single row from the source table can match a given row in the target table.”
      ↩︎ First load versus re-ingestion: overwrite, append and MERGE
      “use the WHEN NOT MATCHED BY SOURCE clause to UPDATE or DELETE records in the target table that do not have corresponding records”
      ↩︎ First load versus re-ingestion: overwrite, append and MERGE
      “Databricks recommends adding an optional conditional clause to avoid fully rewriting the target table.”
      ↩︎ First load versus re-ingestion: overwrite, append and MERGE
      “Databricks recommends adding an optional conditional clause to avoid fully rewriting the target table.”
      ↩︎ Exam trap 4
    7. 7.
      “Set the table property delta.enableChangeDataFeed = true in the ALTER TABLE command.”
      ↩︎ Enabling Change Data Feed so a Delta Sync index can follow the table
    8. 8.
      “By default, streams run in append mode and only add new records to the table.”
      ↩︎ Enabling Change Data Feed so a Delta Sync index can follow the table

    Spotted a mistake, or was something unclear? Tell us.