From Repeated Email to Structured Knowledge: Templates, Extraction, Facts, and Summaries
On this page24
A from-scratch tutorial following repeated email through template mining, source-linked extraction, symbolic facts, proof trees, and hierarchical summarization.
Article details
- Status
- Building Publicly
- Subcategory
- Thunderbird AI
- Last reviewed
- 3 Sept 2026
- Prerequisites
- No clustering or string-algorithm knowledge required
Invoice INV-1001 for Northwind is ready
Invoice INV-1002 for Contoso is ready
Invoice INV-1003 for Fabrikam is ready
Invoice <*> for <*> is ready
1. What is a template?
constant variable constant variable constant
Invoice INV-1001 for Northwind is ready
Invoice <*> for <*> is ready
2. Convert likely variables before clustering
INV-1001 → <*>
2026-09-03 → <*>
maya@example.test → <*>
https://... → <*>
3. Measure compatibility with a current template
Equal-length template similarity
A wildcard accepts a variable token, while a different constant reduces the score.
template: invoice <*> for northwind is ready
candidate: invoice <*> for contoso is ready
matches: yes yes yes no yes yes
score: 5/6 = 0.833
4. Merge by replacing disagreement
invoice <*> for northwind is ready
invoice <*> for contoso is ready
↓
invoice <*> for <*> is ready
5. Different lengths require sequence alignment
invoice <*> ready
invoice <*> for northwind review is ready
Longest common subsequence recurrence
Wildcards are excluded from constant alignment. Gaps between aligned constants become bounded wildcard regions.
invoice <*> ready
6. Thresholds create two opposite errors
invoice for Northwind
invoice for Contoso
invoice for Fabrikam
<*> <*> ready
Pairwise template quality
One global threshold rarely fits every sender; partitioning reduces accidental competition.
7. Partition before mining
bank-alerts@example.test mine together
shop-orders@example.test mine separately
human conversation often avoid mining
8. Online mining must forget something
rare but important tax notice 1 observation
frequent marketing campaign 800 observations
9. Learned structure should begin in shadow mode
observed family
↓
shadow candidate
↓ evaluate matches without changing behaviour
suggested template
↓ human review
promoted template
↓
rematch affected messages
10. Templates can infer typed slots
INV-1001, INV-1002, INV-1003 identifier-like
INR 805, INR 950, INR 1,805 amount-like
24 Aug, 25 Aug, 26 Aug date-like
Payment of {amount} at {merchant}; reference {reference}
11. Complete dry run
12. Regex generation has a security edge
^(.*a.*)+$
Does the pattern match the intended family?
Can the pattern be evaluated within a predictable resource bound?
13. Experiments to run
Repeated machine-generated text often contains more usable structure than semantic similarity reveals. Learning that structure is an online clustering problem with explicit generalization, memory and review policies.
14. Information extraction with source spans
source:
INR 805.00 was debited at Book Nook on 24 August 2026.
Reference: TXN-HC-100005.
fields:
amount INR 805.00
merchant Book Nook
date 24 August 2026
reference TXN-HC-100005
direction debit
15. Regex, template slots, NER and generative extraction
Payment of {amount} at {merchant}. Reference {reference}.
Source-span validation
A confidence score cannot repair an invalid location or a value absent from the submitted source.
16. Run the deterministic extractor
Amount normalization
Normalization is a second fallible operation. Preserve both raw and normalized values.
17. Extraction evaluation and hostile regex
| Method | Strength | Main weakness | Evidence status |
|---|---|---|---|
| Regex | Stable exact shapes | Format variation | Strong when span-valid |
| Approved template | Repeated sender layouts | Template drift | Strong when slot maps to source |
| NER | Flexible entity phrasing | Type and boundary errors | Candidate until validated |
| Generative extraction | Relations and varied prose | Hallucination and schema errors | Derived until source-confirmed |
18. Symbolic facts, rules and proof trees
owns("Meera Iyer", "Atlas")
19. Active voice, passive voice and Datalog
works_on(Person, Project) :- owns(Person, Project).
owns(Meera, Atlas)
has_deadline(Atlas, Friday)
person_deadline(Person, Date) :-
owns(Person, Project),
has_deadline(Project, Date).
20. Provenance must compose through inference
person_deadline(Meera, Friday)
├── owns(Meera, Atlas) source M1 span 12…29
└── has_deadline(Atlas, Friday) source M2 span 4…33
Conservative proof confidence
This is a policy illustration, not universal probabilistic logic. A conclusion should not become more certain than its weakest premise.
21. Hierarchical summarization with provenance
Text compression ratio
A smaller ratio means stronger compression, not better preservation of important facts.
22. Map, reduce and respect email hierarchy
Hierarchical reduction
Text reduction is not associative: changing chunk boundaries or reduction order can change the result.
23. Chronology, coverage and resumable reductions
Body coverage
Report unavailable, skipped, oversized, blocked and failed messages separately.
24. Failure and evaluation across the structured pipeline
Primary references
- He et al.: Drain — An Online Log Parsing Approach
- Drain3 source and persistence model
- GLiNER: Generalist Model for Named Entity Recognition
- OWASP: Regular expression denial of service
- BART: Denoising Sequence-to-Sequence Pre-training
- T5: Exploring the Limits of Transfer Learning
- RAPTOR: Recursive Abstractive Processing for Tree-Organized Retrieval
- Soufflé: A Datalog Synthesis Tool for Static Analysis
- Soufflé language tutorial