doublePass() strategy performs extraction in two passes: first, it processes chunks in parallel and merges them with an LLM; second, it processes chunks sequentially using the merged result as context to refine the extraction.
Usage
Configuration
The AI SDK language model to use for extraction in both passes.
The AI SDK language model to use for merging pass 1 results. Typically a more capable model.
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.
Custom retry executor function. Defaults to
runWithRetries.Enable strict mode for structured output validation. Defaults to
false.When to use
- You need the highest extraction quality
- You have complex documents requiring multiple perspectives
- You’re willing to pay for double processing
- Initial parallel extraction needs refinement from sequential context
How it works
- Pass 1 - Parallel: Extracts from all chunks concurrently
- Pass 1 - Merge: Uses an LLM to merge parallel results
- Pass 2 - Sequential: Re-processes each chunk sequentially, using pass 1 results as context to refine and improve extraction
Trade-offs
Advantages:- Highest extraction quality
- Combines benefits of both parallel and sequential strategies
- Second pass can correct mistakes from first pass
- Fast initial extraction, then refinement
- Highest token usage (2x extraction + merge)
- Slowest overall processing time
- Most expensive strategy
- May be overkill for simple documents
Performance characteristics
The strategy estimatesbatches.length * 2 + 3 steps:
- Prepare
- Pass 1: Extract from batch 1 through N (parallel)
- Pass 1: Merge
- Pass 2: Extract from batch 1 through N (sequential)
- Complete