Engineering notes
Legal RAG: why we split documents by article, not by size
A document search is only as good as its chunks. Cutting a statute every thousand characters separates the rule from its exception. In Magnus’s legal agent every chunk is an article, knows which law it comes from, and can be cited.
- Published
- Reading
- 7 min read
01
What breaks when you split by size
RAG —retrieval-augmented generation, the technique Lewis et al. described in 2020— does not give the model your documents: it gives it chunks. Before anything is searched, each document is cut into pieces, each piece is indexed, and when a question comes in the most similar pieces reach the model. Whatever is not in those pieces does not exist for the model.
The most common way to cut is by size: every so many characters, with a little overlap. In a product manual that works reasonably well. In a legal text it does not, because the unit of meaning is the article, and articles are not all the same length.
-
The rule without its exception
The article says what must be done and, two lines further down, “unless…”. If the cut falls in between, the retrieved chunk states the rule without the exception, and the model repeats it with full confidence.
-
The subsection without its article
A loose “(b) where the contract…” does not say which article, law or chapter it belongs to. It can be found, but it cannot be cited.
-
Two provisions in one piece
The end of one article and the start of the next end up together, and the answer blends two rules that have nothing to do with each other.
This is not theoretical. A Stanford study evaluated commercial legal tools built on RAG and found they got it wrong or made things up in more than one in six queries, even citing sources that did not support what they said (Magesh et al., 2025). And among the failures Barnett et al. documented in real RAG systems is a very concrete one: the answer is in the documents, but it does not arrive among the chunks the model sees.
02
How we split: one article, one chunk
-
One chunk per article
The cut follows the structure of the text, not a character count. Each article goes in whole, with its rule and its exceptions together.
-
If it is too long, by subsection, without losing where it came from
An article that is too long is divided by subsection, and each subsection carries the article number, the chapter, the title and the law it comes from. No piece is left orphaned.
-
Every chunk knows what it is
Alongside the text we store what the structure already says, without spending a single model call: article number, law, chapter, the dates that appear and the other articles it refers to. A separate model pass adds what each article is about: who the subject is, which right it grants, which obligation it imposes.
-
The search can be narrowed
With that data, a search can stay within one law or one branch of law instead of pulling whatever looks most similar from the whole corpus.
It is the same idea Anthropic measured in 2024 with what it called Contextual Retrieval: a chunk that does not know where it comes from is retrieved worse. Adding its context to each chunk cut failed retrievals by 35%; by 49% combined with keyword search, and by 67% adding reranking. In a legal text that context is already written into the structure, and reading it costs nothing.
03
Cite, or flag
Splitting well has a second advantage: every chunk has a name. That is why the legal agent answers citing article and law, and what it cites is checked against what was actually retrieved.
If the answer mentions an article that was not among the retrieved documents, there are two cases. If it was presented as verified, it is an invented citation, and that answer does not go out. If the agent marked it as general knowledge —something it knows but that is not in your documents—, the answer goes out with a clear notice that this part is not backed by your corpus.
The difference matters: a false citation is an error; a useful fact without backing, stated as such, is honest information.
04
Beyond legal texts
The principle works for any document with a structure of its own: a contract is split by clause, a regulation by article, a manual by procedure, a commercial policy by rule. The question for every corpus is the same:
- What is the smallest unit that can be cited without losing its meaning?
- What does that chunk need to know about itself to be found and cited on its own?
05
What this does not solve
- A well-split chunk of a repealed law is still a repealed law. Keeping provisions current is corpus maintenance, not search.
- If the answer is not in the documents, splitting better does not create it. The honest thing is to say it is not there.
- Texts without an article structure —a ruling, a memo, an email— are split by paragraph, with the same precautions as any RAG.
- Measuring this properly takes a question bank built by experts, such as LegalBench-RAG: 6,858 questions that check whether the exact snippet is retrieved, not the whole document. We have not published a measurement of our own yet; when we have one, it will be in Magnus Lab.
Sources: Lewis et al., 2020 — Retrieval-Augmented Generation Magesh et al. (Stanford), 2025 — Hallucination-Free? Barnett et al., 2024 — Seven Failure Points of RAG Anthropic, 2024 — Contextual Retrieval Pipitone & Houir Alami, 2024 — LegalBench-RAG
RAG does not search your documents: it searches the pieces you cut them into.