pub struct SemanticCoherenceScorer { /* private fields */ }Expand description
Semantic coherence scorer using sentence embeddings
Implementations§
Source§impl SemanticCoherenceScorer
impl SemanticCoherenceScorer
Sourcepub fn new(
config: CoherenceConfig,
embedding_provider: Arc<dyn EmbeddingProvider>,
) -> Self
pub fn new( config: CoherenceConfig, embedding_provider: Arc<dyn EmbeddingProvider>, ) -> Self
Create a new semantic coherence scorer
Sourcepub async fn score_chunk_coherence(&self, text: &str) -> Result<f32>
pub async fn score_chunk_coherence(&self, text: &str) -> Result<f32>
Score the semantic coherence of a text chunk
Returns a score between 0.0 (incoherent) and 1.0 (highly coherent). High coherence = high cosine similarity between sentence embeddings.
Sourcepub async fn find_optimal_split(
&self,
text: &str,
candidate_boundaries: &[usize],
) -> Result<OptimalSplit>
pub async fn find_optimal_split( &self, text: &str, candidate_boundaries: &[usize], ) -> Result<OptimalSplit>
Find optimal split points in text to maximize chunk coherence
Uses a greedy algorithm:
- Start with no splits
- Try all candidate split points
- Pick split that maximizes average chunk coherence
- Repeat until coherence stops improving
Sourcepub fn cosine_similarity(&self, a: &[f32], b: &[f32]) -> f32
pub fn cosine_similarity(&self, a: &[f32], b: &[f32]) -> f32
Calculate cosine similarity between two embedding vectors
Sourcepub fn calculate_adaptive_threshold(&self, text: &str) -> f32
pub fn calculate_adaptive_threshold(&self, text: &str) -> f32
Calculate adaptive threshold based on content characteristics
Auto Trait Implementations§
impl Freeze for SemanticCoherenceScorer
impl !RefUnwindSafe for SemanticCoherenceScorer
impl Send for SemanticCoherenceScorer
impl Sync for SemanticCoherenceScorer
impl Unpin for SemanticCoherenceScorer
impl UnsafeUnpin for SemanticCoherenceScorer
impl !UnwindSafe for SemanticCoherenceScorer
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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