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:
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user