pub struct MapReduceDocumentsChain { /* private fields */ }Expand description
MapReduceDocumentsChain
Processes documents in two steps:
- Map: Calls LLM independently for each document to generate an answer
- Reduce: Merges all independent answers into a final answer
Implementations§
Source§impl MapReduceDocumentsChain
impl MapReduceDocumentsChain
Sourcepub fn new<L>(llm: L) -> Self
pub fn new<L>(llm: L) -> Self
Create a new MapReduceDocumentsChain with the given LLM.
Sourcepub fn with_map_prompt(self, template: impl Into<String>) -> Self
pub fn with_map_prompt(self, template: impl Into<String>) -> Self
Set the map-phase prompt template.
Sourcepub fn with_reduce_prompt(self, template: impl Into<String>) -> Self
pub fn with_reduce_prompt(self, template: impl Into<String>) -> Self
Set the reduce-phase prompt template.
Sourcepub fn with_document_variable(self, name: impl Into<String>) -> Self
pub fn with_document_variable(self, name: impl Into<String>) -> Self
Set the document variable name used in the map prompt.
Sourcepub fn with_input_key(self, key: impl Into<String>) -> Self
pub fn with_input_key(self, key: impl Into<String>) -> Self
Set the input key.
Sourcepub fn with_output_key(self, key: impl Into<String>) -> Self
pub fn with_output_key(self, key: impl Into<String>) -> Self
Set the output key.
Sourcepub fn with_verbose(self, verbose: bool) -> Self
pub fn with_verbose(self, verbose: bool) -> Self
Set verbose mode.
Sourcepub fn with_map_concurrency(self, limit: usize) -> Self
pub fn with_map_concurrency(self, limit: usize) -> Self
Cap the number of concurrent map-phase LLM calls (P2-6).
Default is unbounded (all documents mapped in parallel). Setting a limit bounds in-flight requests — useful to respect provider rate limits or bound memory on large document sets.
Sourcepub fn build_map_prompt(&self, context: &str, input: &str) -> String
pub fn build_map_prompt(&self, context: &str, input: &str) -> String
Build the map-phase prompt by substituting the document content and input.
Sourcepub fn build_reduce_prompt(&self, summaries: &[String], input: &str) -> String
pub fn build_reduce_prompt(&self, summaries: &[String], input: &str) -> String
Build the reduce-phase prompt from the per-document summaries and input.
Sourcepub async fn invoke_with_documents(
&self,
documents: Vec<Document>,
input: &str,
) -> Result<String, ChainError>
pub async fn invoke_with_documents( &self, documents: Vec<Document>, input: &str, ) -> Result<String, ChainError>
Invoke with documents and input directly.
Trait Implementations§
Source§impl BaseChain for MapReduceDocumentsChain
impl BaseChain for MapReduceDocumentsChain
Source§fn stream<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<ChainStream, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<ChainStream, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream execution for MapReduceDocumentsChain.
The map phase runs via invoke (parallel, non-streaming, since reduce
needs all summaries) — bounded by map_concurrency when configured.
The reduce phase is streamed token by token via stream_chat.