docpick 0.1.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 (57) hide show
  1. docpick-0.1.0/.gitignore +47 -0
  2. docpick-0.1.0/LICENSE +190 -0
  3. docpick-0.1.0/PKG-INFO +282 -0
  4. docpick-0.1.0/README.md +233 -0
  5. docpick-0.1.0/docs/design.md +646 -0
  6. docpick-0.1.0/pyproject.toml +92 -0
  7. docpick-0.1.0/src/docpick/__init__.py +17 -0
  8. docpick-0.1.0/src/docpick/batch.py +139 -0
  9. docpick-0.1.0/src/docpick/cli.py +379 -0
  10. docpick-0.1.0/src/docpick/core/__init__.py +0 -0
  11. docpick-0.1.0/src/docpick/core/config.py +85 -0
  12. docpick-0.1.0/src/docpick/core/document.py +72 -0
  13. docpick-0.1.0/src/docpick/core/pipeline.py +344 -0
  14. docpick-0.1.0/src/docpick/core/result.py +178 -0
  15. docpick-0.1.0/src/docpick/llm/__init__.py +0 -0
  16. docpick-0.1.0/src/docpick/llm/base.py +63 -0
  17. docpick-0.1.0/src/docpick/llm/prompt.py +146 -0
  18. docpick-0.1.0/src/docpick/llm/vllm_provider.py +211 -0
  19. docpick-0.1.0/src/docpick/ocr/__init__.py +11 -0
  20. docpick-0.1.0/src/docpick/ocr/auto.py +208 -0
  21. docpick-0.1.0/src/docpick/ocr/base.py +55 -0
  22. docpick-0.1.0/src/docpick/ocr/easyocr_engine.py +88 -0
  23. docpick-0.1.0/src/docpick/ocr/got.py +119 -0
  24. docpick-0.1.0/src/docpick/ocr/paddle.py +126 -0
  25. docpick-0.1.0/src/docpick/ocr/vlm.py +136 -0
  26. docpick-0.1.0/src/docpick/schemas/__init__.py +39 -0
  27. docpick-0.1.0/src/docpick/schemas/bank_statement.py +63 -0
  28. docpick-0.1.0/src/docpick/schemas/base.py +41 -0
  29. docpick-0.1.0/src/docpick/schemas/bill_of_lading.py +96 -0
  30. docpick-0.1.0/src/docpick/schemas/certificate.py +73 -0
  31. docpick-0.1.0/src/docpick/schemas/id_document.py +61 -0
  32. docpick-0.1.0/src/docpick/schemas/invoice.py +80 -0
  33. docpick-0.1.0/src/docpick/schemas/kr_tax_invoice.py +90 -0
  34. docpick-0.1.0/src/docpick/schemas/purchase_order.py +82 -0
  35. docpick-0.1.0/src/docpick/schemas/receipt.py +61 -0
  36. docpick-0.1.0/src/docpick/validation/__init__.py +46 -0
  37. docpick-0.1.0/src/docpick/validation/base.py +53 -0
  38. docpick-0.1.0/src/docpick/validation/checksum.py +183 -0
  39. docpick-0.1.0/src/docpick/validation/cross_document.py +256 -0
  40. docpick-0.1.0/src/docpick/validation/rules.py +228 -0
  41. docpick-0.1.0/tests/__init__.py +0 -0
  42. docpick-0.1.0/tests/unit/__init__.py +0 -0
  43. docpick-0.1.0/tests/unit/test_batch.py +217 -0
  44. docpick-0.1.0/tests/unit/test_checksum.py +160 -0
  45. docpick-0.1.0/tests/unit/test_cli.py +145 -0
  46. docpick-0.1.0/tests/unit/test_config.py +36 -0
  47. docpick-0.1.0/tests/unit/test_cross_document.py +180 -0
  48. docpick-0.1.0/tests/unit/test_document.py +62 -0
  49. docpick-0.1.0/tests/unit/test_enterprise_schemas.py +328 -0
  50. docpick-0.1.0/tests/unit/test_error_handling.py +241 -0
  51. docpick-0.1.0/tests/unit/test_ocr_engines.py +346 -0
  52. docpick-0.1.0/tests/unit/test_prompt.py +60 -0
  53. docpick-0.1.0/tests/unit/test_result.py +101 -0
  54. docpick-0.1.0/tests/unit/test_schema_validation.py +131 -0
  55. docpick-0.1.0/tests/unit/test_schemas.py +64 -0
  56. docpick-0.1.0/tests/unit/test_validation_rules.py +232 -0
  57. docpick-0.1.0/tests/unit/test_validator.py +98 -0
@@ -0,0 +1,47 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ *.egg-info/
7
+ dist/
8
+ build/
9
+ *.egg
10
+
11
+ # Virtual environments
12
+ .venv/
13
+ venv/
14
+ env/
15
+
16
+ # IDE
17
+ .idea/
18
+ .vscode/
19
+ *.swp
20
+ *.swo
21
+ *~
22
+
23
+ # Testing
24
+ .pytest_cache/
25
+ .coverage
26
+ htmlcov/
27
+ .tox/
28
+
29
+ # OS
30
+ .DS_Store
31
+ Thumbs.db
32
+
33
+ # Models / large files
34
+ *.onnx
35
+ *.pt
36
+ *.pth
37
+ *.bin
38
+ *.safetensors
39
+
40
+ # Logs
41
+ *.log
42
+
43
+ # Environment
44
+ .env
45
+ .env.local
46
+ CLAUDE.md
47
+ PLAN.txt
docpick-0.1.0/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 QuartzUnit
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
docpick-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,282 @@
1
+ Metadata-Version: 2.4
2
+ Name: docpick
3
+ Version: 0.1.0
4
+ Summary: Document in, Structured JSON out. Schema-driven document extraction with local OCR + LLM.
5
+ Project-URL: Homepage, https://github.com/QuartzUnit/docpick
6
+ Project-URL: Repository, https://github.com/QuartzUnit/docpick
7
+ Project-URL: Issues, https://github.com/QuartzUnit/docpick/issues
8
+ Author: QuartzUnit
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: document-extraction,idp,invoice,llm,ocr,schema,structured-data
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
19
+ Classifier: Topic :: Text Processing
20
+ Requires-Python: >=3.11
21
+ Requires-Dist: click>=8.0
22
+ Requires-Dist: httpx>=0.27
23
+ Requires-Dist: pillow>=10.0
24
+ Requires-Dist: pydantic-settings>=2.0
25
+ Requires-Dist: pydantic>=2.0
26
+ Requires-Dist: pypdfium2>=4.0
27
+ Requires-Dist: pyyaml>=6.0
28
+ Requires-Dist: rich>=13.0
29
+ Provides-Extra: all
30
+ Requires-Dist: easyocr>=1.7; extra == 'all'
31
+ Requires-Dist: paddleocr>=2.9; extra == 'all'
32
+ Requires-Dist: paddlepaddle>=3.0; extra == 'all'
33
+ Requires-Dist: torch>=2.0; extra == 'all'
34
+ Requires-Dist: transformers>=4.40; extra == 'all'
35
+ Provides-Extra: dev
36
+ Requires-Dist: mypy>=1.10; extra == 'dev'
37
+ Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
38
+ Requires-Dist: pytest>=8.0; extra == 'dev'
39
+ Requires-Dist: ruff>=0.8; extra == 'dev'
40
+ Provides-Extra: easyocr
41
+ Requires-Dist: easyocr>=1.7; extra == 'easyocr'
42
+ Provides-Extra: got
43
+ Requires-Dist: torch>=2.0; extra == 'got'
44
+ Requires-Dist: transformers>=4.40; extra == 'got'
45
+ Provides-Extra: paddle
46
+ Requires-Dist: paddleocr>=2.9; extra == 'paddle'
47
+ Requires-Dist: paddlepaddle>=3.0; extra == 'paddle'
48
+ Description-Content-Type: text/markdown
49
+
50
+ # Docpick
51
+
52
+ > Document in, Structured JSON out. Locally. With your schema.
53
+
54
+ **docpick** is a lightweight, schema-driven document extraction pipeline that combines local OCR engines with local LLMs to extract structured JSON from any document — invoices, receipts, bills of lading, tax forms, and more.
55
+
56
+ - **Zero cloud dependency** — runs entirely on your machine (CPU or GPU)
57
+ - **Custom schemas** — define your own Pydantic models or use 8 built-in document schemas
58
+ - **Validation built-in** — checkdigit verification, cross-field rules, cross-document consistency
59
+ - **Apache 2.0** — no GPL/AGPL dependencies
60
+
61
+ ## Install
62
+
63
+ ```bash
64
+ pip install docpick # core (LLM extraction only)
65
+ pip install docpick[paddle] # + PaddleOCR (recommended)
66
+ pip install docpick[easyocr] # + EasyOCR (Korean-optimized)
67
+ pip install docpick[got] # + GOT-OCR2.0 (GPU, vision-language)
68
+ pip install docpick[all] # all OCR backends
69
+ ```
70
+
71
+ **Requirements:** Python 3.11+ / LLM endpoint (vLLM, Ollama, or OpenAI-compatible)
72
+
73
+ ## Quick Start
74
+
75
+ ### Python API
76
+
77
+ ```python
78
+ from docpick import DocpickPipeline
79
+ from docpick.schemas import InvoiceSchema
80
+
81
+ pipeline = DocpickPipeline()
82
+ result = pipeline.extract("invoice.pdf", schema=InvoiceSchema)
83
+
84
+ print(result.data) # Structured dict matching schema
85
+ print(result.validation) # Validation errors/warnings
86
+ print(result.confidence) # Per-field confidence scores
87
+ ```
88
+
89
+ ### CLI
90
+
91
+ ```bash
92
+ # Extract structured data
93
+ docpick extract invoice.pdf --schema invoice --output result.json
94
+
95
+ # OCR only (no LLM)
96
+ docpick ocr document.png --lang ko,en
97
+
98
+ # Validate extracted JSON
99
+ docpick validate result.json --schema invoice
100
+
101
+ # Batch process a directory
102
+ docpick batch ./documents/ --schema invoice --output ./results/ --concurrency 4
103
+
104
+ # List available schemas
105
+ docpick schemas list
106
+
107
+ # Show schema details
108
+ docpick schemas show invoice
109
+ ```
110
+
111
+ ## Built-in Schemas
112
+
113
+ | Schema | Document Type | Key Validations |
114
+ |--------|--------------|-----------------|
115
+ | `invoice` | Commercial invoices | Line item sums, tax ID checkdigit, date order |
116
+ | `receipt` | Retail/restaurant receipts | Total = subtotal + tax + tip |
117
+ | `bill_of_lading` | Ocean/air B/L | Container weight sums, ISO 6346, HS code format |
118
+ | `purchase_order` | Purchase orders | PO total = line items, delivery date order |
119
+ | `kr_tax_invoice` | Korean e-tax invoice (세금계산서) | Business number checkdigit (x2), supply/tax/total sums |
120
+ | `bank_statement` | Bank statements | IBAN mod97, period date order |
121
+ | `id_document` | Passport/ID (ICAO 9303) | MRZ, ISO 3166 country codes, date ranges |
122
+ | `certificate_of_origin` | Certificate of Origin | ISO 3166 alpha-2 country codes |
123
+
124
+ ## Custom Schemas
125
+
126
+ Define your own schema with Pydantic:
127
+
128
+ ```python
129
+ from pydantic import BaseModel
130
+ from docpick import DocpickPipeline
131
+ from docpick.validation.rules import SumEqualsRule, RequiredFieldRule
132
+
133
+ class MyDocument(BaseModel):
134
+ """Custom document schema."""
135
+ company_name: str | None = None
136
+ total_amount: float | None = None
137
+ tax_amount: float | None = None
138
+ net_amount: float | None = None
139
+ items: list[dict] | None = None
140
+
141
+ class ValidationRules:
142
+ rules = [
143
+ RequiredFieldRule("company_name"),
144
+ SumEqualsRule(["net_amount", "tax_amount"], "total_amount"),
145
+ ]
146
+
147
+ pipeline = DocpickPipeline()
148
+ result = pipeline.extract("my_document.pdf", schema=MyDocument)
149
+ ```
150
+
151
+ Or use a JSON Schema file:
152
+
153
+ ```bash
154
+ docpick extract document.pdf --schema my_schema.json
155
+ ```
156
+
157
+ ## Validation
158
+
159
+ ### Check Digit Algorithms
160
+
161
+ | Algorithm | Use Case |
162
+ |-----------|----------|
163
+ | `kr_business_number` | Korean business registration number (10 digits) |
164
+ | `luhn` | Credit card numbers |
165
+ | `iso_6346` | Shipping container numbers |
166
+ | `iban_mod97` | International bank account numbers |
167
+ | `awb_mod7` | Air waybill numbers |
168
+ | `mrz` | Machine Readable Zone (passport/ID) |
169
+
170
+ ### Cross-Field Rules
171
+
172
+ | Rule | Description |
173
+ |------|-------------|
174
+ | `SumEqualsRule` | Sum of fields equals target (with tolerance) |
175
+ | `DateBeforeRule` | Date A must precede Date B |
176
+ | `RequiredFieldRule` | Field must be non-null and non-empty |
177
+ | `FieldEqualsRule` | Two fields must be equal |
178
+ | `RangeRule` | Numeric field within min/max bounds |
179
+ | `RegexRule` | Field matches regex pattern |
180
+
181
+ ### Cross-Document Validation
182
+
183
+ Validate consistency across related documents (e.g., Invoice + B/L + Packing List):
184
+
185
+ ```python
186
+ from docpick.validation.cross_document import create_trade_document_validator
187
+
188
+ validator = create_trade_document_validator()
189
+ result = validator.validate({
190
+ "invoice": invoice_data,
191
+ "bl": bl_data,
192
+ "packing_list": packing_list_data,
193
+ "certificate": certificate_data,
194
+ })
195
+ print(result.is_valid)
196
+ ```
197
+
198
+ ## OCR Engines
199
+
200
+ | Engine | Type | GPU | Languages | Best For |
201
+ |--------|------|-----|-----------|----------|
202
+ | PaddleOCR | Traditional OCR | Optional | 111 | General documents (default) |
203
+ | EasyOCR | Traditional OCR | Optional | 80+ | Korean text |
204
+ | GOT-OCR2.0 | Vision-Language | Required | Multi | Complex layouts |
205
+ | VLM | Vision-Language | Required | Multi | Direct image → JSON |
206
+
207
+ ### 2-Tier Auto Engine
208
+
209
+ The default `auto` engine uses confidence-based fallback:
210
+
211
+ 1. **Tier 1 (CPU):** PaddleOCR → EasyOCR
212
+ 2. **Tier 2 (GPU):** GOT-OCR2.0 → VLM
213
+
214
+ If Tier 1 average confidence falls below threshold (default 0.7), automatically escalates to Tier 2.
215
+
216
+ ## LLM Providers
217
+
218
+ | Provider | Endpoint | Default Model |
219
+ |----------|----------|---------------|
220
+ | vLLM | `http://localhost:30000/v1` | Qwen/Qwen3.5-32B-AWQ |
221
+ | Ollama | `http://localhost:11434` | qwen3.5:7b |
222
+
223
+ Configure via CLI or YAML:
224
+
225
+ ```bash
226
+ docpick config set llm.provider ollama
227
+ docpick config set llm.base_url http://localhost:11434
228
+ docpick config set llm.model qwen3.5:7b
229
+ ```
230
+
231
+ ## Error Handling
232
+
233
+ The pipeline is designed to be resilient:
234
+
235
+ - **OCR failure** → automatic fallback to next available engine
236
+ - **LLM JSON parse failure** → automatic retry with correction prompt (up to 1 retry)
237
+ - **Partial results** → returns whatever was extracted, with errors logged in `result.errors`
238
+ - **Document load failure** → returns empty result with error message
239
+
240
+ ```python
241
+ result = pipeline.extract("damaged.pdf", schema=InvoiceSchema)
242
+ if result.errors:
243
+ print("Pipeline warnings:", result.errors)
244
+ if result.data:
245
+ print("Partial extraction:", result.data)
246
+ ```
247
+
248
+ ## Batch Processing
249
+
250
+ Process entire directories with parallel workers:
251
+
252
+ ```python
253
+ from docpick.batch import BatchProcessor
254
+ from docpick.schemas import InvoiceSchema
255
+
256
+ processor = BatchProcessor(concurrency=4)
257
+ result = processor.process_directory(
258
+ "./invoices/",
259
+ schema=InvoiceSchema,
260
+ recursive=True,
261
+ )
262
+
263
+ print(f"Processed {result.succeeded}/{result.total} files")
264
+ for path, extraction in result.results.items():
265
+ print(f"{path}: {extraction.data.get('total_amount')}")
266
+ ```
267
+
268
+ ## Architecture
269
+
270
+ ```
271
+ Document (PDF/Image)
272
+ → DocumentLoader (pypdfium2)
273
+ → Tier 1: OCR (PaddleOCR/EasyOCR, CPU)
274
+ → [confidence < threshold] → Tier 2: VLM (GOT/VLM, GPU)
275
+ → LLM Extractor (vLLM/Ollama, schema prompt)
276
+ → Pydantic Validation (checkdigit, cross-field, cross-document)
277
+ → ExtractionResult (structured JSON + confidence + validation)
278
+ ```
279
+
280
+ ## License
281
+
282
+ Apache 2.0 — all dependencies are Apache 2.0 or MIT licensed.