/** * MapReduce — fan-out N LLMCalls over deterministic input shards, reduce. * * Origin: classic map-reduce (Dean & Ghemawat, 2004) applied to * LLM context-window constraints. Seen in long-document * summarization: split → summarize each → combine. * * Pattern: Factory → produces a Runner composing `Parallel` of N * shard-aware branches. Each branch is an LLMCall wrapped so it * extracts its shard index from the input by position. * Role: patterns/ layer. Pure composition over existing primitives. * * Shard count is fixed at build time — consumer supplies `shardCount` * and a `split(input, shardCount)` function that MUST return exactly * `shardCount` strings. The extracted strings are packed into one * `message` at run time (delimiter `\u001F`) so each branch can pick * its own index. For run-time-variable shard counts, factor MapReduce * inside a wrapping Runner that rebuilds the Parallel per call. */ import type { LLMProvider } from '../adapters/types.js'; import type { Runner } from '../core/runner.js'; import type { MergeFn, MergeWithLLMOptions } from '../core-flow/Parallel.js'; export interface MapReduceOptions { readonly provider: LLMProvider; readonly model: string; /** System prompt applied to every shard's LLMCall. */ readonly mapPrompt: string; /** * Number of shards to fan out. Must be >= 2 (for one-shard, use * `LLMCall` directly). Fixed at build time. */ readonly shardCount: number; /** * Splitter invoked at run time with `(input, shardCount)`. MUST return * exactly `shardCount` strings. If it returns fewer, remaining shards * receive empty strings; more are truncated. */ readonly split: (input: string, shardCount: number) => readonly string[]; /** * Reducer — either a pure fn combining the N shard outputs, OR an LLM * synthesizer. */ readonly reduce: { readonly kind: 'fn'; readonly fn: MergeFn; } | { readonly kind: 'llm'; readonly opts: MergeWithLLMOptions; }; readonly temperature?: number; readonly maxTokens?: number; readonly name?: string; readonly id?: string; } /** * Build a MapReduce Runner. At run time: * 1. The splitter runs the consumer's `split(input, shardCount)` and * packs the resulting N shards into a delimited string. * 2. Parallel fans out to N branches. Each branch's wrapper extracts * its own shard from the packed input and feeds it to the shared * LLMCall. * 3. The reducer combines the N branch outputs into the final string. */ export declare function mapReduce(opts: MapReduceOptions): Runner<{ message: string; }, string>; //# sourceMappingURL=MapReduce.d.ts.map