What you will be able to do
- Explain how boilerplate, duplicates and off-topic documents reduce RAG retrieval quality
- Strip headers, footers, page markers and OCR noise from extracted text before it is chunked, using ai_parse_document element types where they are available
- Remove exact and near-duplicate documents with metadata rules and MinHash locality-sensitive hashing, and pick which copy to keep
- Exclude whole documents that are irrelevant, outdated, unreliable, toxic or sensitive from the corpus before indexing
Key concept
Extraneous content — Any text that ends up in the index without helping answer a user's question. Examples are repeated page furniture, copies of the same material, and documents that should never have been in the corpus. It still gets embedded and retrieved, so it takes up top-k slots and context that answer-bearing text should have.
1.Why extraneous content degrades retrieval
A RAG application can only answer from what its retriever returns, and the retriever can only return what the data pipeline put in the index. If the index holds page headers, ten copies of the same policy, or a brochure for a product you no longer sell, those chunks compete with the useful ones. Each one that lands in the top-k takes a slot from a chunk that could have answered the question. Each one that reaches the prompt is text the LLM has to read past or, worse, believe.
Retrieval quality and generation quality are linked here. Irrelevant or missing information in the retrieved context is a retrieval problem first, but it shows up as bad answers: hallucinations, outdated figures, or a response that cites the wrong document. Most of the fix belongs in the offline data pipeline, before anything is embedded, rather than in the online chain.
The Databricks unstructured data pipeline puts three separate clean-up steps between ingestion and chunking. Each one works on a different unit of content:
- Data cleaning during parsing removes noise inside a document, such as headers, footers, page numbers and special characters.
- Deduplication removes whole documents that repeat other documents, either exactly or nearly.
- Filtering removes whole documents that do not belong in the corpus at all.
All three run before chunking, so the chunker, the embedding model and the index only ever see content worth retrieving.
Checkpoint 1 of 7· Match them up
A team is preparing documents for a RAG index. Match each pre-chunking clean-up step to the problem it fixes.
Tap a term, then the definition that fits it.
Choose the step by asking what unit of content is wrong. Noise inside a document is removed by cleaning it at parse time. Whole documents that repeat others, exactly or nearly, are removed by deduplication. Clean documents that are stale, off-topic or unwanted are removed by filtering. All three run before chunking.
“Deduplication: Analyze the documents to identify and eliminate duplicates or near-duplicate documents. Filtering: Eliminate irrelevant or unwanted documents from the collection.”Source: docs.databricks.com
2.Stripping boilerplate and noise at parse time
Boilerplate is text that repeats on many pages but says nothing about the topic. Examples are a running page header with the company name, a footer with a confidentiality line, page numbers, and navigation menus on web pages. If you leave it in, the same few phrases appear in hundreds of chunks. That pulls their embeddings toward each other and away from what makes each chunk distinct. The Databricks guidance is direct: remove headers, footers and page numbers, but keep the structure that carries meaning, such as headings, lists and tables.
Cleaning runs on the extracted text, after parsing and before chunking. The aim is to reduce the amount of unnecessary or malformed information the RAG chain has to process. Doing it at this point means every later step works on clean input. A chunking or retrieval setting cannot take junk tokens back out once they are embedded.
A layout-aware parser makes this a filter rather than a guessing game. ai_parse_document managed parsing returns each document as an array of elements, and each element has a type. Layout markers get their own types, separate from body text. Dropping boilerplate then becomes a filter on type: keep the elements that carry content and discard the page furniture. You do not need regular expressions that try to guess which line is a footer.
| Element type | What it is | Typical handling for RAG |
|---|---|---|
| text | A text paragraph or general body text | Keep: this is the main retrievable content |
| table | A table, content represented in HTML | Keep: losing tables hurts retrieval quality |
| section_header | A heading that starts a section | Keep: preserves document structure |
| title | The document title | Keep: useful document-level context |
| page_header | A header at the top of a page | Drop: repeated boilerplate |
| page_footer | A footer at the bottom of a page | Drop: repeated boilerplate |
| page_number | A page number marker | Drop: no semantic content |
Some noise has no element type, so you have to write logic for it. Scanned documents need OCR to get any text out at all. OCR will faithfully turn a diagonal watermark or stamp into scattered, meaningless tokens mixed in with the real sentences. The fix is a cleaning pass on the OCR output, before chunking, that removes known watermark strings and short low-information fragments. Changing chunk overlap or switching to a larger embedding model only changes how the junk is split or diluted. It stays in the index either way.
Repeated text inside a document works the same way. A common case is an email thread where every reply quotes the whole conversation below a separator line. Each message then carries every earlier message, and the same paragraphs get chunked and embedded again and again. Customizing the parsing logic to detect the separator and keep only the new content above it fixes the problem at the source. This kind of upfront investment prevents many downstream quality issues.
Cleaning rules can also delete things that matter. Before you trust a cleaning rule, manually review a sample of the parsed output. For example, a footer rule might be catching the last paragraph of each page, or a fragment filter might be dropping part numbers. Logging parsing errors helps for the same reason, and it often points to quality problems in the source data itself.
Checkpoint 2 of 7· Check yourself
A team parses scanned supplier contracts with ai_parse_document. Retrieval keeps returning chunks that are mostly the company's running header, footer text and page numbers. What should they change in the pipeline?
Boilerplate should be removed from the extracted text at parse time, before chunking. ai_parse_document labels page furniture with its own element types, so the team can filter on type. Headings carry document structure and should be kept. Changing overlap or filtering after retrieval leaves the noise embedded in the index.
“Data cleaning: Preprocess the extracted text to remove irrelevant or noisy information, such as headers, footers, or special characters.”Source: docs.databricks.com
Checkpoint 3 of 7· Exam question
A support-ticket knowledge base includes email threads where each message quotes the entire prior conversation below a "----- Original Message -----" separator, causing the same content to be duplicated across many chunks. Which step should be added to the data preparation pipeline to reduce this redundancy before embedding?
Correct answer: A — Parse each email at ingestion and cut the earlier thread below the reply marker, keeping the new message text for chunking and embedding
- A. Cutting the earlier thread at the reply marker during ingestion leaves only each message's new text. The repeated history is therefore never chunked or embedded, which cuts the redundancy before embedding as the pipeline step requires.
- B. Re-ranking works only at query time. The duplicated chunks are still created, embedded and stored, so the pipeline keeps the redundancy it was meant to remove, and duplicates can still crowd out distinct results before the filter runs.
- C. Merging the messages into one document puts the repeated history from each message into the same text, so it is duplicated inside the merged document. The redundancy is concentrated in one very large unit rather than removed.
- D. A larger chunk size changes how the text is split but not what it contains. Each message still carries the entire earlier thread, so the same content is embedded again and again. The redundancy remains in the corpus.
Checkpoint 4 of 7· Exam question
An engineer is preparing a corpus of scanned legal contracts (PDF images) for a RAG application. Some pages contain large watermark text diagonally overlaid across the page, which OCR extraction turns into scattered, meaningless tokens mixed into the true contract text. What should the engineer do to keep this from degrading retrieval quality?
Correct answer: A — Add a cleanup step after OCR that removes known watermark strings and short low-information fragments from the extracted text, then chunk and embed what remains.
- A. Correct. The noise is already in the extracted text, so it has to be removed before chunking. A post-OCR cleanup that strips known watermark strings and short low-information fragments keeps the stray tokens out of the chunks and their embeddings, which protects retrieval quality.
- B. Incorrect. A large, high-contrast watermark is often recognized with high confidence, so a stricter threshold does not reliably drop it. The stricter cutoff can also discard faint or degraded contract text that is legitimate, so the contamination persists while real content is lost.
- C. Incorrect. Smaller overlap only changes how much text is shared between neighboring chunks. The watermark tokens stay in the extracted text and still land in whichever chunks cover the affected pages, so the noise reaches the embeddings.
- D. Incorrect. A larger embedding model or context window still embeds the watermark tokens together with the contract text. The noise continues to shift each chunk's vector, so the extraction-stage contamination is not addressed and retrieval quality does not reliably recover.
3.Removing duplicate and near-duplicate documents
Duplicates come from ordinary ingestion, not from mistakes. If you pull from several shared drives, the same document often exists in several places, sometimes with small edits. A knowledge base may hold copies of product documentation or drafts of blog posts next to the published versions. When five copies of one passage sit in the index, a query that matches it can fill five of its top-k slots with the same content. Other relevant passages get pushed out, and the LLM gains nothing from the extra copies.
The cheapest pass uses metadata only. If items have the same title and creation date but appear as multiple entries from different sources or locations, you can collapse them without reading their contents. This catches exact copies that were filed twice. It misses copies that were renamed, re-saved or lightly edited.
Content-based near-duplicate detection catches what metadata misses. The recommended technique is locality-sensitive hashing with MinHash, which already has a Spark implementation in Spark ML. It hashes each document based on the words it contains. Documents with similar word sets get similar hashes, so joining on the hashes finds duplicates and near-duplicates efficiently, without comparing every pair of documents directly. At a high level it is a four-step process:
- Create a feature vector for each document. Optionally apply stop word removal, stemming or lemmatization first, then tokenize into n-grams.
- Fit a MinHash model and hash the vectors using MinHash for Jaccard distance.
- Run a similarity join on the hashes to get a result set for each duplicate or near-duplicate document.
- Filter out the duplicates you don't want to keep.
| Approach | What it compares | Catches | Misses |
|---|---|---|---|
| Metadata rules | Fields such as title and creation date | The same item ingested from several sources or locations | Copies with different metadata or small edits |
| MinHash locality-sensitive hashing | Hashes built from the words each document contains | Exact and near-duplicate content, including subtly modified copies | Matches outside your featurization and hash-table settings, which you may need to tune |
Finding a duplicate group still leaves the question of which copy to keep. A baseline keeps one arbitrarily, such as the first result or a random pick. A better rule keeps the best version: the most recently updated, the one with published status, or the one from the most authoritative source. That choice matters when the copies disagree. Keeping a stale draft and dropping the published version is a deduplication that made the corpus worse. Matching quality also depends on the featurization step and the number of hash tables in the MinHash model, so expect to tune both.
An exact byte hash only matches identical files. Copies on shared drives often have small edits, so they hash differently and get through. MinHash builds its hash from the words a document contains, so subtly modified copies still land close enough to be joined as near-duplicates.
Checkpoint 5 of 7· Check yourself
After a MinHash similarity join, one duplicate group holds the published expense policy from the HR site and an earlier draft from a personal drive with different reimbursement limits. Which rule should decide what stays in the corpus?
Picking a copy at random or taking the first one is only a baseline. When near-duplicates disagree, keep the best version: the most recently updated, the published one, or the one from the most authoritative source. If you keep both copies, the redundant and conflicting chunks stay in the index.
“select the “best” version of the duplicate using other logic (such as most recently updated, publication status, or most authoritative source)”Source: docs.databricks.com
Sources2
4.Filtering whole documents out of the corpus
Some documents are perfectly clean and completely unique, yet still make answers worse. Filtering removes documents that are irrelevant to the application's purpose, too old or unreliable, or that contain problematic content such as harmful language. It also removes documents with sensitive information you do not want the agent to expose. None of this can be fixed inside the document. Take a deprecated brochure with outdated prices and no formatting noise at all. Cleaning it, chunking it more finely or adding overlap only makes its wrong prices easier to retrieve. Excluding it from ingestion, or archiving it out of the pipeline, is the only fix.
Filters are driven by metadata, and some of that metadata is predicted rather than stored. Document-level fields such as version, modification date or source system can exclude superseded or off-topic material by rule. For content risks, you can run a model and filter on its output:
- A toxicity classifier produces a prediction per document that you can filter on.
- A personally identifiable information (PII) detection algorithm flags documents to remove.
- Detection mechanisms aimed at data poisoning catch documents planted by bad actors. Every document source you feed into an agent is a potential attack vector.
Rules only go so far. Deciding what is off-topic or superseded is a judgement about the application, so bring in domain experts and stakeholders from the start to help identify and curate the content. They know which product lines are retired, which audience the assistant serves, and which policy version is current. Store the raw ingested data in a target table, and run filtering downstream of it. Excluded documents then stay preserved and traceable for auditing, and they can come back if a rule turns out to be too aggressive.
Checkpoint 6 of 7· Check yourself
An internal HR assistant's corpus includes some well-formatted, unique documents that a PII detection model flags as containing employees' personal details. How should the pipeline deal with them?
Clean, unique documents that should not be exposed need to be filtered out of the corpus as whole documents before chunking. A model's prediction, such as a PII flag, can drive that filter. Running the filter downstream of the raw target table keeps excluded documents preserved and traceable for auditing. Filtering after retrieval or changing chunk size leaves the sensitive content in the index.
“consider including a step in your pipeline to filter out these documents by using any metadata, such as applying a toxicity classifier”Source: docs.databricks.com
Checkpoint 7 of 7· Exam question
A team notices that a RAG assistant occasionally answers using outdated pricing from a deprecated product brochure that was ingested alongside current documentation. The brochure itself contains no boilerplate or formatting noise. From a data preparation standpoint, what is the best way to prevent this document from degrading answer quality?
Correct answer: A — Remove the retired brochure from the source set and rebuild the index, so the next ingestion run starts from the remaining documents
- A. The brochure's prices are out of date, and retrieval cannot tell an old document from a current one. Taking the document out of the source set and rebuilding the index leaves nothing for the assistant to retrieve and quote from it.
- B. Splitting along section headings gives more precise chunks, but the outdated prices are still embedded and indexed. A tighter pricing chunk from the retired brochure can still be retrieved and quoted.
- C. Stripping markup and special characters fixes noise, and the brochure has none. Cleaning the text does nothing about the prices being out of date, so the old figures stay in the index.
- D. More overlap only changes how much neighbouring text each chunk carries. The deprecated prices remain in the index, and appearing in more chunks makes them easier to retrieve.
Sources2
Sources
(4)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“It's difficult to generate high-quality RAG output if the context provided to the LLM is missing important information or contains superfluous information.”
↩︎ Why extraneous content degrades retrieval“generation quality will invariably be impacted by poor retrieval”
↩︎ Why extraneous content degrades retrieval“It's difficult to generate high-quality RAG output if the context provided to the LLM is missing important information or contains superfluous information.”
↩︎ Key concept - 2.https://docs.databricks.com/aws/en/agents/tutorials/ai-cookbook/quality-data-pipeline-ragOfficial docs
“removing duplicates, and filtering out unwanted information, the next step is to break it down into smaller, manageable units called chunks”
↩︎ Why extraneous content degrades retrieval“Filtering: Eliminate irrelevant or unwanted documents from the collection.”
↩︎ Why extraneous content degrades retrieval“Data cleaning: Preprocess the extracted text to remove irrelevant or noisy information, such as headers, footers, or special characters.”
↩︎ Stripping boilerplate and noise at parse time“Reduce the amount of unnecessary or malformed information your RAG chain needs to process.”
↩︎ Stripping boilerplate and noise at parse time“Optical Character Recognition (OCR) techniques are typically required to extract text from images.”
↩︎ Stripping boilerplate and noise at parse time“you may need to customize the parsing logic to extract the most relevant information.”
↩︎ Stripping boilerplate and noise at parse time“it often prevents many downstream quality issues.”
↩︎ Stripping boilerplate and noise at parse time“Regularly assess the quality of the parsed data by manually reviewing a sample of the output.”
↩︎ Stripping boilerplate and noise at parse time“Doing so often points to upstream issues with the quality of the source data.”
↩︎ Stripping boilerplate and noise at parse time“if you pull from one or more shared drives, multiple copies of the same document could exist in multiple locations.”
↩︎ Removing duplicate and near-duplicate documents“you can end up with highly redundant chunks in your final index that can decrease the performance of your application.”
↩︎ Removing duplicate and near-duplicate documents“You can eliminate some duplicates using metadata alone.”
↩︎ Removing duplicate and near-duplicate documents“a technique called MinHash works well here, and a Spark implementation is already available in Spark ML.”
↩︎ Removing duplicate and near-duplicate documents“Fit a MinHash model and hash the vectors using MinHash for Jaccard distance.”
↩︎ Removing duplicate and near-duplicate documents“most recently updated, publication status, or most authoritative source”
↩︎ Removing duplicate and near-duplicate documents“you may need to experiment with the featurization step and the number of hash tables used in the MinHash model”
↩︎ Removing duplicate and near-duplicate documents“either because they are irrelevant to its purpose, too old or unreliable, or because they contain problematic content such as harmful language.”
↩︎ Filtering whole documents out of the corpus“applying a toxicity classifier to the document to produce a prediction you can use as a filter”
↩︎ Filtering whole documents out of the corpus“applying a personally identifiable information (PII) detection algorithm to the documents to filter documents.”
↩︎ Filtering whole documents out of the corpus“any document sources you feed into your agent are potential attack vectors for bad actors to launch data poisoning attacks.”
↩︎ Filtering whole documents out of the corpus“Engage domain experts and stakeholders from the beginning of any project to help identify and curate relevant content”
↩︎ Filtering whole documents out of the corpus“This approach ensures data preservation, traceability, and auditing.”
↩︎ Filtering whole documents out of the corpus“Data cleaning: Preprocess the extracted text to remove irrelevant or noisy information, such as headers, footers, or special characters.”
↩︎ Exam trap 1“Deduplication: Analyze the documents to identify and eliminate duplicates or near-duplicate documents.”
↩︎ Exam trap 2“either because they are irrelevant to its purpose, too old or unreliable, or because they contain problematic content such as harmful language.”
↩︎ Exam trap 3“Deduplication: Analyze the documents to identify and eliminate duplicates or near-duplicate documents. Filtering: Eliminate irrelevant or unwanted documents from the collection.”
↩︎ Checkpoint“select the “best” version of the duplicate using other logic (such as most recently updated, publication status, or most authoritative source)”
↩︎ Checkpoint“consider including a step in your pipeline to filter out these documents by using any metadata, such as applying a toxicity classifier”
↩︎ Checkpoint - 3.
“Remove boilerplate (headers, footers, page numbers).”
↩︎ Stripping boilerplate and noise at parse time“Preserve document structure (headings, lists, tables).”
↩︎ Stripping boilerplate and noise at parse time“Poor parsing (missing tables, broken formatting) directly impacts retrieval quality.”
↩︎ Stripping boilerplate and noise at parse time - 4.
“a layout marker like a page header or footer”
↩︎ Stripping boilerplate and noise at parse time“page_header: A header that appears at the top of a page.”
↩︎ Stripping boilerplate and noise at parse time