Data Preparation · Topic 1 of 2
Source Documents, Extraction and Delta Tables
Databricks GenAI Engineer: choose RAG source documents, pick the Python package to parse each format, filter noise and write chunks to Delta tables.
- 5 min
- Choose sources for coverage, authority, freshness and rights to use, not volume.
- Match the parser to the format; scans need OCR and tables need a table aware parser.
- Strip headers, footers, navigation and boilerplate before chunking.
What it is
A RAG application can only answer from what it retrieves, so data preparation decides its ceiling. You choose the source documents that hold the needed knowledge, extract their text with a parser that fits the format, filter out content that adds noise, and write the resulting chunks to a Delta table in Unity Catalog.
That table is the source for a Vector Search index.
How it works
Choosing source documents
Start from the questions users will ask, then find documents that answer them.
| Check | Why it matters |
|---|---|
| Coverage | Every expected question has an answer somewhere in the set |
| Authority | The official, current version, not drafts or copies |
| Freshness | Old versions give outdated answers; remove or replace them |
| Duplicates | Several copies of one text crowd out other results |
| Rights to use | Licensing and terms must allow use in the application |
| Access | Sensitive documents need governance or exclusion |
More documents are not always better. Loosely related or outdated material is retrieved in place of the right passage.
Raw files are usually stored in a Unity Catalog volume, so access is governed and the pipeline reads them by path.
Choosing a Python package for extraction
| Source format | Typical package | Notes |
|---|---|---|
| Text PDF | pypdf, PyMuPDF | Fast text extraction page by page |
| PDF with tables | pdfplumber | Keeps table cells and positions |
| Scanned PDF or image | pytesseract (OCR) | No text layer, so OCR is required |
| Word documents | python-docx | Reads paragraphs, headings and tables |
| PowerPoint | python-pptx | Reads text from slides and shapes |
| HTML pages | BeautifulSoup | Parses tags so navigation and scripts can be dropped |
| Many mixed formats | unstructured | Splits files into typed elements such as titles, text and tables |
On Databricks, the ai_parse_document SQL function can also parse PDFs and other binary documents into structured content without managing parser libraries.
Pick the parser that keeps the structure you need; a plain text extractor flattens tables.
Filtering extraneous content
Remove content that matches many queries but answers none:
- Repeated page headers, footers, page numbers and copyright lines.
- Navigation menus, cookie banners and scripts in web pages.
- Tables of contents and indexes that repeat headings without content.
- Boilerplate disclaimers repeated in every document.
- Encoding errors, broken characters and very short fragments.
Filtering happens after extraction and before chunking. It improves retrieval because the embedding of each chunk then reflects its real subject, not the shared boilerplate.
Writing chunks to a Delta table
The usual order of operations:
- Read the raw files from the volume.
- Parse and filter each file.
- Split into chunks and give each a stable unique ID, plus metadata such as source path, title and page.
- Write to a Delta table in Unity Catalog with a three level name,
catalog.schema.table. - Enable Change Data Feed on the table, which a Delta Sync index needs to pick up changes.
- Create the Delta Sync index with the chunk ID as the primary key and the text column to embed.
CREATE TABLE IF NOT EXISTS main.rag.doc_chunks (
chunk_id STRING, doc_path STRING, chunk_text STRING
) TBLPROPERTIES (delta.enableChangeDataFeed = true);
chunks_df.write.mode("append").saveAsTable("main.rag.doc_chunks")
A Delta Sync index then picks up changed rows in triggered mode (each time a sync runs) or continuous mode (within seconds).
How the exam asks about this
- "Answers quote last year's pricing although this year's sheet was added." Remove or replace outdated sources; both versions are retrieved and compete.
- "Scanned contracts return empty text when parsed." The files have no text layer, so use OCR before chunking.
- "The Delta Sync index cannot be created on the chunks table." Check that the table is in Unity Catalog, has a primary key column and has Change Data Feed enabled.
What to remember for the exam
- Choose sources for coverage, authority, freshness and rights to use, not volume.
- Match the parser to the format; scans need OCR and tables need a table aware parser.
- Strip headers, footers, navigation and boilerplate before chunking.
- Each chunk row needs a unique ID, the text and source metadata.
- Write chunks to a Unity Catalog Delta table and enable Change Data Feed for a Delta Sync index.
- Raw files belong in a Unity Catalog volume so access is governed.
Do not fix noisy retrieval by adding a guardrail or a longer prompt. If boilerplate or outdated documents are in the index, the fix is at the data layer: clean, filter or remove them and re-index.
Common mistakes
Indexing everything available. Adding every file in a share brings in drafts, duplicates and off topic material. Retrieval then returns the wrong passages more often.
Ignoring document licensing. Content scraped or bought for another purpose may not be licensed for a RAG application. Rights to use are part of choosing sources.
Writing chunks without IDs or metadata. Without a stable key the index cannot track updates, and without a source path the app cannot cite or remove a document.
Check yourself
Which Python package suits HTML pages full of menus and scripts?
BeautifulSoup, which parses the tags so you can keep the main content and drop navigation and scripts.
What table property does a Delta Sync index need on its source table?
Change Data Feed, set with delta.enableChangeDataFeed = true, so the index can pick up inserts, updates and deletes.
Why store the source path with each chunk?
It lets the application cite where an answer came from and lets you update or delete every chunk of one document.
Topic 1 of 2 in Data Preparation
Test yourself on Data Preparation
The full Databricks Generative AI Engineer Associate question bank has 600 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Databricks. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.