Chunking
Tables in RAG chunks: repeat the header or write header-value rows
Split web tables for retrieval without orphaned rows: repeat the header row in every piece, or rewrite each row as header-value pairs, then test both.
By Rose Donaldson, Context Retrieval team · Published
This article was drafted with AI assistance from the sources listed below and edited and published by the Context Retrieval team. Disclosure: the Context Retrieval API, which this article mentions, is this site's own product.
- The fetched Markdown still has a header row, a separator row and data rows.
- A table that fits under your cap stays one chunk, with its caption and lead-in.
- When you split by rows, every piece starts with the header row.
- Or rewrite each row as column: value pairs so no value depends on position.
- Compare the variants one change at a time on your own table questions.
A table is the one part of a web page where meaning lives in position. A cell that reads 5 means nothing until you know its row and its column. A prose splitter does not know that. It cuts the table where the token count runs out, and the second half becomes a chunk of numbers with no labels. The retriever may still return that chunk, and the model will try to read it. This note covers the two common fixes, how to do each in a few lines of code, and how to tell which one your corpus needs.
Check that the table survived the fetch
Before you choose a splitting rule, check what you actually have. A page fetched as Markdown should give you a pipe table: a header row, a separator row of dashes, then data rows. If the table arrived as loose lines of text, or as one cell per line, no chunking rule will put the columns back. Fix that at ingestion or skip the page, and read a handful of table-heavy pages from each source before you build anything on top of them.
Chonkie's TableChunker, for one, expects that structure: its docs say a Markdown table needs a header, a separator row and at least one data row.1 Our chunking guide gives the general rule: keep a table whole when it fits under your cap. The rest of this note is about the tables that do not fit.
Fix one: split by rows and repeat the header
The first fix keeps the Markdown format and changes only where the cuts go. Split between rows, never inside one, and start every piece with the header row and the separator. Twig's chunking docs describe this as vertical splitting, list "Header repetition, storage overhead" as its trade-off, and also say to keep a table with its caption and surrounding notes.2 Chonkie's TableChunker works the same way by default: its tokenizer defaults to "row", its chunk_size defaults to 3 rows (header not counted), and every chunk keeps the header.1
You do not need a library for this. A plain function is enough for simple pipe tables:
def parse_pipe_table(text):
lines = [l for l in text.strip().splitlines() if l.strip()]
rows = [[c.strip() for c in l.strip().strip("|").split("|")] for l in lines]
return rows[0], rows[2:] # rows[1] is the |---| separator
def split_with_header(header, body, rows_per_chunk):
head = "| " + " | ".join(header) + " |\n|" + "---|" * len(header)
for i in range(0, len(body), rows_per_chunk):
part = body[i:i + rows_per_chunk]
yield head + "\n" + "\n".join("| " + " | ".join(r) + " |" for r in part)
table = """
| Plan | Requests per minute | Support |
|------|---------------------|---------|
| Free | 10 | Community |
| Team | 100 | Email |
| Enterprise | 1000 | Dedicated |
"""
header, body = parse_pipe_table(table)
for chunk in split_with_header(header, body, rows_per_chunk=2):
print(chunk, end="\n\n")
The values in the example table are made up. Choose rows_per_chunk from your token cap, not from this example. The parser does not handle escaped pipes (\|) inside cells, so check your own tables for them.
Fix two: rewrite each row as header-value pairs
The second fix changes the format. Each row becomes one line in which every value carries its column name: Plan: Team, Requests per minute: 100, Support: Email. Now a row means the same thing wherever it lands, and nothing depends on counting pipes. This also suits wide tables, where a model can easily read the wrong column.
def header_value_rows(header, body):
for row in body:
yield ", ".join(f"{h}: {v}" for h, v in zip(header, row) if v)
for line in header_value_rows(header, body):
print(line)
Group these lines into chunks under your cap, and put the table's caption or lead-in sentence at the top of each chunk, so the retriever knows what the rows are about. The cost is the opposite of fix one: you lose the grid, so a question that compares rows ("which plan has the most requests?") depends on the right rows landing in the same chunk or the same top-k. Twig's docs name that trade-off too: row-level chunks are self-contained but lose comparative context.2
What the evidence says, and what it does not
Two recent sources point toward labelled rows, with caveats.
A Runbear blog post from April 10, 2026 compared an old and a new pipeline on 51 table-focused questions across 21 real documents, with Claude Sonnet for both generation and scoring. It reports accuracy of 0.771 for the old pipeline and 0.929 for the new one, 11 questions won by the new one, 2 by the old one and 38 tied.3 Read the setup closely, though. The new pipeline moved from Markdown tables in 800-token chunks to header-value rows in 4,096-token chunks, both at once. The test shows that the combination helped on that corpus. It cannot say how much of the gain came from the format and how much from the larger chunks.
A May 2026 paper on structure-aware tabular chunking encodes each row as a block of column_name: value pairs and merges rows into non-overlapping chunks. On MAUD, a legal reading-comprehension benchmark built from merger-agreement contracts, it reports hybrid-retrieval MRR rising from 0.3576 with recursive chunking to 0.5945, and BM25 Recall@1 from 0.366 to 0.754.4 That is tabular data from a dataset, not tables on web pages, so treat it as a reason to test labelled rows, not as a result for your corpus.
Test one change at a time
The way out of the Runbear ambiguity is cheap. Take 20 to 50 questions that need a table to answer, and run four variants: the current splitter, header repetition, header-value rows at your current chunk size, and header-value rows with a larger cap. Score retrieval first (did the right rows reach the top-k?) and answers second. The note on chunk size for RAG shows how to run one tuning pass like this. We have not benchmarked these variants ourselves; on a corpus of pricing and reference pages, the result may differ from one built on spec sheets.
Whichever fetcher you use, store the fixed table format with the chunker version on each chunk, so you can re-run the comparison later. If you fetch with Context Retrieval API, it returns the main content as Markdown, plain text or HTML, and results[].textTruncated tells you when the Markdown was cut at text.maxCharacters (100,000 characters by default), which matters when a long table sits at the end of a page. See the SDKs for the request.
Footnotes
Frequently asked questions
How do I chunk tables for RAG?
Keep a table whole when it fits under your chunk size, together with its caption and the sentence that introduces it. When it does not fit, split it by rows and repeat the header row in every piece, or rewrite each row as column-name and value pairs so every value carries its label.
Should I repeat the table header in every chunk?
Yes, when you split a table by rows. A row without its header is a list of unlabelled values. The cost is some repeated text and storage, which is usually small next to a wrong answer.
Are header-value rows better than Markdown tables for retrieval?
There is no general answer yet. One April 2026 practitioner test reported higher accuracy after switching to header-value rows, but it also changed the chunk size at the same time, so it cannot say which change helped. Test both formats on your own questions.
What about very wide tables?
One option is to split by columns and keep rows together, repeating the key or ID column in every piece so the parts can still be joined. Header-value rows also help, because a value no longer depends on its column position.