Struct text_splitter::ChunkConfig
source · pub struct ChunkConfig<Sizer>where
Sizer: ChunkSizer,{ /* private fields */ }Expand description
Configuration for how chunks should be created
Implementations§
source§impl ChunkConfig<Characters>
impl ChunkConfig<Characters>
sourcepub fn new(capacity: impl Into<ChunkCapacity>) -> Self
pub fn new(capacity: impl Into<ChunkCapacity>) -> Self
Create a basic configuration for chunking with only the required value a chunk capacity.
By default, chunk sizes will be calculated based on the number of characters in each chunk.
You can set a custom chunk sizer by calling Self::with_sizer.
By default, chunks will be trimmed. If you want to preserve whitespace,
call Self::with_trim and set it to false.
source§impl<Sizer> ChunkConfig<Sizer>where
Sizer: ChunkSizer,
impl<Sizer> ChunkConfig<Sizer>where
Sizer: ChunkSizer,
sourcepub fn capacity(&self) -> &ChunkCapacity
pub fn capacity(&self) -> &ChunkCapacity
Retrieve a reference to the chunk capacity for this configuration.
sourcepub fn with_overlap(self, overlap: usize) -> Result<Self, ChunkConfigError>
pub fn with_overlap(self, overlap: usize) -> Result<Self, ChunkConfigError>
Set the amount of overlap between chunks.
§Errors
Will return an error if the overlap is larger than or equal to the chunk capacity.
sourcepub fn with_sizer<S: ChunkSizer>(self, sizer: S) -> ChunkConfig<S>
pub fn with_sizer<S: ChunkSizer>(self, sizer: S) -> ChunkConfig<S>
Set a custom chunk sizer to use for determining the size of each chunk
use text_splitter::{Characters, ChunkConfig};
let config = ChunkConfig::new(512).with_sizer(Characters);sourcepub fn trim(&self) -> bool
pub fn trim(&self) -> bool
Whether chunkd should have whitespace trimmed from the beginning and end or not.
sourcepub fn with_trim(self, trim: bool) -> Self
pub fn with_trim(self, trim: bool) -> Self
Specify whether chunks should have whitespace trimmed from the beginning and end or not.
If false (default), joining all chunks should return the original
string.
If true, all chunks will have whitespace removed from beginning and end.
use text_splitter::ChunkConfig;
let config = ChunkConfig::new(512).with_trim(false);Trait Implementations§
source§impl<Sizer> Debug for ChunkConfig<Sizer>where
Sizer: ChunkSizer + Debug,
impl<Sizer> Debug for ChunkConfig<Sizer>where
Sizer: ChunkSizer + Debug,
source§impl<T> From<T> for ChunkConfig<Characters>where
T: Into<ChunkCapacity>,
impl<T> From<T> for ChunkConfig<Characters>where
T: Into<ChunkCapacity>,
Auto Trait Implementations§
impl<Sizer> Freeze for ChunkConfig<Sizer>where
Sizer: Freeze,
impl<Sizer> RefUnwindSafe for ChunkConfig<Sizer>where
Sizer: RefUnwindSafe,
impl<Sizer> Send for ChunkConfig<Sizer>where
Sizer: Send,
impl<Sizer> Sync for ChunkConfig<Sizer>where
Sizer: Sync,
impl<Sizer> Unpin for ChunkConfig<Sizer>where
Sizer: Unpin,
impl<Sizer> UnwindSafe for ChunkConfig<Sizer>where
Sizer: 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
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 more