WeKnora icon indicating copy to clipboard operation
WeKnora copied to clipboard

[Feature]: Preserve per-table header context for multi-table Excel worksheets

Open lynnlase opened this issue 1 month ago • 1 comments

[Feature]: Preserve per-table header context for multi-table Excel worksheets

Problem

The built-in Excel RAG parser retains cell values, but a worksheet containing multiple independently headed tables loses the local header context of each table. With xlsx_first_row_as_header=True, the first worksheet row supplies field labels for every subsequent table. With the default False, column letters are used instead. This is a structural interpretation limitation, not a claim that all cell text is missing.

This matters for technical spreadsheets containing a title, notes, and several tables whose columns have different meanings. Later rows can be indexed with unrelated first-table labels, making retrieval and answer interpretation unreliable.

Minimal synthetic reproduction

No business workbook or private data is required. In a single worksheet, populate these rows:

Row A B C
1 Table one title (merge A1:C1)
2 Object Code Value
3 Object A ZX-01 First table value
4
5 Table two title (merge A5:C5)
6 Parameter Unit Value
7 Parameter B mm Last table value
from io import BytesIO
from openpyxl import Workbook
from docreader.parser.excel_parser import ExcelParser

wb = Workbook()
ws = wb.active
ws.append(["Table one title"])
ws.merge_cells("A1:C1")
ws.append(["Object", "Code", "Value"])
ws.append(["Object A", "ZX-01", "First table value"])
ws.append([])
ws.append(["Table two title"])
ws.merge_cells("A5:C5")
ws.append(["Parameter", "Unit", "Value"])
ws.append(["Parameter B", "mm", "Last table value"])
buf = BytesIO()
wb.save(buf)

for use_header in (False, True):
    doc = ExcelParser(file_name="synthetic.xlsx", file_type="xlsx",
                      xlsx_first_row_as_header=use_header).parse_into_text(buf.getvalue())
    print(use_header, next(c.content for c in doc.chunks if "Last table value" in c.content))

The current first-row-header path labels the final row as approximately:

Table one title: Parameter B,Table one title_2: mm,Table one title_3: Last table value

The default path instead emits A: Parameter B,B: mm,C: Last table value. Cell text is present, but neither path binds that row to Parameter / Unit / Value in the second table.

Desired capability

Consider an opt-in, table-aware path that identifies each independent table header, retains surrounding notes/title separately, and associates rows with their own table and worksheet coordinates. Preserve the existing fallback for ambiguous layouts. A merged parent field should apply only within its real merged range; ordinary blank cells must not inherit unrelated neighboring values.

Version and related work

  • Reproduced on a packaged v0.8.2-derived DocReader. The synthetic qualification also checked multiple worksheets, vertical merged cells, ordinary blanks, and character offsets; those checks passed and should remain protected.
  • Inspected official main at bccb4b151bae403508da77fbb174efc79dc47c1a: _read_sheet_dataframe still uses one first-row header per worksheet. This is a source inspection, not an execution of main.
  • #2314 provides the explicit first-row-header option; it does not detect independent tables.
  • #1796 proposed structured Excel table extraction but is closed without merging. Could that approach be revisited?
  • #3700 adds worksheet/row locators, which helps citation positioning but does not change per-table header selection.

This request concerns built-in Excel RAG parsing, rather than the DuckDB data-analysis tool, image extraction, or any tenant/permission extension. We have not isolated all downstream retrieval misses to this parser behavior and are not claiming this change alone would resolve them.

lynnlase avatar Oct 06 '26 01:10 lynnlase

Hi, I'd like to work on the multi-table header issue. I saw the earlier approach in #1796. Would you be open to a fix focused on the example here, while keeping the current default behavior?

waterboyNick avatar Oct 07 '26 17:10 waterboyNick