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.
This commit is contained in:
Rafał Tyński
2026-10-04 02:44:03 +02:00
parent 2bc083fb95
commit 25ce901021
13 changed files with 611 additions and 2 deletions
@@ -0,0 +1,30 @@
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));
}
}