pub struct ConversationRetrievalChain { /* private fields */ }Expand description
ConversationRetrievalChain
Retrieval-augmented conversation chain with memory that automatically:
- Loads conversation history
- Retrieves relevant documents
- Combines history + context + question
- LLM generates answer
- Saves to conversation memory
Implementations§
Source§impl ConversationRetrievalChain
impl ConversationRetrievalChain
Sourcepub fn new<L>(
llm: L,
retriever: Arc<dyn RetrieverTrait>,
memory: ConversationBufferMemory,
) -> Self
pub fn new<L>( llm: L, retriever: Arc<dyn RetrieverTrait>, memory: ConversationBufferMemory, ) -> Self
Create a new ConversationRetrievalChain with the given LLM,
retriever, and conversation buffer memory.
Sourcepub fn from_memory<L>(
llm: L,
retriever: Arc<dyn RetrieverTrait>,
memory: Arc<Mutex<dyn BaseMemory>>,
) -> Self
pub fn from_memory<L>( llm: L, retriever: Arc<dyn RetrieverTrait>, memory: Arc<Mutex<dyn BaseMemory>>, ) -> Self
Create from any BaseMemory implementation (window / summary /
vector-store / persistent), mirroring ConversationChain::from_memory.
Sourcepub fn with_system_prompt(self, prompt: impl Into<String>) -> Self
pub fn with_system_prompt(self, prompt: impl Into<String>) -> Self
Set the system 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_return_source_documents(self, return_source: bool) -> Self
pub fn with_return_source_documents(self, return_source: bool) -> Self
Set whether to return the source documents with the answer.
Sourcepub async fn clear_memory(&self) -> Result<(), ChainError>
pub async fn clear_memory(&self) -> Result<(), ChainError>
Clear the conversation memory.
Trait Implementations§
Source§impl BaseChain for ConversationRetrievalChain
impl BaseChain for ConversationRetrievalChain
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 ConversationRetrievalChain – token by token output.
P2-2: real streaming — loads history, retrieves and assembles the prompt,
then pushes LLM tokens via stream_chat. The full answer is accumulated
through an unbounded channel (the P1-4 pattern) and written to memory
once the stream completes, matching the invoke path’s save_context.