mirror of
https://github.com/napnap75/multiarch-docker-images.git
synced 2026-11-12 00:52:11 +01:00
feat: implement paperless import with config auto-update and new mapping structure (#10)
* Add mapping-based configuration for document processing - Create new config structure with company-type mappings - Add date extraction regex patterns to config - Update config.py to support new mapping-based configuration - Create pipeline.py with full document processing workflow - Enforce strict validation: unknown companies/types route to review - Period rules now come from (company, type) mappings, not templates - Remove document_family field from templates as requested Implements workflow: 1. Extract first page text 2. Find emission date using regex from config 3. Find company/type using ML, validated against config lists 4. Look up (company, type) in mappings for template + period rule 5. If no mapping found -> route to review 6. Apply period rule to calculate period 7. Apply template key_pattern to generate filename Closes #config-review Co-authored-by: napnap75 <napnap75@users.noreply.github.com> * Add field_groups support for additional fields in configuration - Add field_groups section to templates.yaml with predefined lists: - bank_accounts: for bank statements - properties: for building-related documents - contract_references: for contracts and invoices - customer_numbers: for customer identification - Add field_groups to CompanyTypeMapping dataclass - Add get_field_groups(), get_field_group_values(), get_field_groups_for_mapping() methods - Update pipeline to extract additional field values from predefined lists using ML - Additional fields are extracted for each field_group in the mapping - If field values cannot be determined -> route to review Implements workflow: 1. Extract first page text 2. Find emission date using regex patterns from config 3. Find company and document_type using ML, validated against config lists 4. Look up (company, document_type) in mappings for template, period rule, and field groups 5. For each field group, find value using ML from predefined list 6. If no mapping found or field values cannot be determined -> route to review 7. Apply period rule to calculate period from emission date 8. Apply template key_pattern to generate filename with all fields Closes #field-groups-review Co-authored-by: napnap75 <napnap75@users.noreply.github.com> * Update documentation and configuration for new structure - Move configuration from config/templates.yaml to config.jsonc at root - Rename field_groups to additional_fields throughout - Update PRD section 4.1 to reference new period format configuration - Update PRD FR4.1 and FR4.2 to reference JSONC and additional_fields - Update Arch.md to reference JSONC configuration file - Update module layout comments to reference JSONC - Update processing pipeline diagram to reference companies list and additional fields - Update configuration section to describe new JSONC structure The new config.jsonc includes: - companies: predefined list of valid companies - document_types: predefined list of valid document types - additional_fields: predefined value groups (bank_accounts, properties, etc.) - date_extraction: regex patterns for finding emission date - period_formats: customizable period formats with granularity, format template, and offset - mappings: (company, document_type) -> template + period_format + additional_fields - templates: template definitions with key patterns Closes #config-review Co-authored-by: napnap75 <napnap75@users.noreply.github.com> * feat: implement JSONC config with wildcard mappings and period formats - Add JSONC configuration file at root (config.jsonc) - Support simplified date_extraction as ordered list of regex strings - Implement wildcard mappings (company OR document_type can be None) - Add period_formats with granularity, custom format templates, and offsets - Rename field_groups to additional_fields - Update config.py: JSONC loading, PeriodFormatConfig, CompanyTypeMapping with optional fields - Update period.py: format_period_from_emission_date with custom template support - Update pipeline.py: use new config structure with strict validation Closes #10 Co-authored-by: napnap75 <napnap75@users.noreply.github.com> * feat: implement new mapping structure with match/set rules - New mapping structure: each rule has 'match' (criteria) and 'set' (actions) - match: can contain company, document_type, both, or neither (empty = matches all) - set: can contain template, period_format, additional_fields - Rules processed in order, later matches override earlier ones - Added default rule that applies to all documents - Added MappingRule, MappingMatch, MappingSet dataclasses - Updated resolve_mapping() to process all rules and apply overrides - Added 'default' template for fallback Closes #10 Co-authored-by: napnap75 <napnap75@users.noreply.github.com> * feat: implement paperless import with config auto-update and new mapping structure - New mapping structure with match/set sections - Auto-update config.jsonc with missing companies, document_types, additional_fields - Tag-to-field matching with strict validation (unmatched/ambiguous tags route to pending) - Route documents to pending/{paperless_id} when validation fails - Save config at end of run if changes detected - Use created_date from Paperless as emission_date - Write sidecars with errors for pending documents - Clear files/ and pending/ at start of each run Closes #10 Co-authored-by: napnap75 <napnap75@users.noreply.github.com> * Various corrections following real life tests * Various corrections following real life tests --------- Co-authored-by: Vibe Nuage Agent <vibe@mistral.ai> Co-authored-by: napnap75 <napnap75@users.noreply.github.com>
This commit is contained in:
co-authored by
napnap75
Vibe Nuage Agent
parent
72f8254e10
commit
911ed1c027
@@ -41,7 +41,7 @@ flowchart TD
|
||||
- Offline-first: no runtime downloads, no external services (NFR1, AC10).
|
||||
- Zero silent wrong renames: every ambiguous path routes to not processed (NFR3).
|
||||
- Crash safety: copy-then-delete renames, atomic sidecar writes, SQLite repairable from sidecars alone (NFR4, AC8, AC9).
|
||||
- Minimal operational surface: one container, one YAML template config, env-var credentials (NFR6).
|
||||
- Minimal operational surface: one container, one JSONC configuration file, env-var credentials (NFR6).
|
||||
- Single user, local network: performance targets are modest (NFR2) but correctness targets are strict.
|
||||
|
||||
## 3. Tech Stack and Key Decisions
|
||||
@@ -80,14 +80,13 @@ On startup, the process runs the recovery scan (FR1.3, FR10.3): objects in `inbo
|
||||
```
|
||||
app/
|
||||
main.py # FastAPI app, lifespan: recovery scan + poller start
|
||||
config.py # env vars + YAML template loading
|
||||
config.py # env vars + JSONC configuration loading
|
||||
storage/ # S3 interface (boto3), key helpers, collision suffix
|
||||
sidecar.py # atomic sidecar write (temp key + copy), schema
|
||||
replica/ # SQLAlchemy models, sync, rebuild
|
||||
pipeline/ # extract (PyMuPDF), classify, fill fields, validate
|
||||
period.py # period computation from emission date + template rules
|
||||
gazetteer.py # counterparty matching (rapidfuzz)
|
||||
templates.py # YAML template registry (slots, period rules, key patterns)
|
||||
period.py # period computation from emission date + period format config
|
||||
templates.py # JSONC template registry (slots, period rules, key patterns)
|
||||
rename.py # copy-then-delete move + event logging
|
||||
jobs/ # poller, consistency scan, retrain subprocess, rebuild
|
||||
api/ # routes: files, templates, retrain, consistency, auth
|
||||
@@ -108,7 +107,7 @@ flowchart TD
|
||||
empty -- no --> cls["Classify (TF-IDF + LogReg)"]
|
||||
cls --> conf{"Confidence >= threshold?"}
|
||||
conf -- no --> pending
|
||||
conf -- yes --> fill["Fill fields: regexes, gazetteer, period from emission date"]
|
||||
conf -- yes --> fill["Fill fields: regexes, companies list, additional fields from groups, period from emission date"]
|
||||
fill --> valid{"Fields valid?"}
|
||||
valid -- no --> pending
|
||||
valid -- yes --> rename["Compute key, copy-then-delete, write sidecar + SQLite"]
|
||||
@@ -172,7 +171,7 @@ Subprocesses report progress and metrics by writing a status JSON consumed by th
|
||||
|
||||
## 7. Configuration and Secrets
|
||||
|
||||
- Templates: single YAML file (or a directory of YAML files) defining, per template: document family, document types, period rules, optional field schema, extraction regexes, validation rules, key pattern, target prefix.
|
||||
- Templates: single JSONC file defining: document family, document types, period rules, optional field schema, extraction regexes, validation rules, key pattern, target prefix.
|
||||
- Environment: S3 endpoint, access key, secret key, bucket name, poll interval, confidence threshold, dashboard credentials, paths (SQLite file, model registry, template YAML).
|
||||
- No secrets in the YAML; no secrets in sidecars.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user