Lesson 27.3 · 3 of 5 · 6 min read · Reviewed 24 Nov 2026
Tables, charts and figures
By the end, you can
- Prepare tables so retrieval and the model can read them correctly.
- Turn charts and figures into text that can be searched and cited.
Why tables break
A table on a page is clear to a person: each number sits under a column header and beside a row label. Naive extraction turns it into a streamStreaming: Receiving a response as a series of server-sent events while it is generated, instead of waiting for the whole reply.:
Plan Monthly credits Refund window Basic 100 14 days Pro 500 30 days Team 2,000 30 days
Ask “what is the refund window on Pro?” and the model has to guess which number belongs to which column. It often guesses wrong, and confidently.
Three ways to store a table
| Approach | What the chunk looks like | Verdict |
|---|---|---|
| Flattened text | The stream above | Loses structure; avoid |
| Markdown or HTML table | Header row, then one line per row | Good default; models read it well |
| Row records | Plan: Pro. Monthly credits: 500. Refund window: 30 days. |
Good for big tables and exact lookups |
As Markdown:
Table 2 (page 7): Plan limits
| Plan | Monthly credits | Refund window |
|---|---|---|
| Basic | 100 | 14 days |
| Pro | 500 | 30 days |
| Team | 2,000 | 30 days |
Chunking long tables
- Never split a row across two chunksChunking: Splitting documents into smaller passages before embedding and indexing them..
- Repeat the header row (and the table title) at the top of every chunk.
- Keep the table with its caption and page, so a chunk from the middle still says “Table 2, page 7, plan limits”.
- For very large tables, consider loading them into a database and giving the model a query tool instead (chapter 33). Retrieval is for finding text; a table of 50,000 rows is data.
Charts and figures
A bar chart in a PDF is lines and shapes. Text extraction returns, at best, the axis labels. To make a chart searchable you need text that says what it shows:
- The caption and any figure number, from the parser.
- A written description, often produced by a vision-capable model from the figure image (27.4): “Bar chart: support tickets per month, January to June, rising from about 1,200 to 2,000.”
- The underlying numbers, if the source data or an appendix table exists. These beat any description.
Mark generated descriptions as generated, and keep a link to the figure’s page so a person can check it.
A worked chunk
[Annual report > 4. Support > Figure 3, page 12]
Caption: Tickets per month, H1.
Description (generated): rises steadily from about 1,200 in January to about 2,000 in June.
A question such as “did ticket volume grow in the first half?” can now retrieve this chunk, and the answer can cite page 12.
Common mistakes
- Trusting a table parser without spot-checking cells against the original page.
- Splitting merged header cells so a column loses half its name.
- Indexing chart images with no text, so they can never be retrieved.
- Treating a generated chart description as exact data when it only gives approximate values.
Key points
- Flattened tables lose the link between a number and its row and column headers.
- Keep tables as Markdown or HTML, never split a row, and repeat the header row in every chunk of a long table.
- Charts and figures need text: the caption, a written description, and the underlying numbers if you can get them.
- Store the page and table or figure number with each chunk so answers can cite them.
Chunk a long table with headers
Turn a parsed table into chunks that never split a row and always repeat the title and header row, plus a row-record version.
You will have: Two chunking functions (Markdown chunks and row records) and a printout showing each chunk starts with the table title and header.
Steps
- Read the table title, header and rows.
- Write markdown_chunks(rows_per_chunk): each chunk is the title, the header row, the separator, then whole rows.
- Write row_records: one line per row, with every column name repeated and the table and page in front.
- Print the Markdown chunks for 3 rows per chunk and check every chunk starts with the title.
- Answer 'what is the refund window on Pro?' by searching the row records for the plan name.
Done when
- Seven rows in chunks of three give three chunks, the last with one row.
- Every chunk contains the header row.
- The Pro lookup prints 30 days with the page number.
Open in the Playground No API key needed.
Starter code (Python)
TITLE = "Table 2 (page 7): Plan limits"
HEADER = ["Plan", "Monthly credits", "Refund window"]
ROWS = [["Basic", "100", "14 days"], ["Plus", "250", "14 days"], ["Pro", "500", "30 days"],
["Team", "2,000", "30 days"], ["Scale", "5,000", "30 days"], ["Enterprise", "custom", "60 days"],
["Student", "50", "14 days"]]
def markdown_chunks(rows_per_chunk=3):
# TODO: title, header, separator, then up to rows_per_chunk whole rows per chunk
return []
def row_records():
# TODO: e.g. "[Table 2, page 7] Plan: Pro. Monthly credits: 500. Refund window: 30 days."
return []
for c in markdown_chunks():
print(c)
print("---")
print(row_records())
Show a solution
TITLE = "Table 2 (page 7): Plan limits"
HEADER = ["Plan", "Monthly credits", "Refund window"]
ROWS = [["Basic", "100", "14 days"], ["Plus", "250", "14 days"], ["Pro", "500", "30 days"],
["Team", "2,000", "30 days"], ["Scale", "5,000", "30 days"], ["Enterprise", "custom", "60 days"],
["Student", "50", "14 days"]]
def md_row(cells):
return "| " + " | ".join(cells) + " |"
def markdown_chunks(rows_per_chunk=3):
head = [TITLE, md_row(HEADER), md_row(["---"] * len(HEADER))]
return ["\n".join(head + [md_row(r) for r in ROWS[i:i + rows_per_chunk]]) for i in range(0, len(ROWS), rows_per_chunk)]
def row_records():
return ["[Table 2, page 7] " + " ".join(f"{h}: {v}." for h, v in zip(HEADER, r)) for r in ROWS]
chunks = markdown_chunks(3)
for c in chunks:
print(c)
print("---")
print(f"{len(chunks)} chunks; all start with the title: {all(c.startswith(TITLE) for c in chunks)}")
print(f"all contain the header: {all(md_row(HEADER) in c for c in chunks)}")
hit = next(r for r in row_records() if "Plan: Pro." in r)
print("lookup:", hit)