pub struct SemanticSplitter<E> { /* private fields */ }Expand description
Semantic chunker
Cuts a chunk where the similarity between adjacent sentences drops below
breakpoint_threshold; forces a break when the accumulated length exceeds
max_chunk_size.
Implementations§
Source§impl<E: Embeddings> SemanticSplitter<E>
impl<E: Embeddings> SemanticSplitter<E>
Sourcepub fn new(
embeddings: E,
breakpoint_threshold: f32,
max_chunk_size: usize,
) -> Self
pub fn new( embeddings: E, breakpoint_threshold: f32, max_chunk_size: usize, ) -> Self
Creates a semantic chunker
§Arguments
embeddings- the embedding modelbreakpoint_threshold- the breakpoint threshold for adjacent-sentence similarity (0.0–1.0; lower is harder to break)max_chunk_size- the maximum characters per chunk
Sourcepub fn with_defaults(embeddings: E) -> Self
pub fn with_defaults(embeddings: E) -> Self
Creates with default parameters (threshold=0.5, max=1000)
Sourcepub async fn split_text(
&self,
text: &str,
) -> Result<Vec<String>, EmbeddingError>
pub async fn split_text( &self, text: &str, ) -> Result<Vec<String>, EmbeddingError>
Chunks text asynchronously
Sourcepub async fn split_document(
&self,
document: &Document,
) -> Result<Vec<Document>, EmbeddingError>
pub async fn split_document( &self, document: &Document, ) -> Result<Vec<Document>, EmbeddingError>
Chunks a document asynchronously, preserving metadata (writes the chunk index)
Auto Trait Implementations§
impl<E> Freeze for SemanticSplitter<E>where
E: Freeze,
impl<E> RefUnwindSafe for SemanticSplitter<E>where
E: RefUnwindSafe,
impl<E> Send for SemanticSplitter<E>where
E: Send,
impl<E> Sync for SemanticSplitter<E>where
E: Sync,
impl<E> Unpin for SemanticSplitter<E>where
E: Unpin,
impl<E> UnsafeUnpin for SemanticSplitter<E>where
E: UnsafeUnpin,
impl<E> UnwindSafe for SemanticSplitter<E>where
E: 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