< Summary

Information
Class: Intentum.AI.Embeddings.EmbeddingScore
Assembly: Intentum.AI
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.AI/Embeddings/EmbeddingScore.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 39
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
Normalize(...)100%44100%
CosineSimilarity(...)100%66100%

File(s)

/home/runner/work/Intentum/Intentum/src/Intentum.AI/Embeddings/EmbeddingScore.cs

#LineLine coverage
 1using Intentum.AI.Similarity;
 2
 3namespace Intentum.AI.Embeddings;
 4
 5/// <summary>
 6/// Shared helpers for embedding score normalization used by provider embedding implementations.
 7/// </summary>
 8public static class EmbeddingScore
 9{
 10    /// <summary>
 11    /// Computes a scalar score from an embedding vector using L2 magnitude,
 12    /// normalized to [0, 1]. This provides a rough "activation strength" indicator.
 13    /// For meaningful similarity, use cosine similarity between two vectors instead.
 14    /// </summary>
 15    public static double Normalize(IReadOnlyList<double> values)
 916    {
 917        if (values.Count == 0)
 118            return 0;
 19
 820        var sumOfSquares = 0.0;
 5221        foreach (var v in values)
 1422            sumOfSquares += v * v;
 23
 824        var magnitude = Math.Sqrt(sumOfSquares / values.Count);
 825        return Math.Clamp(magnitude, 0.0, 1.0);
 926    }
 27
 28    /// <summary>
 29    /// Computes cosine similarity between two embedding vectors. Returns a value in [0, 1]
 30    /// where 1 means identical direction and 0 means orthogonal or opposite.
 31    /// </summary>
 32    public static double CosineSimilarity(IReadOnlyList<double> a, IReadOnlyList<double> b)
 1133    {
 1134        if (a.Count == 0 || b.Count == 0 || a.Count != b.Count)
 335            return 0;
 36
 837        return CosineSimilarityHelper.CosineSimilarityNormalized(a.ToArray(), b.ToArray());
 1138    }
 39}