pub struct DocumentChunker {
pub config: DocumentChunkerConfig,
pub chunks_produced: u64,
pub documents_processed: u64,
}Expand description
Document chunking engine.
Maintains running counters for chunks produced and documents processed
across the lifetime of the instance. All heavy work is done in the
chunk_* family of methods.
Fields§
§config: DocumentChunkerConfigActive configuration.
chunks_produced: u64Total number of TextChunks emitted since construction.
documents_processed: u64Total number of documents submitted to DocumentChunker::chunk_text.
Implementations§
Source§impl DocumentChunker
impl DocumentChunker
Sourcepub fn new(config: DocumentChunkerConfig) -> Self
pub fn new(config: DocumentChunkerConfig) -> Self
Construct a new DocumentChunker with the supplied configuration.
Sourcepub fn chunk_text(&mut self, doc_id: &str, text: &str) -> Vec<TextChunk>
pub fn chunk_text(&mut self, doc_id: &str, text: &str) -> Vec<TextChunk>
Chunk text using the strategy stored in self.config, filter chunks
shorter than min_chunk_chars, and update internal counters.
Sourcepub fn chunk_fixed_size(
&self,
doc_id: &str,
text: &str,
size: usize,
overlap: usize,
) -> Vec<TextChunk>
pub fn chunk_fixed_size( &self, doc_id: &str, text: &str, size: usize, overlap: usize, ) -> Vec<TextChunk>
Split text into fixed-size windows of size characters stepping by
size - overlap characters between each window.
If overlap >= size it is clamped to size.saturating_sub(1) to
guarantee progress.
Sourcepub fn chunk_sentence_boundary(
&self,
doc_id: &str,
text: &str,
max_chars: usize,
overlap_sentences: usize,
) -> Vec<TextChunk>
pub fn chunk_sentence_boundary( &self, doc_id: &str, text: &str, max_chars: usize, overlap_sentences: usize, ) -> Vec<TextChunk>
Split text at sentence boundaries and group sentences so that each
chunk stays within max_chars characters. The last overlap_sentences
sentences of each chunk are prepended to the next chunk.
Sourcepub fn chunk_paragraph(
&self,
doc_id: &str,
text: &str,
max_chars: usize,
) -> Vec<TextChunk>
pub fn chunk_paragraph( &self, doc_id: &str, text: &str, max_chars: usize, ) -> Vec<TextChunk>
Split text at \n\n paragraph boundaries. Paragraphs that exceed
max_chars are further split at sentence boundaries.
Sourcepub fn chunk_semantic(
&self,
doc_id: &str,
text: &str,
max_chars: usize,
_threshold: f64,
) -> Vec<TextChunk>
pub fn chunk_semantic( &self, doc_id: &str, text: &str, max_chars: usize, _threshold: f64, ) -> Vec<TextChunk>
Group sentences into chunks of at most max_chars characters.
_threshold is a placeholder for future embedding-based similarity.
Sourcepub fn merge_small_chunks(
chunks: Vec<TextChunk>,
min_chars: usize,
) -> Vec<TextChunk>
pub fn merge_small_chunks( chunks: Vec<TextChunk>, min_chars: usize, ) -> Vec<TextChunk>
Merge chunks shorter than min_chars into the following chunk.
The last chunk absorbs any trailing short chunks. Offsets and indices
are updated in place.
Sourcepub fn stats(chunks: &[TextChunk]) -> ChunkStats
pub fn stats(chunks: &[TextChunk]) -> ChunkStats
Compute aggregate statistics over a slice of chunks.
Sourcepub fn rechunk_with_strategy(
&mut self,
doc_id: &str,
text: &str,
strategy: ChunkStrategy,
) -> Vec<TextChunk>
pub fn rechunk_with_strategy( &mut self, doc_id: &str, text: &str, strategy: ChunkStrategy, ) -> Vec<TextChunk>
Temporarily override the strategy on this chunker, produce chunks, then restore the original strategy.
Sourcepub fn set_metadata(chunks: &mut [TextChunk], key: &str, value: &str)
pub fn set_metadata(chunks: &mut [TextChunk], key: &str, value: &str)
Add key = value metadata to every chunk in chunks.
Sourcepub fn chunker_stats(&self) -> (u64, u64)
pub fn chunker_stats(&self) -> (u64, u64)
Return (chunks_produced, documents_processed) counters.
Trait Implementations§
Source§impl Clone for DocumentChunker
impl Clone for DocumentChunker
Source§fn clone(&self) -> DocumentChunker
fn clone(&self) -> DocumentChunker
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DocumentChunker
impl RefUnwindSafe for DocumentChunker
impl Send for DocumentChunker
impl Sync for DocumentChunker
impl Unpin for DocumentChunker
impl UnsafeUnpin for DocumentChunker
impl UnwindSafe for DocumentChunker
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.