pub struct RefineDocumentsChain { /* private fields */ }Expand description
RefineDocumentsChain
Iteratively refines the answer document by document. Generates an initial answer from the first document, then refines with each subsequent document.
Implementations§
Source§impl RefineDocumentsChain
impl RefineDocumentsChain
Sourcepub fn new<L>(llm: L) -> Self
pub fn new<L>(llm: L) -> Self
Create a new RefineDocumentsChain with the given LLM.
Sourcepub fn with_initial_prompt(self, template: impl Into<String>) -> Self
pub fn with_initial_prompt(self, template: impl Into<String>) -> Self
Set the initial prompt template used for the first document.
Sourcepub fn with_refine_prompt(self, template: impl Into<String>) -> Self
pub fn with_refine_prompt(self, template: impl Into<String>) -> Self
Set the refine prompt template used for subsequent documents.
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 prompts.
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 build_initial_prompt(&self, context: &str, input: &str) -> String
pub fn build_initial_prompt(&self, context: &str, input: &str) -> String
Build the initial prompt from the first document’s content and input.
Sourcepub fn build_refine_prompt(
&self,
context: &str,
input: &str,
existing_answer: &str,
) -> String
pub fn build_refine_prompt( &self, context: &str, input: &str, existing_answer: &str, ) -> String
Build the refine prompt from the new context, input, and existing answer.
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 (iterative refinement).
Trait Implementations§
Source§impl BaseChain for RefineDocumentsChain
impl BaseChain for RefineDocumentsChain
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 RefineDocumentsChain.
Runs the initial + all intermediate refine steps via invoke (since
their output feeds the next step), then streams the final refine step
token by token via stream_chat. With a single document there is no
final refine step — the initial answer is emitted directly (P2-4), so
the LLM is not re-called on the identical initial prompt.