feat(matching): rank with semantic embeddings and explain matches by evidence
This commit is contained in:
1 parent
facc1789b1
commit
24b64d698a
215 files changed
+16951
-327
No files matched your search
@@ -153,11 +153,15 @@ func (service *Service) searchOnce(ctx context.Context, request Request) (Result
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ranked, err := service.rank(ctx, unit, request, basis, policy, cards)
|
||||
semantics, err := loadNeedSemantics(ctx, unit, policy, basis)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err = service.reveal(ctx, unit, request, policy, ranked)
|
||||
ranked, err := service.rank(ctx, unit, request, basis, policy, semantics, cards)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err = service.reveal(ctx, unit, request, policy, semantics, ranked)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
@@ -182,6 +186,9 @@ func (service *Service) matchingPolicy(ctx context.Context, unit outbound.UnitOf
|
||||
// searchBasis is what a need snapshot contributes to the search. A bank search
|
||||
// has an empty basis.
|
||||
type searchBasis struct {
|
||||
// need is the requirements snapshot of a need search; nil for a bank
|
||||
// search.
|
||||
need *domain.NeedSnapshot
|
||||
specialization *domain.SpecializationCode
|
||||
skills []requestedSkill
|
||||
requestedFormats []domain.QuestionnaireWorkFormat
|
||||
@@ -205,7 +212,9 @@ func loadBasis(ctx context.Context, unit outbound.UnitOfWork, request Request) (
|
||||
if need.RequirementsVersion() != request.Need.RequirementsVersion {
|
||||
return searchBasis{}, ErrNeedNotFound
|
||||
}
|
||||
requirements := need.Snapshot().Requirements
|
||||
snapshot := need.Snapshot()
|
||||
basis.need = &snapshot
|
||||
requirements := snapshot.Requirements
|
||||
if requirements.Specialization.Status == domain.NeedValueConfirmed && requirements.Specialization.Value != nil {
|
||||
specialization := *requirements.Specialization.Value
|
||||
basis.specialization = &specialization
|
||||
@@ -315,10 +324,13 @@ func entriesOf(visible domain.VisibleCandidateCard) []candidateEntry {
|
||||
type rankedEntry struct {
|
||||
entry Entry
|
||||
candidate uuid.UUID
|
||||
fit int64
|
||||
coverage int64
|
||||
rank int64
|
||||
near bool
|
||||
// card is the card as this organization reads it; the semantic
|
||||
// explanation names only what it shows.
|
||||
card domain.AnonymousCandidateViewDTO
|
||||
fit int64
|
||||
coverage int64
|
||||
rank int64
|
||||
near bool
|
||||
}
|
||||
|
||||
// groups holds the ranked entries of the three groups before the output is cut.
|
||||
@@ -332,6 +344,7 @@ func (service *Service) rank(
|
||||
request Request,
|
||||
basis searchBasis,
|
||||
policy domain.MatchingPolicy,
|
||||
semantics needSemantics,
|
||||
cards []domain.VisibleCandidateCard,
|
||||
) (groups, error) {
|
||||
specialization, compatible := effectiveSpecialization(request.Filters.Specialization, basis.specialization)
|
||||
@@ -358,9 +371,17 @@ func (service *Service) rank(
|
||||
if err != nil {
|
||||
return groups{}, err
|
||||
}
|
||||
semanticValues, err := candidateSemantics(ctx, unit, semantics, accepted)
|
||||
if err != nil {
|
||||
return groups{}, err
|
||||
}
|
||||
var result groups
|
||||
for _, entry := range accepted {
|
||||
ranked := scoreEntry(entry, policy, basis, requestedFormats, facts[entry.candidateID], reachedCohorts)
|
||||
var semantic *int64
|
||||
if value, known := semanticValues[entry.candidateID]; known {
|
||||
semantic = &value
|
||||
}
|
||||
ranked := scoreEntry(entry, policy, basis, requestedFormats, facts[entry.candidateID], reachedCohorts, semantic)
|
||||
switch {
|
||||
case entry.category == nil:
|
||||
result.unconfirmed = append(result.unconfirmed, ranked)
|
||||
@@ -460,15 +481,15 @@ func (service *Service) reveal(
|
||||
unit outbound.UnitOfWork,
|
||||
request Request,
|
||||
policy domain.MatchingPolicy,
|
||||
semantics needSemantics,
|
||||
ranked groups,
|
||||
) (Result, error) {
|
||||
result := Result{Source: sourceOf(request), Main: []Entry{}, Near: []Entry{}, Unconfirmed: []Entry{}}
|
||||
limit := int(policy.MaxResultsPerGroup)
|
||||
for _, group := range []*[]rankedEntry{&ranked.main, &ranked.near, &ranked.unconfirmed} {
|
||||
if len(*group) > limit {
|
||||
*group = (*group)[:limit]
|
||||
result.Truncated = true
|
||||
}
|
||||
result.Truncated = cutGroups(&ranked, int(policy.MaxResultsPerGroup))
|
||||
// The explanation is part of what is revealed and charged, so it is
|
||||
// attached before the charge records the fields.
|
||||
if err := attachSemanticEvidence(ctx, unit, semantics, ranked); err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
views, err := service.views(ctx, unit, request.ActorID, request.OrganizationID)
|
||||
if err != nil {
|
||||
@@ -522,6 +543,18 @@ func (service *Service) reveal(
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// cutGroups cuts each group to the limit and reports whether one was longer.
|
||||
func cutGroups(ranked *groups, limit int) bool {
|
||||
truncated := false
|
||||
for _, group := range []*[]rankedEntry{&ranked.main, &ranked.near, &ranked.unconfirmed} {
|
||||
if len(*group) > limit {
|
||||
*group = (*group)[:limit]
|
||||
truncated = true
|
||||
}
|
||||
}
|
||||
return truncated
|
||||
}
|
||||
|
||||
// entryFields lists the card fields that an entry actually shows, so the
|
||||
// candidate's history names what the search returned about them.
|
||||
func entryFields(entry Entry) []domain.CardField {
|
||||
@@ -545,6 +578,12 @@ func entryFields(entry Entry) []domain.CardField {
|
||||
if entry.PublicContext.SalaryCompatibility != nil {
|
||||
fields = append(fields, domain.CardFieldSalaryCompatibility)
|
||||
}
|
||||
for _, evidence := range entry.SemanticEvidence {
|
||||
if evidence.ProjectTitle != nil {
|
||||
fields = append(fields, domain.CardFieldProjects)
|
||||
break
|
||||
}
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -553,6 +592,7 @@ func orderedFields(set map[domain.CardField]struct{}) []domain.CardField {
|
||||
for _, field := range []domain.CardField{
|
||||
domain.CardFieldCategories, domain.CardFieldStack, domain.CardFieldExperience,
|
||||
domain.CardFieldSelfAssessment, domain.CardFieldWorkFormats, domain.CardFieldSalaryCompatibility,
|
||||
domain.CardFieldProjects,
|
||||
} {
|
||||
if _, shown := set[field]; shown {
|
||||
fields = append(fields, field)
|
||||
@@ -595,6 +635,7 @@ func scoreEntry(
|
||||
requestedFormats []domain.QuestionnaireWorkFormat,
|
||||
facts []evidenceSource,
|
||||
reachedCohorts map[outbound.CategoryKey]bool,
|
||||
semantic *int64,
|
||||
) rankedEntry {
|
||||
evidence := make([]evidenceSource, 0, len(entry.card.Skills)+len(facts))
|
||||
for _, skill := range entry.card.Skills {
|
||||
@@ -609,7 +650,7 @@ func scoreEntry(
|
||||
}
|
||||
}
|
||||
}
|
||||
computed := computeScores(scoreInput{confirmed: confirmed, policy: policy, skills: basis.skills, evidence: evidence})
|
||||
computed := computeScores(scoreInput{confirmed: confirmed, policy: policy, skills: basis.skills, evidence: evidence, semantics: semantic})
|
||||
context := PublicContext{
|
||||
ExperienceBand: entry.card.ExperienceBand, SalaryCompatibility: entry.card.SalaryCompatibility,
|
||||
}
|
||||
@@ -622,7 +663,7 @@ func scoreEntry(
|
||||
summary, flags := explain(explanationInput{
|
||||
confirmed: confirmed, declaredGrade: entry.declaredGrade, policy: policy, scores: computed, context: context,
|
||||
requestedFormats: requestedFormats, needDomainConfirmed: basis.needDomainConfirmed,
|
||||
percentileReason: percentileReason(entry, reachedCohorts),
|
||||
percentileReason: percentileReason(entry, reachedCohorts), semanticsKnown: semantic != nil,
|
||||
})
|
||||
components := Components{Fit: microToFloat(computed.fit), Coverage: microToFloat(computed.coverage)}
|
||||
if confirmed {
|
||||
@@ -639,7 +680,7 @@ func scoreEntry(
|
||||
DeclaredGrade: entry.declaredGrade, Category: entry.category,
|
||||
PublicContext: context, EvidenceSummary: summary, Components: components, UnknownFlags: flags,
|
||||
},
|
||||
candidate: entry.candidateID, fit: computed.fit, coverage: computed.coverage, rank: computed.rank,
|
||||
candidate: entry.candidateID, card: entry.card, fit: computed.fit, coverage: computed.coverage, rank: computed.rank,
|
||||
near: confirmed && computed.belongsToNearGroup(policy),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user