Function engram::metrics::cosine_similarity

source ·
pub fn cosine_similarity(a: &[f64], b: &[f64]) -> f64
Expand description

Compute the cosine similarity between two vectors. Formula: dot(a, b) / (|a| * |b|)

§Examples

let a = [1.0, 2.0, 3.0];
let b = [1.0, 2.0, 3.0];
let c = [1.0, 2.0, 4.0];
let cs_ab = cosine_similarity(&a, &b);
let cs_ac = cosine_similarity(&a, &c);