PDF 表格跨頁註釋可能令 RAG 答案失準
PDF table notes on the next page can corrupt RAG answers
PDF 表格跨頁時,擷取器可能遺失續頁列的表頭或把註釋套用到不適用的列,令 RAG 檢索到正確數值卻附上錯誤限定。建議保留各列、儲存格及註釋的頁碼與位置,並只透過明確的範圍連結套用註釋;範圍未能確定時,應保留未解狀態供覆核。檢索分塊需包含表頭及適用註釋,並以跨頁測試確認限定只套用於相關儲存格,引用頁碼則分別指向數值和註釋。
A table ends at the bottom of page 4. Page 5 starts with two more rows, followed by a note saying one value excludes maintenance. A PDF extractor may return both pages cleanly while leaving the second page's rows without the header or attaching the note to every row. A search result can then return the right number with the wrong qualification.
Consider this invented input:
Page 4: Table 2. Latency (ms)
System Median P95
A 12 28
B 18 42*
Page 5:
C 21 51
* B P95 excludes scheduled maintenance.
A row-only chunk for B that contains B 18 42 cannot answer whether 42 includes maintenance. A chunk for C must not inherit the exclusion. The desired representation ties the note to B's P95 cell and keeps the page on which each piece appeared. This example is a test fixture, not a measurement.
Keep source fragments before merging
Extract page-local blocks first. Store each row's source page and bounding box alongside its cells. Preserve the original marker on the cell and capture the note as a separate object with its own page and bounding box. If your parser already provides stable block IDs, retain those too. The source location is useful when someone needs to inspect the PDF after a failed answer.
A continuation detector can propose a link from the first table fragment to the second. Column alignment, a matching caption or an explicit "continued" label provide evidence. A page break by itself is weak evidence: the next page might start a different table with the same number of columns. A repeated header helps, but it can also occur in a separate table. Keep a proposed link distinct from a confirmed one and send ambiguous cases to review.
The note needs a separate scope decision. Here the * marker occurs on B's P95 cell, and the note explicitly names the same system and column. If the note merely said * Excludes maintenance, the marker would still be evidence for the cell-level link. If the marker is missing or appears on several cells, retain the unresolved note instead of applying it to the entire table. A note printed below a table can qualify the whole table, a column, a row or an individual cell; position alone cannot settle every case.
Build retrieval chunks from relationships
Represent each cell with its row label, column label and source page. Attach a note only through an explicit scope link. When producing a retrieval chunk, include the headers and the notes attached to its cells. Keep the note's page as a second citation rather than assigning it to the row's page.
For the fixture above, a compact result could look like this:
{
"table": "Table 2",
"row": "B",
"cell": {"column": "P95", "value": 42, "unit": "ms", "page": 4},
"notes": [{"text": "B P95 excludes scheduled maintenance.", "page": 5}]
}
This is a proposed downstream shape. It does not imply that a particular extractor returns these fields. In production, also keep a document identifier and a link to the original row and note blocks. For C, emit an empty notes list if its scope has been resolved and no note applies. If scope is unresolved, expose that state separately; an empty list should not conceal uncertainty.
Test the boundary, not just the answer
Create a small set of page-pair fixtures and check the intermediate records as well as the final response. Start with the example above, then change just one detail at a time:
- Move the marker from B to C. The note should follow the marked cell; it should disappear from B's chunk.
- Remove the marker. The note should remain available for review and should not silently attach to either row.
- Put a different table at the top of page 5 with similar columns. The pipeline should not merge it solely because the columns line up.
- Repeat the header on page 5. Each row chunk should retain the header while preserving its actual source page.
For a retrieval test, ask for B's P95 and its qualification. Check that the retrieved material contains both 42 ms and the exclusion, and that the cited pages point to the value and the note. Ask the same question for C and verify that the exclusion is absent. If the pipeline cannot resolve the relationship, a response that flags the missing scope is safer than a confident answer with the wrong qualifier.
These checks extend the earlier table audit workflow across page boundaries. Keep the page-local evidence even after constructing a logical table: reviewers need it to distinguish a bad continuation link from a bad note assignment.
來源:DEV Community · dev.to