Files
Hy2026/backend/Application/Matchmaking/VectorMath.cs
T
Rafał Tyński 25ce901021 feat(backend): add semantic matchmaking with embedding pipeline
Add a pluggable embedding provider with an offline deterministic default, vector indexing for problems and innovations, cosine semantic ranking, similar cases and solution suggestions, area filtering and an admin reindex endpoint. Refresh the index when innovations or submissions change.
2026-10-04 02:44:03 +02:00

31 lines
720 B
C#

namespace TarninaHub.Application.Matchmaking;
public static class VectorMath
{
public static double CosineSimilarity(IReadOnlyList<float> a, IReadOnlyList<float> b)
{
if (a.Count == 0 || a.Count != b.Count)
{
return 0;
}
double dot = 0;
double magnitudeA = 0;
double magnitudeB = 0;
for (var i = 0; i < a.Count; i++)
{
dot += (double)a[i] * b[i];
magnitudeA += (double)a[i] * a[i];
magnitudeB += (double)b[i] * b[i];
}
if (magnitudeA <= 0 || magnitudeB <= 0)
{
return 0;
}
return dot / (Math.Sqrt(magnitudeA) * Math.Sqrt(magnitudeB));
}
}