How the Training Loop Works
1) USER UPLOADS INVOICE
β
2) PdfPig extracts text (or vision LLM for image)
β
3) mxbai-embed-large embeds the text β 1024-d vector
β
4) Cosine similarity finds TOP-3 most similar past training examples
β
5) qwen2.5:7b gets prompt = system + 3 examples + invoice text
β
6) qwen2.5:7b returns JSON (constrained by Ollama's format="json")
β
7) USER REVIEWS, CORRECTS WHERE NEEDED, then either:
β’ "Save Corrections" β fixes the scan but doesn't train
β’ "Promote to Training" β saves as a new example for future scans
The model itself is NEVER fine-tuned. We only grow the example library
β which keeps everything 100% local (no GPU training), fast (a few seconds
per scan), and reversible (you can always delete bad examples).
Training Curves
As you add more confirmed examples:
- Extraction accuracy goes up β the LLM sees how YOUR vendors format their invoices
- Manual corrections drop β fields the model used to miss are now in its context
- Confidence scores rise β the model is more sure of its output
- Processing time stays roughly constant β only the top-3 examples are used regardless
Best Practices
- Start with 5β10 examples per doc type. Add more as you encounter unusual layouts.
- Promote examples that have distinct vendor layouts β repeating the same vendor adds little.
- If a vendor changes format, add the new layout as an example β old one stays valid too.
- Edit prompt templates to add company-specific rules (e.g., "TDS column must map to taxAmount").