pub struct ParallelChunker<C: Chunker + Clone> { /* private fields */ }Expand description
Parallel chunking orchestrator.
Wraps another chunker and uses rayon for parallel processing. Useful for very large texts where chunking itself is CPU-bound.
§Examples
use rlm_rs::chunking::{Chunker, ParallelChunker, SemanticChunker};
let chunker = ParallelChunker::new(SemanticChunker::new());
let text = "Hello, world! ".repeat(1000);
let chunks = chunker.chunk(1, &text, None).unwrap();Implementations§
Source§impl<C: Chunker + Clone> ParallelChunker<C>
impl<C: Chunker + Clone> ParallelChunker<C>
Sourcepub fn new(inner: C) -> Self
pub fn new(inner: C) -> Self
Creates a new parallel chunker wrapping the given chunker.
§Arguments
inner- The chunker to use for actual text processing.
Sourcepub const fn min_parallel_size(self, size: usize) -> Self
pub const fn min_parallel_size(self, size: usize) -> Self
Sets the minimum text size for parallel processing.
Texts smaller than this will be processed sequentially.
Sourcepub fn num_segments(self, n: usize) -> Self
pub fn num_segments(self, n: usize) -> Self
Sets the number of parallel segments.
Trait Implementations§
Source§impl<C: Chunker + Clone + Send + Sync> Chunker for ParallelChunker<C>
impl<C: Chunker + Clone + Send + Sync> Chunker for ParallelChunker<C>
Source§fn chunk(
&self,
buffer_id: i64,
text: &str,
metadata: Option<&ChunkMetadata>,
) -> Result<Vec<Chunk>>
fn chunk( &self, buffer_id: i64, text: &str, metadata: Option<&ChunkMetadata>, ) -> Result<Vec<Chunk>>
Chunks the input text into segments. Read more
Source§fn supports_parallel(&self) -> bool
fn supports_parallel(&self) -> bool
Returns whether this chunker supports parallel processing. Read more
Source§fn description(&self) -> &'static str
fn description(&self) -> &'static str
Returns a description of the chunking strategy.
Auto Trait Implementations§
impl<C> Freeze for ParallelChunker<C>where
C: Freeze,
impl<C> RefUnwindSafe for ParallelChunker<C>where
C: RefUnwindSafe,
impl<C> Send for ParallelChunker<C>
impl<C> Sync for ParallelChunker<C>
impl<C> Unpin for ParallelChunker<C>where
C: Unpin,
impl<C> UnwindSafe for ParallelChunker<C>where
C: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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 more