pub struct MapRerankDocumentsChain { /* private fields */ }Expand description
MapRerankDocumentsChain
First calls LLM independently for each document to generate an answer and score, then ranks by relevance score and returns the highest-scoring answer.
Implementations§
Source§impl MapRerankDocumentsChain
impl MapRerankDocumentsChain
Sourcepub fn new<L>(llm: L) -> Self
pub fn new<L>(llm: L) -> Self
Create a new MapRerankDocumentsChain 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_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_top_k(self, k: usize) -> Self
pub fn with_top_k(self, k: usize) -> Self
Set the number of top results to return.
Sourcepub fn with_default_score(self, score: u32) -> Self
pub fn with_default_score(self, score: u32) -> Self
Configure the fallback score for LLM output without a parseable score.
None (default) skips such documents; Some(n) ranks them with score n
instead of silently assigning the old middle score 50 (P1-3).
Sourcepub fn build_map_prompt(&self, context: &str, input: &str) -> String
pub fn build_map_prompt(&self, context: &str, input: &str) -> String
Build Map stage prompt.
Sourcepub async fn invoke_with_documents(
&self,
documents: Vec<Document>,
input: &str,
) -> Result<Vec<(u32, String)>, ChainError>
pub async fn invoke_with_documents( &self, documents: Vec<Document>, input: &str, ) -> Result<Vec<(u32, String)>, ChainError>
Invoke with documents and input directly.
Trait Implementations§
Source§impl BaseChain for MapRerankDocumentsChain
impl BaseChain for MapRerankDocumentsChain
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 MapRerankDocumentsChain.
P2-2: the map phase runs via stream_chat per document (tokens
accumulated for scoring), then the reranked top answer(s) are emitted.
Raw token streaming of the final answer is impossible here — ranking
requires each document’s complete output — so the ranked result is the
stream payload, produced without the base default’s silent unwrap_or("").