pub struct SelfQueryRetriever<M: BaseChatModel> { /* private fields */ }Expand description
Self-querying retriever: LLM splits the query -> whitelist validation -> filtered similarity search.
Implements RetrieverTrait and can be wrapped into an LCEL chain by crate::RetrieverRunnable.
Implementations§
Source§impl<M: BaseChatModel> SelfQueryRetriever<M>
impl<M: BaseChatModel> SelfQueryRetriever<M>
Sourcepub fn new(
llm: impl Into<Arc<M>>,
store: Arc<dyn VectorStore>,
embeddings: Arc<dyn Embeddings>,
allowed_attributes: Vec<String>,
) -> Self
pub fn new( llm: impl Into<Arc<M>>, store: Arc<dyn VectorStore>, embeddings: Arc<dyn Embeddings>, allowed_attributes: Vec<String>, ) -> Self
Creates a self-querying retriever.
llm: the model responsible for splitting the natural-language query (supports structured output, or falls back to text).store/embeddings: the vector store and embedding model used for the filtered similarity search.allowed_attributes: the whitelist of attributes allowed in filter fields; an empty whitelist disables filtering entirely (LLM-returned filters are always ignored with a warning); with a non-empty whitelist, a filter referencing a field outside the whitelist explicitly returnsRetrieverError::InvalidFilterrather than silently dropping it and falling back to an unfiltered search.
Trait Implementations§
Source§impl<M: BaseChatModel> RetrieverTrait for SelfQueryRetriever<M>
impl<M: BaseChatModel> RetrieverTrait for SelfQueryRetriever<M>
Source§fn retrieve<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
k: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Document>, RetrieverError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn retrieve<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
k: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Document>, RetrieverError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Retrieves relevant documents Read more
Source§fn retrieve_with_scores<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
k: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, RetrieverError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn retrieve_with_scores<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
k: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, RetrieverError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Retrieves relevant documents (with scores)
Auto Trait Implementations§
impl<M> !RefUnwindSafe for SelfQueryRetriever<M>
impl<M> !UnwindSafe for SelfQueryRetriever<M>
impl<M> Freeze for SelfQueryRetriever<M>
impl<M> Send for SelfQueryRetriever<M>
impl<M> Sync for SelfQueryRetriever<M>
impl<M> Unpin for SelfQueryRetriever<M>
impl<M> UnsafeUnpin for SelfQueryRetriever<M>where
Arc<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