Skip to content
AgentLabs.

RAG Agent Chunking: Document Structure, Chunk Size and Overlap

RAG Agent Chunking: Document Structure, Chunk Size and Overlap

RAG agents and chunks: how an AI agent selects useful pieces of knowledge

When you ask a question and the model does not really remember anything

Sometimes I sit at a screen, ask a new AI agent a question and feel I am speaking to a diligent intern who has read a great deal but cannot quite remember where. It remembers approximately. It invents a little. Sometimes intelligent, sometimes simply confident. This is where a retrieval augmented generation agent, or RAG agent, enters the story.

Instead of trusting vague model memory, we connect it to real documents: reports, contracts, articles, presentations and code. The engine searches for relevant information, returns it to the model and the model writes an answer based on that knowledge. Perfect on paper. In reality, it depends greatly on a seemingly technical, almost psychological question: how documents are divided into chunks.

Sounds petty? Why should it matter whether a contract is divided into passages of 200 or 800 words? It turns out to matter greatly. It distinguishes an AI agent feeling like a serious personal assistant from one returning generic answers or, worse, missing a critical clause.

What is a RAG agent, and what on earth do chunks have to do with it?

Begin with the basics, without grand terminology. A RAG agent is an AI agent relying not only on what its large model learned during training, but also on an external document repository. This could be an internal company knowledge base, a SharePoint folder or even PDFs you have sat on for years.

The process works roughly like this, simplified but functional:

The stages towards an intelligent answer

When a user asks a question, several things happen in the background:

1. The question goes to the RAG agent's search component, usually an embeddings-based engine.
2. The engine seeks relevant document sections: chunks, rather than whole documents.
3. These chunks are injected into the language model, which tries to answer from the supplied text.
4. The user sees an intelligent-looking answer and hopes it is correct too.

Here is the catch: good search requires dividing documents into smaller units. We will not feed an entire 200-page text into the engine for every query, because of cost and token limits. This introduces chunking.

Chunking: the art and science of dividing a document without ruining it

Chunking is where you tell the AI agent, “This passage ends here; a new chunk begins there.” But where is here? A sentence? Paragraph? Heading? Contract clause? Three hundred characters? A thousand tokens?

Cut too small and the engine finds highly specific pieces lacking context. Cut too large and each piece is rich in context, but search is less precise and the model spends half its context on noise.

This is not theoretical. Imagine a legal AI agent helping Israeli lawyers. Splitting a contract into 200-character chunks may scatter an important clause across two pieces, causing search to miss it. Conversely, treating the whole contract as one chunk will make the system fail when it handles more than one or two documents.

Chunks by length, structure or both?

In the real world, most teams begin by asking the recommended chunk size for RAG. Everyone asks; few like the answer: “It depends.”

Let us nevertheless bring some order:

  • Fixed-length chunking: simplest to implement and explain. Cut every X characters or tokens. Done.
  • Structure-based chunking: cut by headings, clauses, bullet points or paragraphs.
  • Hybrid chunking: structure first, then combine or split according to minimum and maximum lengths.

In practice, a serious AI agent, particularly in an Israeli business or legal setting, almost always ends up with something hybrid. Real documents, unlike blog examples, are not neatly structured. Nobody told your finance department about chunking best practices.

How does chunk size affect answer quality?

Here comes the critical question: why invest time and headaches in chunk size, overlap, splitting logic and more?

Search precision versus depth of context

Take two classic scenarios:

1. Chunks that are too small

Think of a newspaper cutting: two short sentences taken from an entire article. Can you understand the context, who is speaking or the real subject? The same happens when a RAG agent receives too small a document fragment:

  • Search may find a precise word or phrase match.
  • The model then has to guess the fragment's context.
  • The likelihood of creative inventions, or hallucinations, actually increases.

A good AI agent needs to understand where the right word appeared, beyond finding it. Was it a contractual exception, merely an example or a condition applying only on a particular date? Without context, the model drifts.

2. Chunks that are too large

A few months ago, a CTO at a large Israeli company told me they began with enormous chunks: “We simply took every documentation chapter and made it one unit.” It worked, until it stopped working.

When every chunk contains a whole page or several, problems appear:

  • Search returns much irrelevant text alongside the important passage.
  • A large part of the model's token allowance is wasted on noise.
  • With large repositories, document ranking becomes less precise because everything resembles everything else.

Suddenly, the AI agent gives long, impressive answers without addressing the user's specific concern, or mixes clauses that should not appear together.

Overlap: why intentional repetition is sometimes necessary

Another widely used term is overlap. Instead of non-overlapping passages, many systems create overlap: for example, a 500-token chunk followed by one beginning at token 250. Deliberate repetition.

The benefits of overlapping chunks

The intuition is simple: a sentence's meaning often depends on the sentence before or after it. A sharp cut can sever a critical passage in two.

Overlap ensures a sentence on the boundary appears in at least one chunk with neighbours on both sides. This matters particularly for:

  • Legal contracts, where “except” or “in relation to clause 3.2” can change everything.
  • Policy documents: conditions, caveats and versions.
  • Code: functions crossing lines, files or modules.

You can overdo this too

Excessive overlap puts many duplicates into the repository. Storage costs rise, search slows and retrieval becomes slightly less able to distinguish different document sections.

Simply put, overlap is like salt: without it, bland results; too much ruins the dish.

Beyond text: chunking suited to domain and content

A common AI agent mistake is assuming all documents are alike, that contracts, user guides, code and meeting minutes are all just text. They are not.

Contracts and law

In legal work, a good chunk usually aligns with a clause or subclause. Not necessarily the entire clause, which may span a page, but at least a unit with clear logic.

  • Sometimes the whole clause forms one unit.
  • If too long, divide it into subparagraphs while retaining connections between lines.
  • Avoid cutting through exception lists, definitions or complicated conditions.

A legal AI agent missing this structure gives answers lacking legal mileage. It is not stupid; it simply cannot see the whole picture.

Code and technical systems

For code, chunking needs to think like a programmer:

  • A typical chunk may be a function, class or small module.
  • Connections between files, imports and calls sometimes matter more than text length.
  • Overlap can help here too, for example when a function is logically divided into parts.

Sometimes, therefore, a custom build pipeline must understand code rather than merely characters. Create code-aware chunking, rather than cutting every 500 characters.

Product documentation, guides and help centres

Document structure here is usually friendlier: headings, subheadings and bullet points. A RAG agent built on a help centre can exploit this:

  • Each article becomes a parent unit.
  • An H2 or H3 heading provides a natural chunk boundary within it.
  • If still too long, divide by paragraphs while retaining minimum and maximum lengths.

The goal is that when users ask how to change their password, the AI agent finds precisely the relevant guide, rather than a paragraph in a general security text.

Israel, Hebrew and the disorder of real documents

There is another layer many international RAG solutions do not fully handle: Hebrew, particularly Israeli business Hebrew.

Hebrew documents tend to be:

  • Less structurally consistent.
  • Full of internal abbreviations, not always explained.
  • Mixing Hebrew, English and numbers on one line.

Building an AI agent for an Israeli company also means language differences: Hebrew documents, English documents and bilingual ones. Chunking must handle them all without dividing documents until their meaning dissolves.

A small example from the field

In one project I encountered, an Israeli development team built a RAG agent for a service department. They began with chunks of 1,000 characters, without structure or sophistication. The system worked, but answers were not always accurate.

After several tuning rounds, they adopted a different approach:

  • First split by help-centre article headings.
  • Then divide particularly long passages while retaining at least two paragraphs per chunk.
  • Add one paragraph of overlap between neighbouring chunks to maintain continuity.

According to their internal measures, answer satisfaction improved significantly. Because the model received better-organised raw material, rather than becoming more intelligent.

Questions and answers: what everyone asks about chunking and RAG

How should you choose an initial RAG agent chunk size?

A practical, rather than absolute, recommendation is 300–800 tokens, roughly half a page to a page and a half, with 10–20% overlap. Then measure accuracy rates, user satisfaction and hallucination counts. Do not hesitate to adjust.

Should every content type receive its own chunking strategy?

In one word, yes. In a sentence, the more seriously you take organisational AI agents, the more sense it makes to tailor chunking for contracts, product documentation, minutes and code. You need not begin there, but that is the direction.

What happens without chunking?

Feed whole documents to the retrieval engine and usually:

  • Search becomes heavier and slower.
  • Fewer precise matches are found.
  • Tokens are wasted on irrelevant parts of the answer.

Ultimately, your AI agent behaves more like a general search engine than an intelligent assistant knowing precisely where a document hides the answer.

How much overlap is normal?

There is no sacred number, but most systems use between 10% and 30% of chunk length. For a 500-token chunk, 50–150 tokens of overlap is a reasonable starting area.

How do you distinguish a chunking problem from a model problem?

A painful question. If the AI agent answers from incorrect sources or misses a relevant document, check retrieval and chunking first. If it retrieves the right document but writes the wrong answer, the model or prompt wording is more likely responsible.

Summary table: what affects what?

ParameterWhat it means in practicePossible benefitRisk when overdoneAI agent notes
Chunk sizeFragment length in tokens, characters or paragraphsMore context and fewer inventionsLess search precision and wasted tokensDirectly affects RAG agent answer quality
OverlapShared content between neighbouring chunksContinuity and fewer cuts through an ideaDuplicates and index loadCritical in complex legal and technical documents
Structure-aware splittingDividing by headings, clauses or functionsCapturing meaningful knowledge unitsDevelopment complexity and dependence on document qualityMakes an AI agent feel domain-aware
Document typeContract, code, documentation, minutes and so onDomain-specific strategy adaptationMore configuration and maintenanceKey when building an AI agent for a large organisation
Language and charactersHebrew, English, mixtures and abbreviationsFewer parsing errors and distortionsRequires real testing on a local corpusHebrew must be taken seriously in Israel
Document volumeKnowledge-base sizeMore knowledge accessible to the RAG agentPoor chunking makes correct retrieval very difficultChunking quality becomes more critical as the repository grows

Between algorithms and practice: approaching this without getting lost

We could discuss algorithms, embeddings and rerankers for hours. Ultimately, anybody establishing an AI agent in Israel or elsewhere is judged by a simple question: do people use and trust it?

Good chunking resembles good article editing. Readers do not think about it, but it separates flowing text from chaos.

Practical insights without turning this into a checklist

Start simply, but measure

Do not spend months planning perfect chunking before even activating the RAG agent. Begin with:

  • A medium length of 500–700 tokens.
  • Moderate overlap.
  • Basic paragraph or heading boundaries where available.

Then measure: how often are answers inaccurate? In which document types and domains? That shows where chunking needs improvement.

Speak to the system's users

Obvious, perhaps, but many development teams skip this. Users feel when an AI agent speaks to the point and when it struggles. Lawyers, support staff and product managers each have a different intuition about a unit of meaning. These are precisely the people to invite into chunking discussions.

Do not fear differences across the system

One system may well need:

  • One chunking strategy for contracts.
  • Another for internal documentation.
  • A third for code.

This is recognising that a good AI agent treats knowledge types differently, rather than disorder. There is no reason to impose artificial uniformity.

Looking ahead: when an AI agent chooses its own cuts

Experiments already exist, some highly interesting, where the system itself tries to learn chunking. Instead of setting 500 tokens in advance, other models mark natural text boundaries: where one idea ends and another begins.

A future RAG agent may run another AI agent behind the scenes solely as a content editor: taking a document, dividing it logically, tagging it and marking connections.

Until that matures, those building systems today, particularly in Israel with mixed infrastructure, mixed languages and tangled legacy systems, must view chunking as strategic rather than peripheral. Like choosing the right data structure in a large system: invisible externally, but everything creaks when it is wrong.

Conclusion: where text ends and decisions begin

Looking at a successful AI agent that actually helps people rather than merely appearing in a presentation, it is easy to focus on the model, brand or latest GPT. Beneath the surface, however, much of the magic happens quietly: how documents are stored, tagged and, above all, divided.

Correct document chunking is no single formula or uniform best practice copied from Stack Overflow. It combines domain understanding, listening to users, model familiarity and some trial and error.

If you are considering establishing or improving an organisational RAG agent, weighing chunk size or overlap, or wondering how to handle disordered Hebrew documents, this deserves serious discussion. We would be happy to help with an initial consultation at no cost, avoiding recurring AI agent project mistakes and saving several rounds of “Why doesn't this work as expected?”

From reading to a pilot

Connect the agent to your knowledge sources

We will map where information is stored, who may access it and how to check an answer against its source.