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,20 @@
|
||||
namespace TarninaHub.Application.Matchmaking;
|
||||
|
||||
public sealed record RankedItem<T>(T Item, double Score);
|
||||
|
||||
public static class SemanticRanker
|
||||
{
|
||||
public static IReadOnlyList<RankedItem<T>> Rank<T>(
|
||||
IReadOnlyList<float> queryVector,
|
||||
IEnumerable<(T Item, IReadOnlyList<float> Vector)> candidates,
|
||||
int topK,
|
||||
double minScore = 0)
|
||||
{
|
||||
return candidates
|
||||
.Select(candidate => new RankedItem<T>(candidate.Item, VectorMath.CosineSimilarity(queryVector, candidate.Vector)))
|
||||
.Where(ranked => ranked.Score >= minScore)
|
||||
.OrderByDescending(ranked => ranked.Score)
|
||||
.Take(topK)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user