pub struct ParentDocumentRetriever<S: ChunkedDocumentStoreTrait = ChunkedDocumentStore> { /* private fields */ }Expand description
A parent/child document retriever.
On ingestion, documents are split into small chunks (leaves) for indexing; any leaf hit
returns the entire parent document. This differs from ChunkedBM25Retriever’s
AutoMerging (gated by hit ratio; returns leaf chunks when the threshold is not met):
ParentDocument is the classic RAG pattern of “small-chunk recall, full document fed to
the LLM” — the leaf chunks provide precise hits, while the whole parent document gives
the LLM complete context.
Internally it wraps a ChunkedBM25Retriever in an RwLock: retrieval takes the read
lock, ingestion takes the write lock, so it can implement RetrieverTrait (whose
methods all take &self). Combined with
RetrieverRunnable it can plug directly into an LCEL chain:
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
Creates a retriever with the specified AutoMerging configuration.
leaf_chunk_size in the config determines the leaf-chunk granularity; under the
ParentDocument semantics merge_threshold does not take part in hit decisions
(any leaf hit returns the parent document), but it still constrains how the
underlying index is chunked.
Sourcepub fn inner(&self) -> &RwLock<ChunkedBM25Retriever<S>>
pub fn inner(&self) -> &RwLock<ChunkedBM25Retriever<S>>
Returns the inner retriever reference, for direct access to the underlying index.
For example, read-only retrieval uses retriever.inner().read().await; ingestion
uses .write().await.