warp-ingest 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. warp_ingest-1.0.0/LICENSE.txt +202 -0
  2. warp_ingest-1.0.0/NOTICE.txt +13 -0
  3. warp_ingest-1.0.0/PKG-INFO +245 -0
  4. warp_ingest-1.0.0/README.md +200 -0
  5. warp_ingest-1.0.0/pyproject.toml +113 -0
  6. warp_ingest-1.0.0/warp_ingest/__init__.py +0 -0
  7. warp_ingest-1.0.0/warp_ingest/file_parser/__init__.py +8 -0
  8. warp_ingest-1.0.0/warp_ingest/file_parser/file_parser.py +8 -0
  9. warp_ingest-1.0.0/warp_ingest/file_parser/ocr_parser.py +170 -0
  10. warp_ingest-1.0.0/warp_ingest/file_parser/parser_factory.py +34 -0
  11. warp_ingest-1.0.0/warp_ingest/file_parser/pdf_plumber_parser.py +1415 -0
  12. warp_ingest-1.0.0/warp_ingest/ingestion_daemon/__init__.py +24 -0
  13. warp_ingest-1.0.0/warp_ingest/ingestion_daemon/__main__.py +50 -0
  14. warp_ingest-1.0.0/warp_ingest/ingestion_daemon/app.py +139 -0
  15. warp_ingest-1.0.0/warp_ingest/ingestion_daemon/auth.py +41 -0
  16. warp_ingest-1.0.0/warp_ingest/ingestion_daemon/autotune.py +116 -0
  17. warp_ingest-1.0.0/warp_ingest/ingestion_daemon/config.py +47 -0
  18. warp_ingest-1.0.0/warp_ingest/ingestor/__init__.py +16 -0
  19. warp_ingest-1.0.0/warp_ingest/ingestor/formatter.py +26 -0
  20. warp_ingest-1.0.0/warp_ingest/ingestor/image_tokens.py +142 -0
  21. warp_ingest-1.0.0/warp_ingest/ingestor/ingestor_api.py +39 -0
  22. warp_ingest-1.0.0/warp_ingest/ingestor/line_parser.py +976 -0
  23. warp_ingest-1.0.0/warp_ingest/ingestor/oc_visualize.py +726 -0
  24. warp_ingest-1.0.0/warp_ingest/ingestor/opencontracts_exporter.py +1492 -0
  25. warp_ingest-1.0.0/warp_ingest/ingestor/patterns.py +170 -0
  26. warp_ingest-1.0.0/warp_ingest/ingestor/pdf_ingestor.py +344 -0
  27. warp_ingest-1.0.0/warp_ingest/ingestor/segmentation_metrics.py +46 -0
  28. warp_ingest-1.0.0/warp_ingest/ingestor/semantic_units.py +1914 -0
  29. warp_ingest-1.0.0/warp_ingest/ingestor/styling_utils.py +692 -0
  30. warp_ingest-1.0.0/warp_ingest/ingestor/table_engine.py +1347 -0
  31. warp_ingest-1.0.0/warp_ingest/ingestor/visual_ingestor/__init__.py +0 -0
  32. warp_ingest-1.0.0/warp_ingest/ingestor/visual_ingestor/block_renderer.py +486 -0
  33. warp_ingest-1.0.0/warp_ingest/ingestor/visual_ingestor/indent_parser.py +1033 -0
  34. warp_ingest-1.0.0/warp_ingest/ingestor/visual_ingestor/order_fixer.py +841 -0
  35. warp_ingest-1.0.0/warp_ingest/ingestor/visual_ingestor/style_utils.py +258 -0
  36. warp_ingest-1.0.0/warp_ingest/ingestor/visual_ingestor/table_parser.py +1363 -0
  37. warp_ingest-1.0.0/warp_ingest/ingestor/visual_ingestor/vi_helper_utils.py +142 -0
  38. warp_ingest-1.0.0/warp_ingest/ingestor/visual_ingestor/visual_ingestor.py +6457 -0
  39. warp_ingest-1.0.0/warp_ingest/ingestor_utils/__init__.py +0 -0
  40. warp_ingest-1.0.0/warp_ingest/ingestor_utils/compat.py +185 -0
  41. warp_ingest-1.0.0/warp_ingest/ingestor_utils/ing_named_tuples.py +8 -0
  42. warp_ingest-1.0.0/warp_ingest/ingestor_utils/parsing_utils.py +206 -0
  43. warp_ingest-1.0.0/warp_ingest/ingestor_utils/utils.py +391 -0
  44. warp_ingest-1.0.0/warp_ingest/ingestor_utils/word_splitter.py +112 -0
  45. warp_ingest-1.0.0/warp_ingest/ingestor_utils/words.txt +126141 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,13 @@
1
+ Copyright 2024 Ambika Sukla, Nlmatics Corp.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,245 @@
1
+ Metadata-Version: 2.4
2
+ Name: warp-ingest
3
+ Version: 1.0.0
4
+ Summary: Pure-Python, RAG-friendly document parsers (PDF/HTML/text/XML/Markdown). Java- and Tika-free.
5
+ Author: Ambika Sukla, Jonathan, John Scrudato
6
+ Author-email: Ambika Sukla <ambika.sukla@nlmatics.com>, Jonathan <jonathan.hilgart@gmail.com>, John Scrudato <scrudato@umich.edu>
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE.txt
9
+ License-File: NOTICE.txt
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Legal Industry
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Requires-Dist: beautifulsoup4>=4.12.0,<5.0.0
22
+ Requires-Dist: fastapi>=0.115,<1.0
23
+ Requires-Dist: nltk>=3.9.1
24
+ Requires-Dist: numpy>=1.24,<3
25
+ Requires-Dist: pdfplumber>=0.11.4,<0.12.0
26
+ Requires-Dist: pypdfium2>=5
27
+ Requires-Dist: python-multipart>=0.0.9
28
+ Requires-Dist: uvicorn>=0.30,<1.0
29
+ Requires-Dist: onnxruntime>=1.17.0,<1.23 ; python_full_version == '3.10.*' and extra == 'ocr'
30
+ Requires-Dist: onnxruntime>=1.27.0 ; python_full_version >= '3.11' and python_full_version < '3.15' and extra == 'ocr'
31
+ Requires-Dist: opencv-python-headless>=4.13.0.92 ; extra == 'ocr'
32
+ Requires-Dist: pyclipper>=1.4.0 ; extra == 'ocr'
33
+ Requires-Dist: pyyaml>=6.0.3 ; extra == 'ocr'
34
+ Requires-Dist: rapidocr-onnxruntime>=1.3.0,<2.0.0 ; extra == 'ocr'
35
+ Requires-Dist: shapely>=2.1.2 ; extra == 'ocr'
36
+ Requires-Dist: six>=1.17.0 ; extra == 'ocr'
37
+ Requires-Dist: pymupdf4llm>=0.0.17 ; extra == 'tables'
38
+ Requires-Dist: markdown2>=2.4.0 ; extra == 'tables'
39
+ Requires-Python: >=3.10, <3.15
40
+ Project-URL: Repository, https://github.com/Open-Source-Legal/Warp-Ingest
41
+ Project-URL: Issues, https://github.com/Open-Source-Legal/Warp-Ingest/issues
42
+ Provides-Extra: ocr
43
+ Provides-Extra: tables
44
+ Description-Content-Type: text/markdown
45
+
46
+ <img width="620" height="423" alt="Warp-Ingest" align="center" src="https://github.com/user-attachments/assets/dffc8c8b-d7fc-4b64-8442-6ecce16a244f" />
47
+
48
+ # Warp-Ingest
49
+
50
+ **Warp-Ingest is a state-of-the-art, deterministic PDF parser.** It turns a PDF into
51
+ layout-aware structure — accurate word- and block-level bounding boxes, structural
52
+ labels (section header, paragraph, list item, table row), and the relationships
53
+ between them (the section/sub-section/paragraph **parent ↔ child** hierarchy) — and
54
+ renders it as blocks, JSON, HTML, or an [OpenContracts](https://github.com/JSv4/OpenContracts)
55
+ structural export.
56
+
57
+ It is **rule-based, not model-based**: structure comes from text coordinates,
58
+ graphics, and font data — no GPU, no per-page rasterization, no training set. That
59
+ makes it fast and predictable on long, text-layer documents (hundreds of pages), which
60
+ is where vision parsers are slowest and least stable. See
61
+ [Rule-based vs. model-based](#rule-based-vs-model-based) for the rationale.
62
+
63
+ Warp-Ingest is a pure-Python rewrite of the nlmatics `nlm-ingestor` engine, with the
64
+ Java/Apache-Tika and Tesseract dependencies removed.
65
+
66
+ ## How the pipeline works
67
+
68
+ ```
69
+ PDF ──pdfplumber──► per-word boxes + fonts ──► Tika-format XHTML ──► visual_ingestor ──► blocks / JSON / HTML / OpenContracts
70
+ (scanned pages ──rapidocr──► OCR words ──► same XHTML ──┘)
71
+ ```
72
+
73
+ - **`pdfplumber`** (MIT) extracts each word's real bounding box and font data in
74
+ absolute, top-left-origin PDF points.
75
+ - A scanned or sparse page is detected automatically and routed to the optional
76
+ **`rapidocr-onnxruntime`** OCR backend (Apache-2.0, no Tesseract binary, no GPU),
77
+ which emits the **same** word-box format — so a scanned page and a born-digital page
78
+ flow through the identical layout engine.
79
+ - The front-end emits an intermediate **Tika-format XHTML** (one `<p>` per visual line,
80
+ carrying per-word positions and fonts). `visual_ingestor` — the ~6,000-line rule
81
+ engine — groups those lines into typed blocks, detects tables from rule-line
82
+ graphics, strips repeating headers/footers, removes watermarks, and fixes reading
83
+ order.
84
+
85
+ The word-level boxes use the same technique as OpenContracts (see
86
+ [docs/bbox_architecture.md](docs/bbox_architecture.md)).
87
+
88
+ ## What the parser produces
89
+
90
+ 1. Sections and sub-sections with their nesting levels.
91
+ 2. Paragraphs (lines joined into coherent blocks).
92
+ 3. The parent ↔ child links between sections and paragraphs.
93
+ 4. Tables, with the section each table sits in.
94
+ 5. Lists and nested lists.
95
+ 6. Content joined across page breaks.
96
+ 7. Removal of repeating headers and footers.
97
+ 8. Watermark removal.
98
+ 9. OCR with bounding boxes for scanned pages.
99
+ 10. An [OpenContracts structural export](docs/opencontracts_export_format.md): PAWLS
100
+ word tokens, one structural annotation per block, and the `parent_id` heading
101
+ hierarchy as explicit relationships.
102
+
103
+ ## Benchmarks
104
+
105
+ Warp-Ingest is scored on the official
106
+ [LlamaIndex ParseBench](https://github.com/run-llama/ParseBench) — **2,078
107
+ human-verified pages** of real enterprise documents — by running it *through the
108
+ official framework* with deterministic, rule-based metrics (no LLM-as-a-judge). Among
109
+ the **8 deterministic, local, no-API parsers**, Warp-Ingest is a **top-2 result
110
+ (2nd overall)**, it is the **only** local parser that carries real **visual
111
+ grounding**, and it **leads on Charts**. Full numbers, methodology, and the
112
+ reproduction commands are in [benchmarks/parsebench/RESULTS.md](benchmarks/parsebench/RESULTS.md).
113
+
114
+ ## Installation
115
+
116
+ ```bash
117
+ # install the project and dev tools with uv
118
+ uv sync --group dev
119
+
120
+ # include the optional OCR backend for scanned PDFs
121
+ uv sync --group dev --extra ocr
122
+
123
+ # one-time NLTK data download
124
+ uv run python -m nltk.downloader punkt punkt_tab stopwords
125
+ ```
126
+
127
+ ## Running the service
128
+
129
+ ```bash
130
+ python -m warp_ingest.ingestion_daemon # or: ./run.sh (FastAPI/uvicorn, port 5001)
131
+ ```
132
+
133
+ The launcher budgets concurrency automatically from the CPUs actually available
134
+ (CPU affinity **and** the container cgroup quota, so a docker `--cpus` / K8s
135
+ `limits.cpu` deployment uses exactly its slice): one uvicorn worker per
136
+ effective CPU, with the front-end page-striping pool and the OCR session
137
+ threads sized so the layers never oversubscribe the box. Every knob can be
138
+ overridden via environment variables:
139
+
140
+ | Env var | Default | Effect |
141
+ |---|---|---|
142
+ | `WARP_API_KEY` | `abc123` | API key required by `/api/parse` (send as `X-API-Key` or `Authorization: Bearer`) |
143
+ | `WARP_WEB_WORKERS` (or `WEB_CONCURRENCY`) | effective CPUs | uvicorn worker processes |
144
+ | `WARP_FE_WORKERS` | `max(1, min(8, cpus // workers))` | per-worker front-end page-striping pool (≤1 = serial) |
145
+ | `WARP_OCR_THREADS` | `max(1, cpus // (workers × fe_workers))` | onnxruntime intra-op threads per OCR session |
146
+ | `WARP_WORKER_PARSE_SLOTS` | `1` | concurrent parses allowed inside one worker |
147
+ | `WARP_HOST` / `WARP_PORT` (or `PORT`) | `0.0.0.0` / `5001` | bind address |
148
+
149
+ `POST /api/parse` with a `file` form field and the API key; the response body is
150
+ the parse result (`{"page_dim": ..., "num_pages": ..., "result": ...}`) and
151
+ errors are standard `{"detail": ...}` bodies. Interactive OpenAPI docs at `/docs`.
152
+
153
+ ```
154
+ curl -H "X-API-Key: abc123" -F file=@document.pdf \
155
+ "http://localhost:5001/api/parse?render_format=all"
156
+ ```
157
+
158
+ Query parameters (booleans accept `true`/`false`, `1`/`0`, `yes`/`no`, `on`/`off`):
159
+
160
+ | Param | Values | Effect |
161
+ |---|---|---|
162
+ | `render_format` | `all` \| `json` \| `html` \| `opencontracts` | output rendering |
163
+ | `apply_ocr` | bool | force OCR on every page (scanned pages are OCR'd automatically regardless) |
164
+ | `disable_ocr` | bool | keep every page on its embedded text layer — no OCR for this request |
165
+ | `semantic_units` | bool | append the additive Semantic-Unit clause layer (`render_format=opencontracts`) |
166
+
167
+ `GET /` and `GET /healthz` are unauthenticated health endpoints (`/healthz`
168
+ reports the resolved concurrency settings and OCR availability). Warp-Ingest
169
+ parses **PDF only**; a non-PDF upload returns HTTP 415.
170
+
171
+ ### Docker
172
+
173
+ ```bash
174
+ docker build -t warp-ingest .
175
+ docker run -p 5010:5001 -e WARP_API_KEY=change-me warp-ingest
176
+ ```
177
+
178
+ Every GitHub release publishes a versioned multi-arch image to GHCR
179
+ (`ghcr.io/open-source-legal/warp-ingest:X.Y.Z` / `:X.Y` / `:X` / `:latest`,
180
+ cosign-signed) via `.github/workflows/docker-publish.yml`.
181
+
182
+ ### Library use
183
+
184
+ ```python
185
+ from warp_ingest.ingestor import pdf_ingestor
186
+
187
+ export = pdf_ingestor.parse_to_opencontracts("document.pdf") # OpenContracts export
188
+ ingestor = pdf_ingestor.PDFIngestor("document.pdf", {"render_format": "all"})
189
+ blocks = ingestor.blocks
190
+ ```
191
+
192
+ The notebook
193
+ [pdf_visual_ingestor_step_by_step.ipynb](notebooks/pdf_visual_ingestor_step_by_step.ipynb)
194
+ walks the whole pipeline on a sample PDF.
195
+
196
+ ## Testing
197
+
198
+ No Java or Tika is needed.
199
+
200
+ ```bash
201
+ make test # full pytest suite (unit + fixture parsing, incl. OCR)
202
+ uv run pytest tests/ # same, directly
203
+ ```
204
+
205
+ Beyond unit tests, the suite includes cross-engine regression against the original
206
+ Java/Tika engine (S-1), an OpenContracts-export regression, a Docling layout oracle,
207
+ and vision-adjudicated structural-correctness suites — all floored against committed
208
+ baselines so engine changes can only improve, never silently regress. See
209
+ [CLAUDE.md](CLAUDE.md) for the map of which suite guards what.
210
+
211
+ ## Rule-based vs. model-based
212
+
213
+ Over four years the nlmatics team evaluated many options, including a YOLO-based vision
214
+ parser, and settled on the rule-based approach for these reasons:
215
+
216
+ 1. **Speed.** It is ~100× faster than a vision parser, which must rasterize every page
217
+ (even text-layer ones). A vision parser is the better tool for scanned PDFs with no
218
+ text layer or small form-like documents; for large text-layer PDFs spanning hundreds
219
+ of pages, a rule-based parser is far more practical.
220
+ 2. **No special hardware.** It runs on CPU.
221
+ 3. **Fixable.** Vision-parser errors are fixed either by adding training examples (which
222
+ can degrade previously-correct behavior) or by layering on rules anyway — at which
223
+ point you are writing rules again.
224
+
225
+ ## Credits
226
+
227
+ The PDF parser
228
+ [visual_ingestor](warp_ingest/ingestor/visual_ingestor/visual_ingestor.py) and its
229
+ indent parsers were
230
+ written by Ambika Sukla, with contributions from Reshav Abraham, Tom Liu (the original
231
+ Indent Parser), and Kiran Panicker (parsing speed, table-parsing, indent-parsing, and
232
+ reordering accuracy). The core
233
+ [line_parser](warp_ingest/ingestor/line_parser.py) was written by Ambika Sukla.
234
+
235
+ Thanks to the `pdfplumber` / `pdfminer.six`, `pypdfium2`, and `RapidOCR` open-source
236
+ communities, and to the Apache PDFBox and Tika developers whose XHTML format the engine
237
+ is built around.
238
+
239
+ ## History
240
+
241
+ Earlier versions depended on an nlmatics-modified Apache Tika (`nlm-tika`) on the JVM
242
+ plus Tesseract for OCR. That is gone — the pure-Python front-end
243
+ ([`pdf_plumber_parser.py`](warp_ingest/file_parser/pdf_plumber_parser.py) and
244
+ [`ocr_parser.py`](warp_ingest/file_parser/ocr_parser.py)) reproduces the same
245
+ intermediate XHTML contract, so the layout engine did not have to change.
@@ -0,0 +1,200 @@
1
+ <img width="620" height="423" alt="Warp-Ingest" align="center" src="https://github.com/user-attachments/assets/dffc8c8b-d7fc-4b64-8442-6ecce16a244f" />
2
+
3
+ # Warp-Ingest
4
+
5
+ **Warp-Ingest is a state-of-the-art, deterministic PDF parser.** It turns a PDF into
6
+ layout-aware structure — accurate word- and block-level bounding boxes, structural
7
+ labels (section header, paragraph, list item, table row), and the relationships
8
+ between them (the section/sub-section/paragraph **parent ↔ child** hierarchy) — and
9
+ renders it as blocks, JSON, HTML, or an [OpenContracts](https://github.com/JSv4/OpenContracts)
10
+ structural export.
11
+
12
+ It is **rule-based, not model-based**: structure comes from text coordinates,
13
+ graphics, and font data — no GPU, no per-page rasterization, no training set. That
14
+ makes it fast and predictable on long, text-layer documents (hundreds of pages), which
15
+ is where vision parsers are slowest and least stable. See
16
+ [Rule-based vs. model-based](#rule-based-vs-model-based) for the rationale.
17
+
18
+ Warp-Ingest is a pure-Python rewrite of the nlmatics `nlm-ingestor` engine, with the
19
+ Java/Apache-Tika and Tesseract dependencies removed.
20
+
21
+ ## How the pipeline works
22
+
23
+ ```
24
+ PDF ──pdfplumber──► per-word boxes + fonts ──► Tika-format XHTML ──► visual_ingestor ──► blocks / JSON / HTML / OpenContracts
25
+ (scanned pages ──rapidocr──► OCR words ──► same XHTML ──┘)
26
+ ```
27
+
28
+ - **`pdfplumber`** (MIT) extracts each word's real bounding box and font data in
29
+ absolute, top-left-origin PDF points.
30
+ - A scanned or sparse page is detected automatically and routed to the optional
31
+ **`rapidocr-onnxruntime`** OCR backend (Apache-2.0, no Tesseract binary, no GPU),
32
+ which emits the **same** word-box format — so a scanned page and a born-digital page
33
+ flow through the identical layout engine.
34
+ - The front-end emits an intermediate **Tika-format XHTML** (one `<p>` per visual line,
35
+ carrying per-word positions and fonts). `visual_ingestor` — the ~6,000-line rule
36
+ engine — groups those lines into typed blocks, detects tables from rule-line
37
+ graphics, strips repeating headers/footers, removes watermarks, and fixes reading
38
+ order.
39
+
40
+ The word-level boxes use the same technique as OpenContracts (see
41
+ [docs/bbox_architecture.md](docs/bbox_architecture.md)).
42
+
43
+ ## What the parser produces
44
+
45
+ 1. Sections and sub-sections with their nesting levels.
46
+ 2. Paragraphs (lines joined into coherent blocks).
47
+ 3. The parent ↔ child links between sections and paragraphs.
48
+ 4. Tables, with the section each table sits in.
49
+ 5. Lists and nested lists.
50
+ 6. Content joined across page breaks.
51
+ 7. Removal of repeating headers and footers.
52
+ 8. Watermark removal.
53
+ 9. OCR with bounding boxes for scanned pages.
54
+ 10. An [OpenContracts structural export](docs/opencontracts_export_format.md): PAWLS
55
+ word tokens, one structural annotation per block, and the `parent_id` heading
56
+ hierarchy as explicit relationships.
57
+
58
+ ## Benchmarks
59
+
60
+ Warp-Ingest is scored on the official
61
+ [LlamaIndex ParseBench](https://github.com/run-llama/ParseBench) — **2,078
62
+ human-verified pages** of real enterprise documents — by running it *through the
63
+ official framework* with deterministic, rule-based metrics (no LLM-as-a-judge). Among
64
+ the **8 deterministic, local, no-API parsers**, Warp-Ingest is a **top-2 result
65
+ (2nd overall)**, it is the **only** local parser that carries real **visual
66
+ grounding**, and it **leads on Charts**. Full numbers, methodology, and the
67
+ reproduction commands are in [benchmarks/parsebench/RESULTS.md](benchmarks/parsebench/RESULTS.md).
68
+
69
+ ## Installation
70
+
71
+ ```bash
72
+ # install the project and dev tools with uv
73
+ uv sync --group dev
74
+
75
+ # include the optional OCR backend for scanned PDFs
76
+ uv sync --group dev --extra ocr
77
+
78
+ # one-time NLTK data download
79
+ uv run python -m nltk.downloader punkt punkt_tab stopwords
80
+ ```
81
+
82
+ ## Running the service
83
+
84
+ ```bash
85
+ python -m warp_ingest.ingestion_daemon # or: ./run.sh (FastAPI/uvicorn, port 5001)
86
+ ```
87
+
88
+ The launcher budgets concurrency automatically from the CPUs actually available
89
+ (CPU affinity **and** the container cgroup quota, so a docker `--cpus` / K8s
90
+ `limits.cpu` deployment uses exactly its slice): one uvicorn worker per
91
+ effective CPU, with the front-end page-striping pool and the OCR session
92
+ threads sized so the layers never oversubscribe the box. Every knob can be
93
+ overridden via environment variables:
94
+
95
+ | Env var | Default | Effect |
96
+ |---|---|---|
97
+ | `WARP_API_KEY` | `abc123` | API key required by `/api/parse` (send as `X-API-Key` or `Authorization: Bearer`) |
98
+ | `WARP_WEB_WORKERS` (or `WEB_CONCURRENCY`) | effective CPUs | uvicorn worker processes |
99
+ | `WARP_FE_WORKERS` | `max(1, min(8, cpus // workers))` | per-worker front-end page-striping pool (≤1 = serial) |
100
+ | `WARP_OCR_THREADS` | `max(1, cpus // (workers × fe_workers))` | onnxruntime intra-op threads per OCR session |
101
+ | `WARP_WORKER_PARSE_SLOTS` | `1` | concurrent parses allowed inside one worker |
102
+ | `WARP_HOST` / `WARP_PORT` (or `PORT`) | `0.0.0.0` / `5001` | bind address |
103
+
104
+ `POST /api/parse` with a `file` form field and the API key; the response body is
105
+ the parse result (`{"page_dim": ..., "num_pages": ..., "result": ...}`) and
106
+ errors are standard `{"detail": ...}` bodies. Interactive OpenAPI docs at `/docs`.
107
+
108
+ ```
109
+ curl -H "X-API-Key: abc123" -F file=@document.pdf \
110
+ "http://localhost:5001/api/parse?render_format=all"
111
+ ```
112
+
113
+ Query parameters (booleans accept `true`/`false`, `1`/`0`, `yes`/`no`, `on`/`off`):
114
+
115
+ | Param | Values | Effect |
116
+ |---|---|---|
117
+ | `render_format` | `all` \| `json` \| `html` \| `opencontracts` | output rendering |
118
+ | `apply_ocr` | bool | force OCR on every page (scanned pages are OCR'd automatically regardless) |
119
+ | `disable_ocr` | bool | keep every page on its embedded text layer — no OCR for this request |
120
+ | `semantic_units` | bool | append the additive Semantic-Unit clause layer (`render_format=opencontracts`) |
121
+
122
+ `GET /` and `GET /healthz` are unauthenticated health endpoints (`/healthz`
123
+ reports the resolved concurrency settings and OCR availability). Warp-Ingest
124
+ parses **PDF only**; a non-PDF upload returns HTTP 415.
125
+
126
+ ### Docker
127
+
128
+ ```bash
129
+ docker build -t warp-ingest .
130
+ docker run -p 5010:5001 -e WARP_API_KEY=change-me warp-ingest
131
+ ```
132
+
133
+ Every GitHub release publishes a versioned multi-arch image to GHCR
134
+ (`ghcr.io/open-source-legal/warp-ingest:X.Y.Z` / `:X.Y` / `:X` / `:latest`,
135
+ cosign-signed) via `.github/workflows/docker-publish.yml`.
136
+
137
+ ### Library use
138
+
139
+ ```python
140
+ from warp_ingest.ingestor import pdf_ingestor
141
+
142
+ export = pdf_ingestor.parse_to_opencontracts("document.pdf") # OpenContracts export
143
+ ingestor = pdf_ingestor.PDFIngestor("document.pdf", {"render_format": "all"})
144
+ blocks = ingestor.blocks
145
+ ```
146
+
147
+ The notebook
148
+ [pdf_visual_ingestor_step_by_step.ipynb](notebooks/pdf_visual_ingestor_step_by_step.ipynb)
149
+ walks the whole pipeline on a sample PDF.
150
+
151
+ ## Testing
152
+
153
+ No Java or Tika is needed.
154
+
155
+ ```bash
156
+ make test # full pytest suite (unit + fixture parsing, incl. OCR)
157
+ uv run pytest tests/ # same, directly
158
+ ```
159
+
160
+ Beyond unit tests, the suite includes cross-engine regression against the original
161
+ Java/Tika engine (S-1), an OpenContracts-export regression, a Docling layout oracle,
162
+ and vision-adjudicated structural-correctness suites — all floored against committed
163
+ baselines so engine changes can only improve, never silently regress. See
164
+ [CLAUDE.md](CLAUDE.md) for the map of which suite guards what.
165
+
166
+ ## Rule-based vs. model-based
167
+
168
+ Over four years the nlmatics team evaluated many options, including a YOLO-based vision
169
+ parser, and settled on the rule-based approach for these reasons:
170
+
171
+ 1. **Speed.** It is ~100× faster than a vision parser, which must rasterize every page
172
+ (even text-layer ones). A vision parser is the better tool for scanned PDFs with no
173
+ text layer or small form-like documents; for large text-layer PDFs spanning hundreds
174
+ of pages, a rule-based parser is far more practical.
175
+ 2. **No special hardware.** It runs on CPU.
176
+ 3. **Fixable.** Vision-parser errors are fixed either by adding training examples (which
177
+ can degrade previously-correct behavior) or by layering on rules anyway — at which
178
+ point you are writing rules again.
179
+
180
+ ## Credits
181
+
182
+ The PDF parser
183
+ [visual_ingestor](warp_ingest/ingestor/visual_ingestor/visual_ingestor.py) and its
184
+ indent parsers were
185
+ written by Ambika Sukla, with contributions from Reshav Abraham, Tom Liu (the original
186
+ Indent Parser), and Kiran Panicker (parsing speed, table-parsing, indent-parsing, and
187
+ reordering accuracy). The core
188
+ [line_parser](warp_ingest/ingestor/line_parser.py) was written by Ambika Sukla.
189
+
190
+ Thanks to the `pdfplumber` / `pdfminer.six`, `pypdfium2`, and `RapidOCR` open-source
191
+ communities, and to the Apache PDFBox and Tika developers whose XHTML format the engine
192
+ is built around.
193
+
194
+ ## History
195
+
196
+ Earlier versions depended on an nlmatics-modified Apache Tika (`nlm-tika`) on the JVM
197
+ plus Tesseract for OCR. That is gone — the pure-Python front-end
198
+ ([`pdf_plumber_parser.py`](warp_ingest/file_parser/pdf_plumber_parser.py) and
199
+ [`ocr_parser.py`](warp_ingest/file_parser/ocr_parser.py)) reproduces the same
200
+ intermediate XHTML contract, so the layout engine did not have to change.