pub struct GroundingProjector { /* private fields */ }Expand description
Orthogonal grounding projector G = A(AᵀA)⁻¹Aᵀ.
Projects LLM output vectors onto the subspace spanned by evidence embeddings. The residual (I - G)x is the hallucination component.
Implementations§
Source§impl GroundingProjector
impl GroundingProjector
Sourcepub fn from_evidence(evidence: &[&[f32]], dim: usize) -> Option<Self>
pub fn from_evidence(evidence: &[&[f32]], dim: usize) -> Option<Self>
Build a grounding projector from evidence embeddings.
evidence is a slice of embedding vectors, each of length dim.
Returns None if evidence is empty or AᵀA is singular.
Sourcepub fn project_grounded(&self, x: &[f32]) -> Vec<f32>
pub fn project_grounded(&self, x: &[f32]) -> Vec<f32>
Project vector onto evidence subspace (grounded component).
Returns G·x — the part of x supported by evidence.
Sourcepub fn project_hallucinated(&self, x: &[f32]) -> Vec<f32>
pub fn project_hallucinated(&self, x: &[f32]) -> Vec<f32>
Project vector onto hallucination subspace.
Returns (I - G)·x — the part of x not supported by evidence.
Sourcepub fn hallucination_score(&self, x: &[f32]) -> f32
pub fn hallucination_score(&self, x: &[f32]) -> f32
Compute hallucination score for a vector.
Returns ‖(I - G)·x‖ / ‖x‖ ∈ [0, 1]. 0 = fully grounded, 1 = fully hallucinated.
Sourcepub fn decompose(&self, x: &[f32]) -> GroundingDecomposition
pub fn decompose(&self, x: &[f32]) -> GroundingDecomposition
Decompose a vector into grounded and hallucinated components with scores.
Sourcepub fn verify_idempotent(&self, tolerance: f32) -> bool
pub fn verify_idempotent(&self, tolerance: f32) -> bool
Verify G² ≈ G (idempotent — defining property of projection).
Sourcepub fn verify_symmetric(&self, tolerance: f32) -> bool
pub fn verify_symmetric(&self, tolerance: f32) -> bool
Verify Gᵀ = G (symmetric — orthogonal projection).
Trait Implementations§
Source§impl Clone for GroundingProjector
impl Clone for GroundingProjector
Source§fn clone(&self) -> GroundingProjector
fn clone(&self) -> GroundingProjector
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more