< Summary

Information
Class: Intentum.AI.Similarity.SimpleAverageSimilarityEngine
Assembly: Intentum.AI
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.AI/Similarity/SimpleAverageSimilarityEngine.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 33
Line coverage: 100%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
CalculateIntentScore(...)100%11100%
CalculateIntentScore(...)90%1010100%

File(s)

/home/runner/work/Intentum/Intentum/src/Intentum.AI/Similarity/SimpleAverageSimilarityEngine.cs

#LineLine coverage
 1using Intentum.AI.Embeddings;
 2
 3namespace Intentum.AI.Similarity;
 4
 5/// <summary>
 6/// Similarity engine that averages embedding scores; optionally weighted by source (e.g. event counts).
 7/// </summary>
 8public sealed class SimpleAverageSimilarityEngine : IIntentSimilarityEngine
 9{
 10    /// <inheritdoc />
 11    public double CalculateIntentScore(IReadOnlyCollection<IntentEmbedding> embeddings)
 912        => CalculateIntentScore(embeddings, null);
 13
 14    /// <inheritdoc />
 15    public double CalculateIntentScore(IReadOnlyCollection<IntentEmbedding> embeddings, IReadOnlyDictionary<string, doub
 10316    {
 10317        if (embeddings.Count == 0)
 118            return 0;
 19
 10220        if (sourceWeights == null || sourceWeights.Count == 0)
 2521            return embeddings.Average(e => e.Score);
 22
 9323        var totalWeighted = 0.0;
 9324        var totalWeight = 0.0;
 72325        foreach (var e in embeddings)
 22226        {
 22227            var w = sourceWeights.GetValueOrDefault(e.Source, 1.0);
 22228            totalWeighted += e.Score * w;
 22229            totalWeight += w;
 22230        }
 9331        return totalWeight > 0 ? totalWeighted / totalWeight : embeddings.Average(x => x.Score);
 10332    }
 33}