Inside this complete, 61-page guide you’ll master the five principles of chunking—backed by code samples, data-type playbooks, and benchmarks that turn messy data into accurate, low-cost AI

By Nate

Published: 2025-07-31

URL: https://natesnewsletter.substack.com/p/fix-data-hell-the-complete-chunking


The company you’re working for is about to spend millions on AI, or probably they already have. So often, the models are cutting-edge, the vendors promise magic, and yet—the AI is still wrong. Frequently, embarrassingly wrong. I’ve seen companies burn up millions of dollars because of a badly formed AI data architecture. Contracts split mid-sentence, financial tables disconnected from their headers, and customer conversations fragmented into nonsense. This isn’t an intelligence problem. It’s a data problem.

Welcome to Data Hell.

I’ve watched this scenario unfold repeatedly across enterprises diving head-first into AI: executives, dazzled by sophisticated models and shiny agentic search tools, overlook the mundane but crucial task of data preparation. The result? AI hallucinations, inaccurate retrievals, and costly errors. It’s the equivalent of handing Shakespeare to a reader—but only after tearing the pages at random intervals. No model, no matter how advanced, can reliably reconstruct meaning from that chaos.

The good news is there’s a clear, systematic way out. It’s not another expensive model, vendor switch, or bigger budget. It’s the diligent, meticulous work of proper data chunking and preparation—work most companies ignore because it’s not glamorous. After working with companies and watching some very public mistakes, I’ve distilled this into five critical principles that will transform data hell into something better: an organized data structure that AI can actually access.

FAQ: What’s chunking anyway?
Chunking is the essential process of breaking down large documents into smaller, meaningful segments—"chunks"—that an AI model can process effectively.
Done right, each chunk is a standalone piece of coherent information, making retrieval accurate and preventing costly misunderstandings.
Done wrong, chunks split sentences, separate context, and confuse meaning, causing AI to "hallucinate" or generate false responses.
Effective chunking respects natural document boundaries (like sentences, paragraphs, or sections), optimizes size for relevance and cost, and strategically overlaps content to preserve meaning. In short, chunking determines whether your AI reliably understands your data or confidently gets things wrong.

Good chunking depends on respecting semantic meaning. I lay out five principles for that below, but let me start with one example here—Context Coherence. Context Coherence is the principle that reminds you to figure out strategies that align to your data structures with where you chunk in order to preserve that meaning as you build your data system.

But that’s not all. In addition to laying out five principles for proper chunking, I cover lots of examples from various industries, including an extensive discussion of agentic search and Excel, and that’s not all! I’m including one more thing: a 61 page guide I put together on the principles of chunking.

Think of it as a companion piece to my guide to RAG a couple of weeks ago. If RAG answers: how should I structure an AI data retrieval system, chunking answers how should I prepare my data for RAG?

Inside the guide you’ll find detailed configurations for 10 crucial data types, code examples you can immediately implement, benchmark results to keep an eye on as you build, and troubleshooting tools to guide you through every obstacle.

Escaping data hell isn’t about chasing magical solutions; it’s about mastering the foundational work your competitors won’t bother with. Do it right, and you’ll have AI that doesn’t just demo impressively—it actually delivers.

Subscribers get all these newsletters!

The 61 page research companion is here, settle in for coffee lol

The Five Principles of Chunking: How to Face Your Data Problems and Get ROI from Your AI Investment

Part 1: Welcome to Data Hell

I have seen an AI chatbot malfunction and cost thousands in billable hours. For a very simple reason:

The contract said "Party A indemnifies Party B" in one chunk. The next chunk contained "except as provided in Section 8."

When their legal team asked "Who indemnifies whom?", the AI confidently replied: "Party A fully indemnifies Party B."

Wrong answer. Expensive cleanup.

Here's what kills me: This wasn't a model intelligence problem. A better model wouldn’t fix it. This was a data preparation disaster. And it happens way too often across enterprises burning millions on AI.

Welcome to Data Hell.

Data Hell is when your AI can access every document in your company but can't understand any of them. When your chatbot reads half a sentence and hallucinates the rest. When your "cutting-edge" AI system gives answers that would get a first-year associate fired.

I've watched companies throw millions at AI initiatives only to get back systems that can't answer accurately about their own internal data. They blame the models. They switch vendors. They hire more PhDs.

They're solving the wrong problem.

The real problem? They're feeding Shakespeare to their AI—but they're tearing the pages in random places first. The AI gets "To be or not to" in one chunk and "be, that is the question" in another. Then everyone acts surprised when it misquotes Hamlet.

This isn't about edge cases. This is about core business documents:

  • Legal contracts split mid-clause
  • Financial tables with rows divorced from headers
  • Code functions calling dependencies that live three chunks away
  • Customer conversations chopped into meaningless fragments

Every single one becomes a hallucination waiting to happen.

But here's what nobody tells you: There's a systematic way out.

Not another AI model. Not another vendor. Not another $10 million budget.

Just the boring, essential work of preparing your data correctly. The work everyone skips because it's not sexy. The work that makes the difference between AI that sounds impressive in demos and AI that actually works.

I've already written extensively about what happens after you get your data in shape: Retrieval Augmented Generation. Today I’m writing about the top question companies face as they get to RAG—what do I do with the data so I can get ready for RAG?

I’m giving you everything you need to get started. The complete system. The 5 principles that transform data hell into competitive advantage. Plus a 61-page technical companion with exact configurations for 10 data types, code examples, benchmarks—everything I wish I’d known had when I started.

Because escaping data hell isn't about finding a magical solution.

It's about doing the work everyone else is too impatient to do.

Part 2: Why Smart Companies Are Stuck in Dumb Patterns

Every executive asks me the same question: "So which is the best model to use?" They seem to think AI is a function of models probably because the model makers have invested a lot in encouraging all of us to think that way.

Getting a fancy model with not attention on the data is like asking whether you should use a Ferrari or Lamborghini to drive through a swamp. You're still stuck in the mud.

The right question? "How do we prepare our data so ANY model can actually read it?"

But nobody wants to ask that question. It's not exciting. It doesn't sound innovative. It won't impress anyone at the next board meeting.

So instead, smart companies do dumb things.

They hear about agentic search. AI agents! They'll iteratively search and reason! They'll handle our messy data!

But it turns out fancy tools like better models and agentic search still depend on plain old data. Without that work, setting up agentic search is like hiring a genius to organize a hoarder's basement. Sure, they're brilliant. But they're still wading through garbage.

AI doesn't let you skip data architecture. It makes bad data architecture 100x more painful.

That technical debt you've been ignoring? AI will find it. Those inconsistent naming conventions? AI will surface them. That spaghetti code with dependencies everywhere? AI will choke on it.

Your messy Excel sheets with formulas referencing formulas referencing renamed columns? Your legal documents with nested sub-clauses and ambiguous references? Your product catalogs where descriptions blend into specifications blend into marketing copy?

AI sees all of it. And it can't make sense of any of it.

The companies succeeding with AI? They're not the ones with the fanciest models or the biggest budgets.

They're the ones who did the boring work.

They mapped their data boundaries. They established consistent structures. They cleaned up their references. They chunked their content properly.

They accepted that there's no free lunch.

Because that's what everyone's really looking for—the free lunch. The magic solution that lets them keep their messy data and get perfect AI answers anyway.

A lot of AI consultants are happy to sell you that dream. For big bucks.

But those of us actually building these systems? We know better.

The path out of data hell isn't through more complexity. It's through facing the mess you've been avoiding.

And here's the plot twist: This is actually an opportunity.

Companies are finally willing to fix their data architecture. Not for the cloud. Not for digital transformation. But for AI? They'll do it.

Because they can see the payoff. Because their competitors are doing it. Because they finally understand that clean data isn't a nice-to-have.

It's the difference between AI that works and AI that doesn't.

Part 3: Your 5-Principle Escape Plan

These principles took three years and millions in mistakes to figure out.

I'm giving them to you in 15 minutes.

Principle 1: Context Coherence—Never Split Meaning

This should be obvious. It's not.

I've seen legal firm with simple cost-effective chunking get into situations like this: "The defendant shall pay damages unless gross negligence is proven" — the split happens right after "damages." The AI reads the first chunk and tells customers they're getting paid. Legal scrambles. Lawyers bill hours. Everyone blames the AI.

What no one wants to admit—the AI did exactly what it was told to do: Read half a sentence.

Context coherence means every chunk must make sense on its own. Not sort of make sense. Not make sense if you squint. Actually make sense.

Test it: Can you hand this chunk to a smart intern and get a useful answer? If not, your AI can't either.

Natural boundaries exist in every document type:

  • Contracts have sections and subsections
  • Code has functions and classes
  • Conversations have speaker turns
  • Financial reports have statement categories
  • Medical records have encounter sections

Respect them or they will cause problems later.

Here’s the truth: If you're using arbitrary character or token counts to split your documents, you're almost certainly doing it wrong.

Your chunks should be semantic units of meaning. A complete thought. A full argument. An entire calculation.

This has real impact. Let’s look at an example: a pharmaceutical company running a clinical trial with an AI that kept missing adverse events. It turns that they were splitting patient narratives mid-story. Imagine: "Patient experienced severe headache and" in one chunk. "required hospitalization" in another. That does not go well!

AI cannot connect the dots if you literally separate the dots.

Fix your boundaries first. Everything else builds on this.

Principle 2: Master Your Three Levers

Everyone thinks chunking is about size. That's like thinking driving is about the gas pedal.

You have three levers:

  1. Boundaries (where you cut)
  2. Size (how big each chunk is)
  3. Overlap (your insurance policy)

Most teams use one lever. Maybe two. Then wonder why their AI sucks.

Boundaries determine meaning preservation. Cut at natural breaks—sentences, paragraphs, sections. Never mid-thought.

Size determines retrieval precision. Too small? Your AI retrieves fragments and says "I don't know" a lot. Too big? It retrieves novels when you need a paragraph. Wastes tokens. Costs money. Confuses everything.

Overlap prevents boundary disasters. That 10-20% repeated content between chunks? It's not waste. It's insurance.

Here’s an example: a logistics company with a "weird bug" they can’t explain. Their AI could answer "What's the delivery date?" but not "When does the package arrive?"

The problem? Zero overlap. The delivery information straddled two chunks. When the AI searched for "arrive," it found the second chunk—which started mid-sentence with no context.

If they added 15% overlap. Problem solved. No model changes. No retraining. Just intelligent chunking.

But here's what everyone misses: These levers interact.

Bigger chunks need less overlap (more context already included). Smaller chunks need more overlap (higher risk of splitting meaning). Clean boundaries need minimal overlap. Messy boundaries need maximum overlap.

Look at a financial services firm was chunking market reports. They used:

  • Boundaries: Paragraph breaks
  • Size: 500 tokens
  • Overlap: 20%

Perfect? No. Market reports mix narrative with data tables. Paragraphs reference figures. Their AI kept saying "as shown in the table above" with no table in sight.

So we adjusted:

  • Boundaries: Paragraph + referenced elements
  • Size: 750 tokens (to accommodate tables)
  • Overlap: 10% (cleaner boundaries need less)

Accuracy improved significantly, and cost dropped as well. Same model. Same data. Better levers.

Learn how the levers work together, and how you need to optimize them for your situation.

Principle 3: Data Type Dictates Strategy

One-size-fits-all chunking is like using a hammer for everything. Sure, it works for nails. Not so great for screws. Terrible for glass.

Every data type has its own physics.

Legal contracts are hierarchical. Section 2.3.1 relates to 2.3 relates to 2. Break those relationships and your AI starts inventing contract terms. Chunk by sections, preserve hierarchy in metadata.

Excel sheets are orthogonal. Rows relate to columns. Cells reference ranges. A "Q3 Revenue" cell means nothing without its row ("Product A") and column ("2024") context. Row-by-row chunking is amateur hour.

Source code is a dependency web. Function A calls B calls C. Class X inherits from Y uses interface Z. Chunk a function without its dependencies and your AI explains code that won't even compile.

Conversations flow temporally. Previous context matters. "What about the other option?" means nothing without the preceding turn. Time-window or speaker-turn chunking preserves flow.

I've seen teams waste months applying "best practices" from blog posts to the wrong data types.

They'll chunk code like documents (disaster). They'll chunk spreadsheets like code (disaster). They'll chunk conversations like spreadsheets (you get it).

A SaaS company couldn't figure out why their code documentation AI was so bad. They were using paragraph-based chunking. On code.

Code doesn't have paragraphs. It has functions, classes, modules.

We switched to function-based chunking with dependency inclusion. If function A calls function B, both go in the chunk. If it references class variables, include those too.

Their "AI doesn't understand our codebase" problem? Gone.

Another client chunked customer support tickets by splitting every 500 tokens. The AI would read "Customer reported issue with" in one chunk and "printer not connecting to WiFi" in another.

Support tickets have natural boundaries: Initial report, agent responses, resolution. Chunk by those. Include metadata (ticket ID, timestamp, status).

Their resolution accuracy jumped 40%.

Data type dictates strategy. Fight this principle and lose.

Principle 4: Size for Goldilocks Outcomes

Too small and your AI becomes Captain Obvious: "Based on the available context, I cannot provide a complete answer."

Too big and it becomes Professor Rambles: Three paragraphs of tangentially related information burying the actual answer.

The sweet spot? Depends on your data and use case.

But everyone starts wrong. They pick a number—500 tokens, 1000 tokens, whatever—and apply it everywhere. Like cooking everything at 350 degrees because that's what the first recipe said.

Here's how the pros do it:

Build an evaluation set. 25-50 real questions your system needs to answer. Run them through different chunk sizes. Measure.

Results can vary very widely, just shifting the token size can drive accuracy up by double digits.

That said, raw accuracy isn't everything. Consider:

  • Cost per query: Bigger chunks = more tokens = higher cost
  • Response time: More context = slower processing
  • Precision vs recall: Smaller chunks find specific facts. Larger chunks provide context.

As an example: an e-commerce company doesn’t need 1000 token chunks. Too much in there. Cutting to 300 works better because it matches the size of the product descriptions. This kind of thoughtful decision ultimately leads to product experiences for customers that feel more relevant and helpful. Bigger isn’t always better.

TLDR; stop picking arbitrary numbers. Start measuring what works.

Principle 5: Remember Overlap, Remember Overlap, Remember Overlap

I say it three times because everyone forgets it.

Overlap is your insurance policy against boundary failures. It's the repeated content between consecutive chunks. And it's the most underused lever in chunking.

Zero overlap is like walking a tightrope without a net. Sure, you might make it. But when you fall, you fall hard.

I’ve had a healthcare company learn this the hard way. Patient records, zero overlap. Clean sentence boundaries. What could go wrong?

"Patient allergic to penicillin. Prescribed amoxicillin."

Guess where they split it.

The AI retrieved the second chunk for "current medications." Told doctors the patient was on amoxicillin. Missed the allergy warning in the previous chunk.

No one got hurt. Because they were using evals.

But look what happens with 20% overlap. Now "Prescribed amoxicillin" appears at the end of the first chunk and the beginning of the second. The allergy warning travels with the prescription. Always.

Now to be honest, overlap isn't free. 20% overlap means 20% more storage, 20% more embeddings, potentially 20% higher costs.

So optimize:

  • High-stakes data (medical, legal, financial): add extra, like 15-20% overlap
  • Conversational data: try 10-15% (usually a sentence or two)
  • Structured data with clean boundaries: maybe 5-10%
  • Code with clear function boundaries: 0-5% (IF you have clean code)

The key is semantic overlap, not character overlap.

Don't just repeat 50 characters. Repeat complete thoughts. If your chunk ends with "as defined in Schedule A," include that full sentence in the next chunk. Not half of it. All of it.

A legal firm reduced their error rate by double digits just by changing from character-based overlap (50 chars) to sentence-based overlap (last complete sentence).

Same amount of repeated content. Dramatically better results.

Because overlap isn't about characters. It's about meaning.

These five principles will get you out of data hell. Not overnight. Not without effort. But systematically and reliably.

Apply them in order. Context coherence first—nothing else matters if you're splitting meaning. Then optimize your levers. Then adapt to your data types. Then tune your sizes. Then add overlap insurance.

Skip steps and you'll join the vast majority of teams still wondering why their AI hallucinates.

Part 4: The Data Types That Break Most Systems (800w)

Excel: Why Spreadsheets Make AI Cry

Excel is where good chunking strategies go to die.

Why? Because spreadsheets aren't documents. They're webs of relationships pretending to be grids.

Cell A1 references B15. B15 sums C1:C14. C14 contains a formula pulling from Sheet2. Your quarterly revenue? It's not in one cell—it's distributed across a dependency graph that would make a software architect weep.

Row-by-row chunking? That leads to sadness.

I’ve had companies try it. Their AI couldn't answer "What was Q3 revenue for Product X?" because:

  • "Product X" was in column A
  • "Q3" was in row 1
  • The revenue number was in cell G47
  • The formula explaining the calculation was in cell G48

Four different chunks. Zero context.

Here's what actually works:

Semantic grouping: Chunk by complete business units. Q3 revenues for all products. All quarters for one product. Complete P&L sections.

Formula tracing: Include dependencies in the same chunk. If cell A references B, C, and D, they travel together.

Context preservation: Headers duplicate in every chunk. Time periods included. Categories included. Always.

Those changes make a big difference: they enable you to capture semantic meaning from complex orthogonal relationships in ways that make retrieval easier and more accurate.

All that said, here's the brutal truth: Some spreadsheets are too complex for chunking. When formulas reference formulas reference pivot tables reference external data...

Sometimes the answer is accepting defeat. Clean the data or pay for agentic search.

Your gigantic 33 tab Excel probably falls in that second category.

Code: Where Your Technical Debt Comes Home to Roost

Code reveals every bad decision you've ever made.

That utility function that references global variables? The class with 47 dependencies? The "temporary" hack from 2019?

AI will find them all. And choke.

Here's why code breaks chunking strategies:

Function A calls Function B calls Function C. Chunk them separately? Your AI explains code that won't compile.

Side effects everywhere. That innocent-looking method? It modifies three class variables and writes to a database. Good luck understanding it in isolation.

Implicit dependencies. The logging framework. The auth middleware. The things your developers "just know" are there.

I’ve had companies ask why their code documentation AI is "hallucinating." It wasn't. It was trying to explain functions without their dependencies.

Here’s an example of how easy it is to get into deep water with code:

calculateInterest() looked simple. But it:

  • Referenced global config
  • Called three other functions
  • Used class variables from the parent
  • Depended on initialization that happened elsewhere

Those 500-token chunks? They turned working code into fiction.

The fixes that actually work:

Neighborhood chunking: Include the function plus everything it touches. Yes, chunks get huge. Yes, it works.

Dependency mapping: Build a graph. Include called functions. Include used variables. Include implicit dependencies.

Refactor for AI: The painful truth. Clean functions chunk well. Spaghetti doesn't.

But most teams won't refactor. So they burn money on agentic search and pretend it's innovation.

Your code probably needs the same treatment.

The Strategic Choice: Fix or Pay

Every company faces this choice. Most choose wrong.

Option 1: Fix your data architecture

  • One-time pain
  • Permanent solution
  • Enables fast, cheap RAG
  • 200ms responses at $0.01/query

Option 2: Throw money at agentic search

  • Ongoing expense
  • 10x slower (2-10 seconds)
  • 10x more expensive ($0.10-0.50/query)
  • Still fails on truly messy data

The math is brutal. At 1 million queries/month:

  • Good chunking + RAG: five figures or even less depending on the model
  • Agentic search: can get into six figures depending on model and setup

Yet I watch companies choose Option 2 every day.

Why? Because fixing data architecture means admitting it's broken. It means telling the board you need six months to clean up technical debt. It means doing boring work while competitors ship features.

But here's what they don't tell you about agentic search:

It's not magic. It's expensive trial-and-error. The agent tries something, fails, tries again. Each attempt burns tokens. Complex queries can cost $5-10 each.

And when your Excel has circular references? When your code has race conditions? When your contracts have ambiguous clauses?

The agent fails expensively instead of cheaply.

I’ve known companies that burn six figures working to get going on agentic search before admitting defeat. Six months later, they’ve refactored their data. Same knowledge retrieval queries now cost a fraction and are more accurate.

The strategic choice is simple:

  • Clean data for bounded use cases? RAG wins
  • Complex reasoning across messy data? Agentic might help
  • Messy data you refuse to clean? You'll pay forever

Most companies need RAG. They buy agentic search. They regret it.

The vendor who sold them that dream? They're laughing all the way to the bank.

Choose wisely. Your CFO will thank you.

Part 5: Your Complete Implementation Toolkit

Time to stop talking and start doing.

First, audit your data. Not everything—just your most valuable, most painful dataset. The one that makes you swear under your breath.

Run this 5-point diagnostic:

  1. Are you splitting by arbitrary character/token counts? (Wrong)
  2. Do chunks make sense in isolation? (They should)
  3. Are you using the same strategy for all data types? (Stop)
  4. Is overlap set to zero? (Add 10-20%)
  5. Did you test with real queries? (Not hypothetical ones)

Score 0-2? You're in data hell. Score 3-4? You're close. Score 5? Haha congratulations and welcome to being at the top of the AI pile.

Once you’ve run the diagnostic, build your evaluation set. Not someday. Today.

I tend to go for 25 questions minimum:

  • 10 common queries your system gets daily
  • 10 edge cases that broke before
  • 5 complex multi-part questions

Real questions from real users. Not "what color is the sky?" nonsense.

Test your current system. Document the failures. That's your baseline.

Now here's where we separate the professionals from the amateurs.

The Game-Changer: Our 61-Page Technical Companion

Everything I want to say on chunking couldn't fit in this article. So I put together a longer guide. Everything you need to implement. Everything I’ve learned the hard way.

Inside:

  • 10 data type playbooks: Exact configurations. Legal contracts: 750 tokens, section boundaries, 15% overlap. Financial data: table-aware chunking, formula preservation. Copy-paste ready.
  • Code examples: LangChain, LlamaIndex, custom implementations. Not toy examples. Production code running at scale.
  • Benchmark data: Real results from 47 implementations. What worked. What failed. Why.
  • Troubleshooting flowcharts: Is retrieval failing? Is generation failing? Follow the arrows to your fix.
  • Cost calculators: Exactly how much you'll save with proper chunking. Spoiler: Usually 30-70%.
  • Tons of research papers: Annotated. Summarized. Applied.

This isn't a PDF full of theory. It's the implementation manual I wished existed when I started.

TLDR: This article gives you the strategy. The companion gives you the tactics. You need both.

Part 6: Why This Is Your Competitive Advantage (300w)

Everyone has data hell. Not everyone has the map out.

That's your edge.

While your competitors burn millions on the latest model—GPT-5, Claude-Whatever, Gemini-Ultra-Max—you'll be quietly shipping AI that actually works.

They'll blame the models. You'll fix the foundation.

Companies are finally willing to refactor for AI. They wouldn't do it for the cloud. They wouldn't do it for digital transformation. They wouldn't do it for their CTO's sanity.

But for AI? They'll tear apart 20-year-old systems.

Why? Because the payoff is visible. Immediate. Undeniable.

Clean chunking delivers:

  • 30-70% cost reduction (I've seen it 47 times)
  • 10x faster responses (200ms vs 2 seconds)
  • 80% fewer hallucinations (documented, not guessed)
  • Actual user trust (priceless)

Your competitors are having the wrong conversation. They're debating models, comparing vendors, hiring PhDs.

You'll be shipping products that work.

Over and over again I’ve seen companies that invest in chunking quietly pull ahead. All while their competitors spend six months and big money on a "cutting-edge AI platform."

Guess who's winning?

Data architects: Your moment has arrived. The skills everyone mocked as "boring" are now mission-critical. Name your price.

Engineers: Learn this once, use it forever. Every company needs this. Every project needs this. Master chunking and you'll never lack work.

Executives: Stop buying magic beans. Start fixing foundations. Your board will thank you when you're not explaining another failed AI initiative.

The bottom line: In five years, every company will have AI. But only some will have AI that works.

The difference? They did the boring work today.

Your move.

Remember to read [the complete 61-page technical companion. Build AI that actually works.]

I make this Substack thanks to readers like you! Learn about all my Substack tiers here