pub struct ParentDocumentRetriever<S: ChunkedDocumentStoreTrait = ChunkedDocumentStore> { /* private fields */ }Expand description
父子文档检索器。
文档入库时被切成小块(leaf)索引,查询命中任意小块就返回整篇父文档。
这与 ChunkedBM25Retriever 的 AutoMerging(按命中比例门控,阈值不足
返回小块)不同:ParentDocument 是“小块召回、整文喂给 LLM“的经典 RAG
模式 —— 小块负责精确命中,整篇父文档负责给 LLM 提供完整上下文。
内部用 RwLock 包一层 ChunkedBM25Retriever:检索走读锁、入库走写锁,
因此能实现 RetrieverTrait (其方法全为
&self)。配合 RetrieverRunnable 可以直接进
LCEL 链:
ⓘ
let retriever = Arc::new(ParentDocumentRetriever::new(store));
let chain = RetrieverRunnable::new(retriever, 4).pipe(prompt).pipe(llm);Implementations§
Source§impl<S: ChunkedDocumentStoreTrait> ParentDocumentRetriever<S>
impl<S: ChunkedDocumentStoreTrait> ParentDocumentRetriever<S>
Sourcepub fn with_config(store: Arc<S>, config: AutoMergingConfig) -> Self
pub fn with_config(store: Arc<S>, config: AutoMergingConfig) -> Self
使用指定 AutoMerging 配置创建检索器。
配置中的 leaf_chunk_size 决定小块切分粒度;merge_threshold 在
ParentDocument 语义下不参与命中判定(命中任意小块即返回父文档),但
仍用于约束底层索引的切分行为。
Sourcepub fn inner(&self) -> &RwLock<ChunkedBM25Retriever<S>>
pub fn inner(&self) -> &RwLock<ChunkedBM25Retriever<S>>
返回内部检索器引用,需要直接访问底层索引时使用。
例如只读检索用 retriever.inner().read().await,入库用 .write().await。
Trait Implementations§
Source§impl<S: ChunkedDocumentStoreTrait> RetrieverTrait for ParentDocumentRetriever<S>
impl<S: ChunkedDocumentStoreTrait> RetrieverTrait for ParentDocumentRetriever<S>
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,
检索相关文档 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,
检索相关文档(带分数)
Auto Trait Implementations§
impl<S = InMemoryChunkedDocumentStore> !Freeze for ParentDocumentRetriever<S>
impl<S = InMemoryChunkedDocumentStore> !RefUnwindSafe for ParentDocumentRetriever<S>
impl<S = InMemoryChunkedDocumentStore> !UnwindSafe for ParentDocumentRetriever<S>
impl<S> Send for ParentDocumentRetriever<S>
impl<S> Sync for ParentDocumentRetriever<S>
impl<S> Unpin for ParentDocumentRetriever<S>
impl<S> UnsafeUnpin for ParentDocumentRetriever<S>
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