MCPcopy Index your code
hub / github.com/InfinitiBit/graphbit / with_separators

Method with_separators

core/src/text_splitter.rs:632–666  ·  view source on GitHub ↗

Create a recursive splitter with custom separators

(
        chunk_size: usize,
        chunk_overlap: usize,
        separators: Vec<String>,
    )

Source from the content-addressed store, hash-verified

630
631 /// Create a recursive splitter with custom separators
632 pub fn with_separators(
633 chunk_size: usize,
634 chunk_overlap: usize,
635 separators: Vec<String>,
636 ) -> GraphBitResult<Self> {
637 if chunk_size == 0 {
638 return Err(GraphBitError::validation(
639 "text_splitter",
640 "Chunk size must be greater than 0",
641 ));
642 }
643
644 if separators.is_empty() {
645 return Err(GraphBitError::validation(
646 "text_splitter",
647 "At least one separator must be provided",
648 ));
649 }
650
651 let config = TextSplitterConfig {
652 strategy: SplitterStrategy::Recursive {
653 chunk_size,
654 chunk_overlap,
655 separators: Some(separators.clone()),
656 },
657 ..Default::default()
658 };
659
660 Ok(Self {
661 config,
662 chunk_size,
663 chunk_overlap,
664 separators,
665 })
666 }
667
668 /// Recursively split text using the best separator
669 fn recursive_split(&self, text: &str, separators: &[String]) -> Vec<String> {

Callers

nothing calls this directly

Calls 2

cloneMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected