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
@@ -185,6 +185,34 @@ type matchingPolicyDocument struct {
|
||||
PercentileMinCohort *int32 `json:"percentile_min_cohort"`
|
||||
MaxResultsPerGroup *int32 `json:"max_results_per_group"`
|
||||
SkillTaxonomy *[]matchingSkillGroupDocument `json:"skill_taxonomy"`
|
||||
// Semantics is optional: a document without it is a matching section
|
||||
// that ranks with the neutral Sem.
|
||||
Semantics *matchingSemanticsDocument `json:"semantics,omitempty"`
|
||||
}
|
||||
|
||||
type matchingSemanticsDocument struct {
|
||||
Members *[]matchingSemanticMemberDocument `json:"members"`
|
||||
Calibration *[]matchingCalibrationPointDocument `json:"calibration"`
|
||||
SkillMediumBP *BasisPoints `json:"skill_medium_bp"`
|
||||
SkillHighBP *BasisPoints `json:"skill_high_bp"`
|
||||
TaskMediumBP *BasisPoints `json:"task_medium_bp"`
|
||||
TaskHighBP *BasisPoints `json:"task_high_bp"`
|
||||
MaxEvidencePerEntry *int32 `json:"max_evidence_per_entry"`
|
||||
Source *string `json:"source"`
|
||||
}
|
||||
|
||||
type matchingSemanticMemberDocument struct {
|
||||
ModelID *string `json:"model_id"`
|
||||
ModelRevision *string `json:"model_revision"`
|
||||
PromptVersion *string `json:"prompt_version"`
|
||||
WeightBP *BasisPoints `json:"weight_bp"`
|
||||
MeanBP *int32 `json:"mean_bp"`
|
||||
StandardDeviationBP *int32 `json:"standard_deviation_bp"`
|
||||
}
|
||||
|
||||
type matchingCalibrationPointDocument struct {
|
||||
ScoreBP *int32 `json:"score_bp"`
|
||||
ProbabilityBP *BasisPoints `json:"probability_bp"`
|
||||
}
|
||||
|
||||
type matchingSkillGroupDocument struct {
|
||||
@@ -359,6 +387,31 @@ func encodeMatchingPolicy(policy *MatchingPolicy) *matchingPolicyDocument {
|
||||
PercentileMinCohort: pointer(policy.PercentileMinCohort),
|
||||
MaxResultsPerGroup: pointer(policy.MaxResultsPerGroup),
|
||||
SkillTaxonomy: pointer(encodeMatchingSkillGroups(policy.SkillTaxonomy)),
|
||||
Semantics: encodeMatchingSemantics(policy.Semantics),
|
||||
}
|
||||
}
|
||||
|
||||
func encodeMatchingSemantics(policy *MatchingSemanticsPolicy) *matchingSemanticsDocument {
|
||||
if policy == nil {
|
||||
return nil
|
||||
}
|
||||
points := make([]matchingCalibrationPointDocument, 0, len(policy.Calibration))
|
||||
for _, point := range policy.Calibration {
|
||||
points = append(points, matchingCalibrationPointDocument{ScoreBP: pointer(point.Score), ProbabilityBP: pointer(point.Probability)})
|
||||
}
|
||||
members := make([]matchingSemanticMemberDocument, 0, len(policy.Members))
|
||||
for _, member := range policy.Members {
|
||||
members = append(members, matchingSemanticMemberDocument{
|
||||
ModelID: pointer(member.Model.ID), ModelRevision: pointer(member.Model.Revision),
|
||||
PromptVersion: pointer(member.Model.PromptVersion), WeightBP: pointer(member.Weight),
|
||||
MeanBP: pointer(member.Mean), StandardDeviationBP: pointer(member.StandardDeviation),
|
||||
})
|
||||
}
|
||||
return &matchingSemanticsDocument{
|
||||
Members: pointer(members), Calibration: pointer(points),
|
||||
SkillMediumBP: pointer(policy.SkillMedium), SkillHighBP: pointer(policy.SkillHigh),
|
||||
TaskMediumBP: pointer(policy.TaskMedium), TaskHighBP: pointer(policy.TaskHigh),
|
||||
MaxEvidencePerEntry: pointer(policy.MaxEvidencePerEntry), Source: pointer(policy.Source),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -621,6 +674,43 @@ func decodeOptionalMatchingPolicy(reader *documentReader, document *matchingPoli
|
||||
PercentileMinCohort: require(reader, "matching.percentile_min_cohort", document.PercentileMinCohort),
|
||||
MaxResultsPerGroup: require(reader, "matching.max_results_per_group", document.MaxResultsPerGroup),
|
||||
SkillTaxonomy: taxonomy,
|
||||
Semantics: decodeOptionalMatchingSemantics(reader, document.Semantics),
|
||||
}
|
||||
}
|
||||
|
||||
func decodeOptionalMatchingSemantics(reader *documentReader, document *matchingSemanticsDocument) *MatchingSemanticsPolicy {
|
||||
if document == nil {
|
||||
return nil
|
||||
}
|
||||
points := make([]MatchingCalibrationPoint, 0)
|
||||
for _, point := range require(reader, "matching.semantics.calibration", document.Calibration) {
|
||||
points = append(points, MatchingCalibrationPoint{
|
||||
Score: require(reader, "matching.semantics.calibration.score_bp", point.ScoreBP),
|
||||
Probability: require(reader, "matching.semantics.calibration.probability_bp", point.ProbabilityBP),
|
||||
})
|
||||
}
|
||||
members := make([]MatchingSemanticMember, 0)
|
||||
for _, member := range require(reader, "matching.semantics.members", document.Members) {
|
||||
members = append(members, MatchingSemanticMember{
|
||||
Model: SemanticModel{
|
||||
ID: require(reader, "matching.semantics.members.model_id", member.ModelID),
|
||||
Revision: require(reader, "matching.semantics.members.model_revision", member.ModelRevision),
|
||||
PromptVersion: require(reader, "matching.semantics.members.prompt_version", member.PromptVersion),
|
||||
},
|
||||
Weight: require(reader, "matching.semantics.members.weight_bp", member.WeightBP),
|
||||
Mean: require(reader, "matching.semantics.members.mean_bp", member.MeanBP),
|
||||
StandardDeviation: require(reader, "matching.semantics.members.standard_deviation_bp", member.StandardDeviationBP),
|
||||
})
|
||||
}
|
||||
return &MatchingSemanticsPolicy{
|
||||
Members: members,
|
||||
Calibration: points,
|
||||
SkillMedium: require(reader, "matching.semantics.skill_medium_bp", document.SkillMediumBP),
|
||||
SkillHigh: require(reader, "matching.semantics.skill_high_bp", document.SkillHighBP),
|
||||
TaskMedium: require(reader, "matching.semantics.task_medium_bp", document.TaskMediumBP),
|
||||
TaskHigh: require(reader, "matching.semantics.task_high_bp", document.TaskHighBP),
|
||||
MaxEvidencePerEntry: require(reader, "matching.semantics.max_evidence_per_entry", document.MaxEvidencePerEntry),
|
||||
Source: require(reader, "matching.semantics.source", document.Source),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user