pub fn chunk_text(
text: &str,
chunk_size: usize,
options: Option<ChunkOptions>,
) -> Vec<String>Expand description
Split text into chunks of specified size
§Arguments
text- The text to be splitchunk_size- Maximum size of each chunk (in characters)options- Optional chunking options
§Returns
A vector of text chunks
§Example
use overlap_chunk::{chunk_text, ChunkOptions};
let text = "This is a test text. We will split this long text into smaller chunks.";
let chunks = chunk_text(text, 10, None);
assert_eq!(chunks.len(), 7);
let options = ChunkOptions {
overlap_percentage: 50,
..Default::default()
};
let chunks_with_overlap = chunk_text(text, 10, Some(options));
assert_eq!(chunks_with_overlap.len(), 14);