Skip to main content

TextSplitter

Struct TextSplitter 

Source
pub struct TextSplitter {
    pub split_separator: Separator,
    pub recursive: bool,
    pub clean_text: bool,
    pub max_token_size: Option<u32>,
    pub tokenizer: Option<Arc<dyn Tokenizer + Send + Sync>>,
}

Fields§

§split_separator: Separator§recursive: bool§clean_text: bool§max_token_size: Option<u32>

Optional maximum token size for chunks. When set, recursive splitting will only drill down to finer separators when a chunk exceeds this limit.

§tokenizer: Option<Arc<dyn Tokenizer + Send + Sync>>

Optional tokenizer for accurate token counting. If not set, token counting is skipped and max_token_size constraint is ignored.

Implementations§

Source§

impl TextSplitter

Source

pub fn new() -> Self

Source

pub fn split_text(&self, text: &str) -> Option<VecDeque<TextSplit>>

Source

pub fn on_two_plus_newline(self) -> Self

Source

pub fn on_single_newline(self) -> Self

Source

pub fn on_sentences_rule_based(self) -> Self

Source

pub fn on_sentences_unicode(self) -> Self

Source

pub fn on_words_unicode(self) -> Self

Source

pub fn on_graphemes_unicode(self) -> Self

Source

pub fn on_separator(self, split_separator: &Separator) -> Self

Source

pub fn recursive(self, recursive: bool) -> Self

Source

pub fn clean_text(self, clean_text: bool) -> Self

Source

pub fn max_token_size(self, max_tokens: u32) -> Self

Set the maximum token size for chunks. When set with a tokenizer, recursive splitting will only drill down to finer separators when a chunk exceeds this limit.

Source

pub fn with_tokenizer(self, tokenizer: Arc<dyn Tokenizer + Send + Sync>) -> Self

Set the tokenizer for accurate token counting.

Source

pub fn split_text_split(self, split: &TextSplit) -> Option<VecDeque<TextSplit>>

Split a TextSplit into smaller splits using the configured separator. This is the public API that accepts a TextSplit directly.

Source

pub fn splits_to_text( splits: &VecDeque<TextSplit>, with_separator: bool, ) -> String

Trait Implementations§

Source§

impl Default for TextSplitter

Source§

fn default() -> TextSplitter

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.