
Published on
Measure First RAG Data Preparation With Recursive 512 Token Chunks
The pipeline that makes Retrieval-Augmented Generation reliable has six links: ingest, parse and clean, chunk and enrich, embed, index, then evaluate and monitor. Of those, one decision moves the needle more than any other. Chunking strategy, paired with the metadata riding alongside each chunk, determines whether your retriever finds the right passage or confidently hands your model the wrong one. Everything below builds out that pipeline, step by step, with the measurement discipline to prove it works.
TL;DR:
Effective chunking paired with metadata is crucial, with recursive splitting around 512 tokens being a reliable default for most documents.
Domain-specific corpora require careful profiling, cleaning, and potentially domain-tuned embeddings to handle jargon, inconsistent formatting, and noisy data.
Hybrid retrieval, combining dense embeddings with sparse keyword matching, improves accuracy on technical and legal content, especially when using rerankers for precision.
Regular measurement through labeled test sets, focusing on recall, faithfulness, and citation quality, is essential to optimize and monitor pipeline performance.
Privacy and compliance demand strict handling of sensitive data, including metadata-enforced access controls, PII redaction at ingestion, and traceability of source documents.
Table of Contents
Corpus Selection and Data Ingestion for RAG
How Do You Parse and Clean Documents for RAG?
Which Chunking Strategy Should You Use for RAG?
What Metadata Should Every RAG Chunk Carry?
Embeddings and Indexing: Choosing Models and Index Structure
Should You Use Dense, Sparse, or Hybrid Retrieval?
How Do You Measure RAG Pipeline Quality?
How Do You Keep a RAG Pipeline Fresh in Production?
Practical Checklist and Engineering Notes From Experienced AI Implementation Teams
How Do You Handle Multimodal Data in RAG Pipelines?
How Do You Prepare Noisy or Domain-Specific Data for RAG?
What Privacy and Compliance Rules Apply to RAG Data?
Team BRDGIT Perspective: When to Call In Fractional AI Engineering
How BRDGIT Helps You Build Production-Ready RAG
Sources
Corpus Selection and Data Ingestion for RAG
Before you write a single line of ingestion code, decide what belongs in the corpus and what doesn’t. Microsoft’s guidance on preparing a RAG solution is blunt about this: teams that skip straight to building pipelines without first analyzing their content and collecting representative test queries end up rebuilding the whole thing later. Start narrow. Pick one domain, one document type, and a handful of real questions users actually ask.
Freshness and access control matter just as much as topical relevance. A document that’s technically on-topic but three years stale, or one that a user shouldn’t be able to see, will quietly poison your retrieval quality or create a compliance headache.
Connector design should assume change from day one:
Build source-specific connectors for S3, your CMS, shared drives, and internal APIs rather than one generic scraper.
Preserve a stable document ID and a last-modified timestamp on every record so incremental sync doesn’t reprocess your whole corpus nightly.
Log the source path and access control list (ACL) at ingestion time, not later.
Run a small pilot batch (50 to 200 documents) before scaling to the full corpus.
Pro Tip: Write your first ten test queries before you ingest a single document. You’ll design better connectors when you know exactly what “found it” needs to look like.
How Do You Parse and Clean Documents for RAG?
Raw text extraction from PDFs, HTML, and scanned documents is where most RAG pipelines quietly fail. A naive PDF parser will happily flatten a two-column table into a jumbled sentence, or read a page footer as if it were body content. Layout-aware parsing preserves the visual structure, so tables stay tabular, captions stay attached to their images, and page order stays intact. Unstructured’s own analysis found that this kind of structure-preserving extraction, combined with metadata capture, produces meaningfully better retrieval accuracy than flat text dumps.
Cleaning comes next, and it’s less glamorous but just as necessary:
Strip repeated headers, footers, and page numbers that add noise without adding meaning.
Fix OCR artifacts (broken ligatures, misread characters) before they get embedded.
Normalize whitespace, line breaks, and character encoding across your whole corpus.
Flag and route tables separately from prose so they don’t get chunked into nonsense.
For tooling, Unstructured handles layout-aware partitioning across file types, PyPDF2 works well for straightforward text-based PDFs, and BeautifulSoup remains the standard for HTML parsing when you’re scraping documentation sites or wikis.
Which Chunking Strategy Should You Use for RAG?
Chunking is the decision that breaks more RAG pipelines than any other single choice. Redis’s engineering team, after examining common failure patterns, concluded that chunking strategy is the most frequent root cause of poor retrieval, ahead of embedding model choice or index configuration.
Four strategies cover most production cases:
Fixed-size chunking splits text at a set token count regardless of structure. It’s fast and predictable, but it slices sentences and ideas in half.
Recursive chunking splits on natural boundaries (paragraphs, then sentences) until chunks fit a target size. It respects structure better than fixed-size while staying cheap to compute.
Semantic chunking groups text by meaning shifts using embedding similarity between sentences. It’s more expensive to compute but produces cleaner, self-contained passages.
Late chunking embeds the full document first, then splits, so each chunk’s vector still carries context from its neighbors. It’s newer and costlier, but it helps with documents where meaning depends heavily on surrounding text.
Start with recursive splitting around 512 tokens with roughly 50 tokens of overlap. That default handles most business documents well. Move to semantic or late chunking only when your evaluation data shows recursive chunking missing context, not before. The MIRAGE benchmark team, building their 7,560-query evaluation set, settled on a 330-token segmentation for their experiments, a useful reference point if your documents run shorter than typical enterprise reports.
Chunk size ripples through everything downstream: smaller chunks mean a larger index, tighter retrieval precision, less context per generation call, and higher embedding cost.
Pro Tip: Don’t guess your chunk size. Run the same query set against three chunk sizes and compare hits@5 before you commit to a default.
What Metadata Should Every RAG Chunk Carry?
A chunk without metadata is a black box. When retrieval goes wrong, and it will, metadata is what lets you diagnose why in minutes instead of hours.
Every chunk needs, at minimum:
A document ID and source path that trace back to the original file.
Section title and page number for citation and human verification.
A last-updated timestamp so stale content can be filtered or deprioritized.
Access control labels (ACLs) so retrieval never surfaces content a user shouldn’t see.
Beyond the basics, running named entity recognition (NER) over each chunk and attaching normalized entity IDs pays off twice. It powers metadata filters (pull only chunks mentioning a specific contract number or product SKU) and it lays the groundwork for GraphRAG-style retrieval, where entity relationships supplement vector similarity. Teams that skip this step often find themselves reprocessing the entire corpus later just to add it back in.
Embeddings and Indexing: Choosing Models and Index Structure
Your embedding model choice depends on domain vocabulary, context length limits, and budget, in that order. A general-purpose embedding model handles marketing copy fine; it often stumbles on dense legal or engineering language where a domain-tuned or longer-context model earns its cost. Plan to re-embed whenever you materially change your chunking strategy or swap embedding models. Old vectors from a different model won’t play nicely in the same index.
Your index schema should store more than just the vector. A solid baseline includes:
The embedding vector itself.
The raw chunk text, for grounding the generation step.
The full metadata block (document ID, source, ACLs, timestamps).
A parent document link, so a chunk can be expanded to surrounding context when needed.
On index algorithms, HNSW gives you strong recall with fast lookups but consumes more memory per vector, while IVFPQ compresses vectors for lower memory use at some recall cost. For most mid-sized corpora, HNSW’s memory overhead is worth the recall gain. IVFPQ becomes attractive once you’re indexing tens of millions of chunks and memory becomes the bottleneck.
Should You Use Dense, Sparse, or Hybrid Retrieval?
Dense retrieval, matching by embedding similarity, handles conceptual and paraphrased queries well but frequently misses exact identifiers: part numbers, statute citations, legal case names. Sparse retrieval (keyword and term-frequency based, like BM25) catches those exact matches but misses conceptual overlap. Unstructured’s own analysis of preprocessing pipelines found that hybrid retrieval reduces missed exact-match hits on domain-specific terms where embeddings alone fall short.
For precision-sensitive queries, add a cross-encoder reranker as a second pass over your top candidates. It costs latency, often 50 to 200 milliseconds per query, but it meaningfully improves ranking when the first-pass retrieval returns a noisy candidate set.
Use hybrid retrieval by default for corpora with legal, technical, or product-code content.
Reserve rerankers for queries where precision matters more than raw speed.
Consider query transforms (rewriting a vague question into a more specific one) or HyDE-style techniques, generating a hypothetical answer first to improve the embedding match, when users ask underspecified questions.
Pro Tip: If your support team keeps escalating “the bot couldn’t find it” tickets for queries containing model numbers or case IDs, that’s almost always a sparse-retrieval gap, not a chunking problem.
How Do You Measure RAG Pipeline Quality?
You can’t tune what you don’t measure, and intuition about chunk size or retrieval settings is usually wrong. Build a small labeled test set, even 50 to 100 query-answer pairs, and measure against it before and after every pipeline change.
Four axes matter in production:
Retrieval quality, measured with Recall@K and Mean Reciprocal Rank (MRR), tells you whether the right chunk showed up at all.
Evidence faithfulness checks whether the generated answer actually reflects what the retrieved chunks say.
Citation quality verifies the model is pointing to the right source, not just a plausible-sounding one.
Latency and cost track what evaluation dashboards often ignore until production bills arrive.
The CLEAR-RAG framework formalizes exactly these five dimensions (adding Answer Relevance) into a single scoring rubric, which is worth borrowing even if you don’t adopt it wholesale. For a quick experiment, vary your chunk size across two or three settings and report hits@5 and MRR for each. The MIRAGE benchmark, built from 7,560 queries against 37,800 chunks, shows how much a well-labeled small-sample test can reveal about chunking decisions before you ever touch production traffic.
How Do You Keep a RAG Pipeline Fresh in Production?
A RAG index isn’t a one-time build. Documents change, get deleted, or get replaced, and your index has to keep pace without a full nightly rebuild. Databricks’ engineering guidance on production RAG pipelines recommends incremental sync patterns tied to source last-modified fields, plus chunk versioning so you can roll back a bad reprocessing run.
Track chunk versions so a bad chunking change can be reverted without a full reindex.
Invalidate cached retrieval results when the underlying source document changes.
Sample retrieval recall weekly against your labeled test set to catch silent quality drift.
Monitor latency, token cost per query, and citation failure rates as standing production signals.
Run PII detection on every reingestion pass, not just at initial load, since new documents bring new risk.
Practical Checklist and Engineering Notes From Experienced AI Implementation Teams
Running dozens of AI implementation engagements across manufacturing, distribution, and professional services teaches you fast which pilot steps actually predict production success. Here’s a version commonly recommended to clients starting their first RAG pilot:
Connect one source system, ingest 50 to 200 documents, and confirm stable IDs and ACLs before scaling.
Set your chunking default (recursive, ~512 tokens, ~50 overlap) and freeze it for the pilot.
Write 15 to 20 real test queries drawn from actual user questions, not hypotheticals.
Record hits@5, MRR, and citation accuracy for that query set before touching production traffic.
Revisit AI readiness before committing budget to a full build.
How Do You Handle Multimodal Data in RAG Pipelines?
Most RAG pipelines start text-only and hit a wall the first time someone asks a question that lives inside a chart, a scanned diagram, or a product photo. Images, tables rendered as images, and audio transcripts all need a path into your retrieval system, and that path looks different from plain text ingestion.
For images and diagrams, the practical approach is a captioning or vision-language step that converts visual content into descriptive text before it enters your standard chunking pipeline. That description gets embedded and indexed like any other chunk, with metadata pointing back to the original image file so the generation step can reference or display it. For scanned tables specifically, layout-aware extraction tools that preserve row and column structure outperform generic OCR, since a flattened table reads as gibberish to both a human and an embedding model.
Audio and video content need transcription first, ideally with timestamps preserved as metadata, so a retrieved chunk can point a user back to the exact moment in a recording rather than just the transcript text. This matters more than it sounds. A support team retrieving from a library of recorded training sessions gets far more value from “this answer comes from minute 14:32 of the onboarding call” than from an unanchored paragraph of transcript.
The general principle across every modality: convert to text-plus-metadata as early in the pipeline as possible, then let your existing chunking, embedding, and indexing steps handle it the same way they handle prose. Building a separate retrieval path for each data type multiplies your maintenance burden without a proportional gain in quality.

How Do You Prepare Noisy or Domain-Specific Data for RAG?
Domain-specific corpora, legal filings, engineering specs, clinical notes, bring problems generic pipelines don’t anticipate. Dense jargon, inconsistent formatting across decades of documents, and abbreviations that mean something different in your industry than they do in general language all degrade retrieval quality if you treat them like generic web text.
Start by profiling your corpus before building anything. Pull a random sample of 50 documents and manually check formatting consistency, encoding issues, and how badly OCR (if any documents are scanned) mangled the text. This sample tells you more about required cleaning effort than any generic checklist.
For inconsistent formatting, normalize aggressively at the parsing stage rather than trying to patch it downstream. If your corpus mixes documents from three different eras of a company’s document management system, expect three different heading conventions, and build parsing rules for each rather than one rule you hope covers everything.
Domain vocabulary is where generic embedding models show their limits fastest. A model trained mostly on general web text will embed “consideration” (the contract term) close to “consideration” (thoughtfulness) rather than close to other contract-law concepts. When your evaluation testing shows this kind of confusion, a domain-tuned or fine-tuned embedding model, or simply retrieval-side keyword boosting for known jargon, usually fixes it faster than trying to clean the problem away at the text level.
Noisy data rarely announces itself. It shows up as a chunk that reads fine to a human but embeds oddly, or a retrieval result that’s topically close but factually wrong. That’s exactly why the labeled evaluation set from your measurement plan matters more for domain-specific corpora than for generic ones. General intuition about what “looks clean” breaks down fast in specialized language.
What Privacy and Compliance Rules Apply to RAG Data?
RAG systems create a specific compliance risk that traditional search systems handle differently: once personal or sensitive information gets embedded into a vector index, deleting the source document doesn’t automatically remove its trace from that index. A “right to be forgotten” request or a contract expiration needs a deletion process that reaches the vector store, not just the source repository.
Access control has to travel with the chunk, not just the document. If a chunk of a shared drive file gets indexed with different permissions than a colleague’s version of that file, your retrieval layer needs to enforce the stricter of the two at query time. This is where the ACL metadata field from your chunking step stops being a nice-to-have and becomes the mechanism that prevents an embarrassing data leak.
PII detection deserves a dedicated pass, separate from general content cleaning. Running a detection step (looking for social security numbers, financial account details, health information) at ingestion time, before embedding, lets you redact or route sensitive fields rather than discovering a leak after the fact. Because RAG systems can surface exact source text in generated answers, PII that makes it into your index can resurface verbatim in a chatbot response months later.
Traceability rounds out the compliance picture. Every chunk should be able to answer, on demand, which source document it came from, when that source was last updated, and who is allowed to see it. That audit trail is what turns a compliance review from a weeks-long forensic exercise into a query against your metadata schema.

Team BRDGIT Perspective: When to Call In Fractional AI Engineering
Measurement-first pilots cost less and fail smaller than full builds. Once your evaluation data shows a governance gap or a scaling need beyond your team’s bandwidth, that’s the moment fractional engineering earns its cost, not before. Start with an assessment, run the pilot, then scale support to match what the metrics actually demand.
— Team BRDGIT
How BRDGIT Helps You Build Production-Ready RAG
BRDGIT is the alternative to hiring a full AI engineering team just to find out if your RAG pilot will work. You get the same measurement-first rigor covered above, chunking defaults tested against your actual documents, metadata schemas built for your compliance needs, retrieval tuned against a labeled query set, without carrying a full-time engineering headcount through the build.

The engagement path is straightforward: an AI readiness assessment identifies whether your data and use case are pilot-ready, a scoped pilot proves out chunking, retrieval, and evaluation metrics on real documents, and ongoing fractional AI engineering support carries the system from pilot into production monitoring and governance. That last piece matters most for teams without in-house ML infrastructure experience, since incremental reingestion, PII governance, and recall monitoring all need someone accountable once the system is live.
If your team has documents worth retrieving and a use case worth solving, the next step is a readiness conversation, not a hiring search. Reach out to BRDGIT to scope your pilot.
Sources
For deeper technical grounding, consult Microsoft’s RAG preparation phase guide for pre-build planning, the CLEAR-RAG framework for evaluation design, and this data pipeline engineering roundup for ingestion tooling comparisons.
Chunking for RAG: Strategies, tradeoffs & common mistakes (Redis blog)
Improving RAG Accuracy With Data Preprocessing Pipelines (Unstructured)



