pub struct RetrievalQA { /* private fields */ }Expand description
RetrievalQA Chain
One-stop retrieval QA chain that automatically:
- Retrieves relevant documents
- Assembles prompt (context + question)
- LLM generates answer
Implementations§
Source§impl RetrievalQA
impl RetrievalQA
Sourcepub fn new<L>(llm: L, retriever: Arc<dyn RetrieverTrait>) -> Self
pub fn new<L>(llm: L, retriever: Arc<dyn RetrieverTrait>) -> Self
Create a new RetrievalQA chain with the given LLM and retriever.
Sourcepub fn with_prompt_template(self, template: impl Into<String>) -> Self
pub fn with_prompt_template(self, template: impl Into<String>) -> Self
Set the prompt template.
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 fn with_source_document_key(self, key: impl Into<String>) -> Self
pub fn with_source_document_key(self, key: impl Into<String>) -> Self
Set the key under which source documents are placed in the output.
Sourcepub fn retriever(&self) -> &Arc<dyn RetrieverTrait> ⓘ
pub fn retriever(&self) -> &Arc<dyn RetrieverTrait> ⓘ
Get the retriever reference.
Sourcepub async fn query(
&self,
question: impl Into<String>,
) -> Result<String, ChainError>
pub async fn query( &self, question: impl Into<String>, ) -> Result<String, ChainError>
Simplified query interface returning the answer string.
Sourcepub async fn query_with_sources(
&self,
question: impl Into<String>,
) -> Result<(String, Vec<Document>), ChainError>
pub async fn query_with_sources( &self, question: impl Into<String>, ) -> Result<(String, Vec<Document>), ChainError>
Query the chain, returning both the answer and the retrieved source documents.
Trait Implementations§
Source§impl BaseChain for RetrievalQA
impl BaseChain for RetrievalQA
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 RetrievalQA – token by token output.
P2-2: real streaming — retrieves and assembles the prompt first, then
pushes LLM tokens via stream_chat instead of wrapping invoke in a
single chunk (the base default).
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 !RefUnwindSafe for RetrievalQA
impl !UnwindSafe for RetrievalQA
impl Freeze for RetrievalQA
impl Send for RetrievalQA
impl Sync for RetrievalQA
impl Unpin for RetrievalQA
impl UnsafeUnpin for RetrievalQA
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