pub struct ConversationRetrievalChain<M: BaseChatModel> { /* 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<M: BaseChatModel + 'static> ConversationRetrievalChain<M>
impl<M: BaseChatModel + 'static> ConversationRetrievalChain<M>
pub fn new( llm: M, retriever: Arc<dyn RetrieverTrait>, memory: ConversationBufferMemory, ) -> Self
Sourcepub fn from_memory(
llm: M,
retriever: Arc<dyn RetrieverTrait>,
memory: Arc<Mutex<dyn BaseMemory>>,
) -> Self
pub fn from_memory( llm: M, retriever: Arc<dyn RetrieverTrait>, memory: Arc<Mutex<dyn BaseMemory>>, ) -> Self
Create from any BaseMemory implementation (window / summary /
vector-store / persistent), mirroring ConversationChain::from_memory.
pub fn with_system_prompt(self, prompt: impl Into<String>) -> Self
pub fn with_input_key(self, key: impl Into<String>) -> Self
pub fn with_output_key(self, key: impl Into<String>) -> Self
pub fn with_name(self, name: impl Into<String>) -> Self
pub fn with_k(self, k: usize) -> Self
pub fn with_verbose(self, verbose: bool) -> Self
pub fn with_return_source_documents(self, return_source: bool) -> Self
pub fn memory(&self) -> &Arc<Mutex<dyn BaseMemory>> ⓘ
pub async fn clear_memory(&self) -> Result<(), ChainError>
Trait Implementations§
Source§impl<M: BaseChatModel + Send + Sync + 'static> BaseChain for ConversationRetrievalChain<M>
impl<M: BaseChatModel + Send + Sync + 'static> BaseChain for ConversationRetrievalChain<M>
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.
Source§fn input_keys(&self) -> Vec<&str>
fn input_keys(&self) -> Vec<&str>
Get input keys.
Source§fn output_keys(&self) -> Vec<&str>
fn output_keys(&self) -> Vec<&str>
Get output keys.
Source§fn invoke<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn invoke<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Execute the Chain. Read more
Source§fn invoke_with_config<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn invoke_with_config<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Execute the Chain with a RunnableConfig. Read more
Source§fn stream_with_config<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<ChainStream, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream_with_config<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<ChainStream, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream execute the Chain with a RunnableConfig. Read more
Source§fn validate_inputs(
&self,
inputs: &HashMap<String, Value>,
) -> Result<(), ChainError>
fn validate_inputs( &self, inputs: &HashMap<String, Value>, ) -> Result<(), ChainError>
Validate inputs.
Auto Trait Implementations§
impl<M> !RefUnwindSafe for ConversationRetrievalChain<M>
impl<M> !UnwindSafe for ConversationRetrievalChain<M>
impl<M> Freeze for ConversationRetrievalChain<M>where
M: Freeze,
impl<M> Send for ConversationRetrievalChain<M>
impl<M> Sync for ConversationRetrievalChain<M>
impl<M> Unpin for ConversationRetrievalChain<M>where
M: Unpin,
impl<M> UnsafeUnpin for ConversationRetrievalChain<M>where
M: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more