n_consensus > 1, multiple models extract data from the same document. Their outputs may contain lists in different orders or with slight variations. The Alignment Engine matches corresponding items before computing consensus.
The Problem
Three models extract line items from an invoice:A with B (same index).
With alignment: The engine detects these are the same items and aligns them correctly before consensus.
How It Works
| Step | Question | Example |
|---|---|---|
| 1. Find Best Key | Which field uniquely identifies items? | sku |
| 2. Match Items | Which items correspond across sources? | A↔A↔A, B↔B↔B |
| 3. Consensus | What’s the final value for each field? | qty: 20 (2/3 agree) |
Step 1: Find the Best Key
The engine looks for a field that:- Uniquely identifies each item (no duplicates)
- Is stable across sources (same values appear)
Example
[sku, qty, price, description]:
Key Metrics
| Metric | What it measures |
|---|---|
| Uniqueness | Are values distinct within each source? |
| Jaccard | How similar are value sets across sources? |
| I_E | How many values appear in ALL sources? |
| Coverage | What % of items have this field? |
Composite Keys: If no single field is unique, the engine combines fields like (category, name).
Step 2: Match Items
Once the key is selected, items are matched by their key values.Simple Example
Fuzzy Matching
Keys don’t always match exactly. The engine handles variations: Numeric canonicalization:
Note: Fuzzy key matching uses abs() + rounding for numbers, not percentage tolerance. The 3% tolerance is used in consensus (merging values), not in alignment (matching items).
Step 3: Handle Unmatched Items
Items that can’t be matched become solo rows:Multi-Pass Strategy
Alignment uses multiple passes with different strategies:| Pass | Strategy | Threshold | Purpose |
|---|---|---|---|
| 1 | Standard + Semantic | 0.67 | Key-based alignment (bulk matching) |
| 2 | Semantic (medium) | 0.90 | Re-align residuals with high confidence |
| 3 | Semantic (loose) | 0.85 | Catch remaining similar items |
Result: Aligned Structure
After alignment, the engine produces:When Alignment Matters
| Scenario | Alignment Needed? |
|---|---|
Simple fields (invoice_number, date) | No — same position |
| Tables / line items | Yes — order may vary |
| Nested arrays | Yes — recursive alignment |
| Single values | No — direct comparison |
n_consensus > 1.
Special Case: n=2 (Evaluation Mode)
When comparing exactly 2 sources, the alignment engine has a special optimization:Hungarian Algorithm
After the standard multi-pass alignment, any remaining unmatched items are paired using the Hungarian algorithm — an optimal bipartite matching that minimizes total “cost” (1 - similarity).Evaluation Use Case
With n=2, one source is typically a reference (ground truth) and the other is the prediction. This enables:- Per-field accuracy: How similar is each extracted field to the reference?
- Alignment quality: Did the model extract the same items?
- Error analysis: Which fields diverge from the reference?
Note: Numeric similarity is binary — either within 1% tolerance (score = 1.0) or not (score ≈ 0). There’s no gradient.
Note: For n=2 evaluation, the output is similarity scores (0-1 per field), not consensus values. This tells you how close the prediction is to the reference.