Skip to content

Commit 93abf0b

Browse files
authored
Merge pull request #7 from MMoney1988/feat/chunk-record-export
feat(chunk): export provenance-preserving records
2 parents 5359d21 + 31f743c commit 93abf0b

5 files changed

Lines changed: 798 additions & 3 deletions

File tree

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ It takes JSON exported by [Docling](https://github.com/docling-project/docling)
66

77
- a small traceable JSON file with text blocks, page numbers, bounding boxes, and provenance
88
- a deterministic Markdown quality report that highlights missing fields, broken provenance, invalid bounding boxes, and layout/noise signals
9+
- provenance-preserving JSONL chunk records from normalized parser output
910

10-
This project does not try to replace Docling. Docling does the PDF parsing. This repo checks whether the parser output is structured, traceable, and safe enough to review before using it in downstream workflows.
11+
This project does not try to replace Docling. Docling does the PDF parsing. This repo checks whether the parser output is structured and traceable for human review before downstream use.
1112

1213
It does **not** claim OCR quality, RAG answer quality, table reconstruction, legal extraction, compliance readiness, production extraction accuracy, or enterprise readiness.
1314

@@ -83,7 +84,7 @@ python -m pdf_quality_report.report \
8384

8485
## Export Clean Markdown
8586

86-
Export normalized blocks to clean Markdown with source reference comments for downstream review or RAG ingestion preparation:
87+
Export normalized blocks to clean Markdown with source reference comments for downstream review or retrieval-oriented preparation:
8788

8889
```bash
8990
python -m pdf_quality_report.to_markdown \
@@ -101,6 +102,28 @@ pdf-quality-markdown \
101102
--output /tmp/page_012.md
102103
```
103104

105+
## Export Chunk Records
106+
107+
Export normalized blocks to JSONL chunk records with block IDs, page numbers, bounding-box references, and source metadata
108+
preserved for downstream review or retrieval-oriented preparation:
109+
110+
```bash
111+
python -m pdf_quality_report.chunk \
112+
--input examples/mdpi_pdf_elements/page_006/normalized_blocks.json \
113+
--output /tmp/page_006_chunks.jsonl
114+
```
115+
116+
Use `--out` as a short alias for `--output`. See [Export Chunk Records](docs/how_to_export_chunk_records.md) for a
117+
short walkthrough.
118+
119+
If the package entry point is installed:
120+
121+
```bash
122+
pdf-quality-chunk \
123+
--input examples/mdpi_pdf_elements/page_006/normalized_blocks.json \
124+
--output /tmp/page_006_chunks.jsonl
125+
```
126+
104127
## Included Examples
105128

106129
This repository includes derived example outputs for page 6 and page 12 of the sample article:
@@ -146,7 +169,7 @@ These signals identify page-layout elements that may need review before reusing
146169
- ambiguous_image_blocks: 1
147170
```
148171

149-
`REVIEW` means the hard structure checks passed, but warning details still need human review before Markdown export, RAG ingestion preparation, or manual extraction.
172+
`REVIEW` means the hard structure checks passed, but warning details still need human review before Markdown export, retrieval-oriented preparation, or manual extraction.
150173

151174
## License
152175

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Export Chunk Records
2+
3+
## What this does
4+
5+
Converts `normalized_blocks.json` into JSONL chunk records.
6+
7+
This export step comes after conversion. It does not read PDFs directly. It reads normalized blocks that already contain
8+
text, block IDs, page numbers, bounding boxes, and source provenance.
9+
10+
Use it when you want a compact reviewable artifact that preserves source references for downstream review or
11+
retrieval-oriented preparation.
12+
13+
## What this does not do
14+
15+
No OCR. No table reconstruction. No embeddings. No vector store. No retrieval pipeline. No LLM answer generation.
16+
17+
## Command
18+
19+
```bash
20+
python -m pdf_quality_report.chunk \
21+
--input examples/mdpi_pdf_elements/page_006/normalized_blocks.json \
22+
--output /tmp/page_006_chunks.jsonl
23+
```
24+
25+
```bash
26+
pdf-quality-chunk \
27+
--input examples/mdpi_pdf_elements/page_006/normalized_blocks.json \
28+
--output /tmp/page_006_chunks.jsonl
29+
```
30+
31+
## Output
32+
33+
The export writes one JSON object per line. Each record contains:
34+
35+
- `doc_id`, equal to the stable chunk ID
36+
- `text`, joined from one or more normalized text blocks
37+
- `meta.schema_version`, currently `chunk_record_v0`
38+
- `meta.block_ids`, `meta.page_numbers`, and `meta.bbox_refs`
39+
- `meta.section_heading` and `meta.section_heading_block_id` when a heading applies
40+
- `meta.source_identifier` and `meta.source_pdf_hash`
41+
42+
By default, headers, footers, images, empty text, and very short non-heading fragments are skipped. Tables are exported
43+
only when the normalized table block already has `content.text`.
44+
45+
## When to use it
46+
47+
Use this after the quality report if the normalized blocks are structurally usable and you need source-preserving chunk
48+
records for review or retrieval-oriented preparation.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ docling = [
2727
pdf-quality-convert = "pdf_quality_report.convert:main"
2828
pdf-quality-report = "pdf_quality_report.report:main"
2929
pdf-quality-markdown = "pdf_quality_report.to_markdown:main"
30+
pdf-quality-chunk = "pdf_quality_report.chunk:main"
3031

3132
[tool.pytest.ini_options]
3233
testpaths = ["tests"]

0 commit comments

Comments
 (0)