feat(matching): rank with semantic embeddings and explain matches by evidence

This commit is contained in:
shira committed 2026-10-11 10:39:46 +03:00
1 parent facc1789b1
commit 24b64d698a
215 files changed
+16951 -327

No files matched your search

@@ -3,6 +3,7 @@ package v1
import (
"context"
"errors"
"math"
"github.com/google/uuid"
@@ -18,6 +19,7 @@ import (
type ProfileOperations interface {
GetMyProfile(ctx context.Context, userID uuid.UUID) (profile.View, error)
SaveMyProfile(ctx context.Context, userID uuid.UUID, expectedVersion int64, input domain.CandidateProfileInput) (profile.View, error)
RequestRepositoryChecks(ctx context.Context, userID uuid.UUID) (int, error)
}
// ProfileHandler serves the candidate's own profile operations.
@@ -46,6 +48,39 @@ func (handler *Handler) SaveMyProfile(ctx context.Context, request *api.Candidat
return handler.profile.SaveMyProfile(ctx, request)
}
func (handler *Handler) RequestMyRepositoryChecks(ctx context.Context) (api.RequestMyRepositoryChecksRes, error) {
if handler.profile == nil {
return handler.UnimplementedHandler.RequestMyRepositoryChecks(ctx)
}
return handler.profile.RequestMyRepositoryChecks(ctx)
}
// RequestMyRepositoryChecks schedules new checks of the linked repositories.
func (handler *ProfileHandler) RequestMyRepositoryChecks(ctx context.Context) (api.RequestMyRepositoryChecksRes, error) {
principal, ok := PrincipalFromContext(ctx)
if !ok {
return (*api.RequestMyRepositoryChecksUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
}
scheduled, err := handler.operations.RequestRepositoryChecks(ctx, principal.UserID)
if err != nil {
if limit, ok := errors.AsType[*profile.RepositoryCheckLimitError](err); ok {
return problem.RateLimited(ctx, int32(math.Ceil(limit.RetryAfter.Seconds()))), nil
}
switch {
case errors.Is(err, profile.ErrForbidden), errors.Is(err, profile.ErrEmailNotVerified):
return (*api.RequestMyRepositoryChecksForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
case errors.Is(err, outbound.ErrUserNotFound):
return (*api.RequestMyRepositoryChecksUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
default:
return nil, err
}
}
return &api.ProfileRepositoryCheckRequestHeaders{
CacheControl: api.CacheControlNoStoreNoStore,
Response: api.ProfileRepositoryCheckRequest{Scheduled: int32(scheduled)}, //nolint:gosec // at most ten projects
}, nil
}
func (handler *ProfileHandler) GetMyProfile(ctx context.Context) (api.GetMyProfileRes, error) {
principal, ok := PrincipalFromContext(ctx)
if !ok {
@@ -167,6 +202,7 @@ func candidateProfileInput(request *api.CandidateProfileUpdate) domain.Candidate
for _, item := range request.SoftSkills {
input.SoftSkills = append(input.SoftSkills, domain.ProfileClaimInput[string]{Value: string(item.Skill), Status: domain.ProfileClaimStatus(item.Status)})
}
input.Projects = projectInputs(request.Projects)
if value, ok := request.Terms.Location.Get(); ok {
input.Location = profileStringInput(string(value.Value), value.Status)
}
@@ -277,6 +313,7 @@ func candidateProfileResponse(view profile.View) api.CandidateProfile {
Skill: api.ProfileSoftSkill(item.Value()), Status: api.ProfileItemStatus(item.Status()), Source: profileClaimSourceResponse(item.Source()),
})
}
response.Projects = projectResponses(content, view.RepositoryChecks)
response.Terms = candidateProfileTerms(content)
updatedAt := api.NilTimestamp{}
if saved.UpdatedAt().IsZero() {
@@ -289,6 +326,75 @@ func candidateProfileResponse(view profile.View) api.CandidateProfile {
return response
}
// projectInputs maps the request projects. An absent list keeps the stored
// projects and maps to nil; an empty one clears them.
func projectInputs(items []api.ProfileProjectItemInput) *[]domain.ProfileClaimInput[domain.ProfileProject] {
if items == nil {
return nil
}
projects := make([]domain.ProfileClaimInput[domain.ProfileProject], 0, len(items))
for _, item := range items {
description := ""
if value, ok := item.Description.Get(); ok {
description = string(value)
}
repository := ""
if value, ok := item.RepositoryURL.Get(); ok {
repository = string(value)
}
stack := make([]string, 0, len(item.Stack))
for _, tag := range item.Stack {
stack = append(stack, string(tag))
}
projects = append(projects, domain.ProfileClaimInput[domain.ProfileProject]{
Value: domain.NewProfileProject(string(item.Title), description, stack, repository),
Status: domain.ProfileClaimStatus(item.Status),
})
}
return &projects
}
func projectResponses(content domain.CandidateProfileContent, checks map[string]outbound.RepositoryCheck) []api.ProfileProjectItem {
projects := make([]api.ProfileProjectItem, 0, len(content.Projects()))
for _, item := range content.Projects() {
projects = append(projects, profileProjectResponse(item, checks))
}
return projects
}
// profileProjectResponse maps one project with the state of its repository
// check. A linked repository without a stored check is pending.
func profileProjectResponse(item domain.ProfileClaim[domain.ProfileProject], checks map[string]outbound.RepositoryCheck) api.ProfileProjectItem {
value := item.Value()
description := api.NilProfileProjectDescription{Null: true}
if value.Description != "" {
description.SetTo(api.ProfileProjectDescription(value.Description))
}
stack := make(api.ProfileProjectStack, 0, len(value.StackTags()))
for _, tag := range value.StackTags() {
stack = append(stack, api.StackTag(tag))
}
project := api.ProfileProjectItem{
Title: api.ProfileProjectTitle(value.Title), Description: description, Stack: stack,
RepositoryURL: api.NilProfileRepositoryUrl{Null: true}, RepositoryCheck: api.NilProfileRepositoryCheck{Null: true},
Status: api.ProfileItemStatus(item.Status()), Source: profileClaimSourceResponse(item.Source()),
}
repository, linked := value.Repository()
if !linked {
return project
}
project.RepositoryURL.SetTo(api.ProfileRepositoryUrl(repository.URL()))
check := api.ProfileRepositoryCheck{State: api.ProfileRepositoryCheckStatePending, CheckedAt: api.NilTimestamp{Null: true}}
if stored, ok := checks[repository.Key()]; ok {
check.State = api.ProfileRepositoryCheckState(stored.State)
if !stored.CheckedAt.IsZero() {
check.CheckedAt.SetTo(api.Timestamp(stored.CheckedAt))
}
}
project.RepositoryCheck.SetTo(check)
return project
}
// confirmedCategoriesResponse maps the categories in their stored order. The
// result is never nil, so a profile without categories encodes as an empty list.
func confirmedCategoriesResponse(categories []domain.CandidateAssessmentCategory) []api.ProfileConfirmedCategory {