doublePassAutoMerge() strategy performs extraction in two passes: first, it processes chunks in parallel with automatic merging and deduplication; second, it processes chunks sequentially using the deduplicated result as context to refine the extraction.
Usage
Configuration
The AI SDK language model to use for extraction in both passes.
Maximum tokens per chunk. Documents are split into batches that fit within this limit.
Maximum number of concurrent extraction tasks in pass 1. Defaults to processing all chunks in parallel.
Maximum number of images per chunk. Useful for controlling vision API costs.
Additional instructions to guide the model’s output format or behavior.
The AI SDK language model to use for semantic deduplication. Defaults to the extraction
model.Custom retry executor function for extraction. Defaults to
runWithRetries.Custom retry executor function for deduplication. Defaults to
runWithRetries.Enable strict mode for structured output validation. Defaults to
false.When to use
- You need the highest extraction quality with automatic deduplication
- You have complex documents with duplicate data
- You don’t want to write custom merge logic
- You’re willing to pay for double processing plus deduplication
How it works
- Pass 1 - Parallel: Extracts from all chunks concurrently
- Pass 1 - Auto-merge: Uses
SmartDataMergerwith schema-aware logic - Pass 1 - Dedupe: Removes exact duplicates, then uses LLM to find semantic duplicates
- Pass 2 - Sequential: Re-processes each chunk sequentially, using pass 1 deduplicated results as context to refine extraction
Trade-offs
Advantages:- Highest extraction quality
- Automatic duplicate removal
- No custom merge logic needed
- Schema-aware merging
- Second pass can correct mistakes and add missing data
- Highest token usage (2x extraction + dedupe)
- Slowest overall processing time
- Most expensive strategy
- Less control over merge strategy
Performance characteristics
The strategy estimatesbatches.length * 2 + 3 steps:
- Prepare
- Pass 1: Extract from batch 1 through N (parallel)
- Pass 1: Dedupe
- Pass 2: Extract from batch 1 through N (sequential)
- Complete