parallel() strategy splits large documents into chunks, processes them concurrently, and uses an LLM to merge the extracted results.
Usage
Configuration
The AI SDK language model to use for extracting from each chunk.
The AI SDK language model to use for merging extracted 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. 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 have large documents that exceed context limits
- You want fast processing through parallelization
- You need an LLM to intelligently merge results
- You’re willing to use extra tokens for the merge step
Trade-offs
Advantages:- Fast processing through parallelization
- Intelligent LLM-based merging
- Handles documents of any size
- Configurable concurrency for rate limit management
- Higher token usage (chunk extractions + merge)
- Merge quality depends on merge model capability
- More expensive than simple strategy
Performance characteristics
The strategy estimatesbatches.length + 3 steps:
- Prepare
- Extract from batch 1 through N (parallel)
- Merge
- Complete