You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PDF extraction assigns wrong heading levels (merged, inconsistent, or invented headings) #2142
PDF text extraction gives headings the wrong level, or none:
A bold section heading can be merged into the previous paragraph as inline bold.
Two headings of the same size can come out at different levels.
Plain body text can become a heading.
The extracted-text note then has a misleading outline (H1/H2) and loses real section breaks.
Extraction runs through pdf_inspector.extract_pages_markdown_bytes in src/basic_memory/document_ingestion/pdf_inspector_worker.py, with pdf-inspector 0.2.6.
Repro
A two-page PDF with standard Type 1 fonts:
Page
Text
Font
1
"Quarterly Field Notes"
Helvetica-Bold 20pt
1
"Observations from the Q3 site visits to the coastal monitoring stations."
# Quarterly Field Notes
Observations from the Q3 site visits to the coastal monitoring stations. **Station summary**- North Point: sensors calibrated, battery at 82%.
- Harbor Mouth: salinity drift of 0.4 ppt since last visit.
- Kelp Bed C: camera housing replaced.
# Follow-ups
Order two spare housings before the winter storms.
Re-run the salinity calibration at Harbor Mouth in October.
## Contact: field team lead.
Expected
"Station summary" and "Follow-ups" are both 14pt bold, so they get the same heading level, below the 20pt title (for example H2).
"Station summary" starts its own block instead of joining the paragraph before it.
"Contact: field team lead." stays body text. It is the same 12pt regular font as the other body lines.
Possibly relevant
Levels may be per page. The 14pt heading becomes H1 on page 2, where it is the largest text. That suggests levels are assigned page by page rather than across the whole document.
The last short line on a page may be read as a heading. These are guesses from one PDF, not confirmed against pdf-inspector's code.
Options
Fix it upstream in pdf-inspector. This may need a report there.
Normalize after extraction in pdf_inspector_worker.py, using document-wide font sizes, if pdf-inspector exposes them.
Component: Document ingestion (src/basic_memory/document_ingestion/pdf_inspector_worker.py), which calls pdf-inspector 0.2.6
Priority: Medium. Extraction still returns the text. The outline is wrong, and section breaks can be lost.
Complexity: Medium. If the root cause is in pdf-inspector, the real fix is upstream. A local fix needs font-size data that may not be exposed.
Duplicates: I searched open and closed issues for "pdf heading" and "pdf_inspector" and found none.
Notes
The repro is clear and specific: the font table, the exact output, and the expected output. It covers three separate symptoms:
A bold heading merges into the preceding paragraph as inline bold.
Equal-size headings get different levels. This looks like per-page level assignment.
A short last line on a page is promoted to a heading.
Suggested next steps for whoever picks this up:
Check whether pdf-inspector exposes per-span font size and weight. If it does, normalize levels in the worker using document-wide sizes. If it doesn't, file an upstream report with this repro PDF.
Save the repro PDF as a test fixture, so a regression test can assert the three expected outcomes.
I did not make any code changes. This was triage only.
Activity
claude commentedon Nov 20, 2026
Claude finished @jope-bm's task in 13s —— View job
Triage
bugkept; componentnone)src/basic_memory/document_ingestion/pdf_inspector_worker.py), which callspdf-inspector0.2.6Notes
The repro is clear and specific: the font table, the exact output, and the expected output. It covers three separate symptoms:
Suggested next steps for whoever picks this up:
I did not make any code changes. This was triage only.