pub struct MultiQueryRetriever { /* private fields */ }Expand description
MultiQueryRetriever
Uses an LLM to generate multiple query variants, retrieves with the base retriever for each one, then merges and dedups the results before returning.
Implementations§
Source§impl MultiQueryRetriever
impl MultiQueryRetriever
Sourcepub fn new<L>(llm: L, base_retriever: Arc<dyn RetrieverTrait>) -> Self
pub fn new<L>(llm: L, base_retriever: Arc<dyn RetrieverTrait>) -> Self
Creates a MultiQueryRetriever (accepting any LLM implementing BaseChatModel)
Sourcepub fn new_arc(
llm: Arc<dyn BaseChatModel<Error = ProviderError> + Send + Sync>,
base_retriever: Arc<dyn RetrieverTrait>,
) -> Self
pub fn new_arc( llm: Arc<dyn BaseChatModel<Error = ProviderError> + Send + Sync>, base_retriever: Arc<dyn RetrieverTrait>, ) -> Self
P0-3: Builds from an already-wrapped Arc<dyn BaseChatModel<Error = ProviderError>>
Sourcepub fn with_config(self, config: MultiQueryConfig) -> Self
pub fn with_config(self, config: MultiQueryConfig) -> Self
Sets the MultiQuery configuration
Sourcepub fn with_num_queries(self, n: usize) -> Self
pub fn with_num_queries(self, n: usize) -> Self
Sets the number of generated queries
Sourcepub fn with_k_per_query(self, k: usize) -> Self
pub fn with_k_per_query(self, k: usize) -> Self
Sets the number of documents returned per query
Sourcepub fn with_final_k(self, k: usize) -> Self
pub fn with_final_k(self, k: usize) -> Self
Sets the number of documents returned in the final result
Sourcepub async fn retrieve_multi(
&self,
query: &str,
) -> Result<Vec<Document>, MultiQueryError>
pub async fn retrieve_multi( &self, query: &str, ) -> Result<Vec<Document>, MultiQueryError>
Generates multiple query variants, retrieves each one, and returns the merged deduped documents
Sourcepub async fn retrieve_multi_with_scores(
&self,
query: &str,
) -> Result<Vec<SearchResult>, MultiQueryError>
pub async fn retrieve_multi_with_scores( &self, query: &str, ) -> Result<Vec<SearchResult>, MultiQueryError>
Generates multiple query variants, retrieves each one, and returns the merged deduped results with scores
Sourcepub async fn get_generated_queries(
&self,
query: &str,
) -> Result<Vec<String>, MultiQueryError>
pub async fn get_generated_queries( &self, query: &str, ) -> Result<Vec<String>, MultiQueryError>
Returns the LLM-generated query variants (without retrieving)