TS TypeSafe 文档中文版 原文 ↗

组合评分

把一个复杂的判断拆成若干原子评分,再用你在代码中掌控的权重把它们组合起来。

我们常常希望同时基于多个标准来给一组条目排序。组合评分是一种便于思考的做法:把判断拆成相互独立的维度,分别给每个维度评分,再用你在代码中掌控的权重把它们组合起来。

示例:简历筛选

设想你正在处理工程岗位的简历。你希望基于多个标准给候选人排序,并最终选出排名前 X 的候选人进入下一轮评审。

%%{init: {"fontFamily": "Inter, sans-serif", "flowchart": {"rankSpacing": 35, "wrappingWidth": 300, "subGraphTitleMargin": {"top": 12, "bottom": 36}}}}%% flowchart LR resume["候选人简历"] subgraph req["TypeSafe 并行<br/>评估各个问题"] direction TB py["<b>Score:</b> Python 深度"] lead["<b>Score:</b> 团队领导力"] arch["<b>Score:</b> 系统设计"] general["<b>Score:</b> 通才程度"] %% Invisible links stack the questions; they are answered in parallel. py ~~~ lead ~~~ arch ~~~ general end resume -- "一次请求<br/>简历 + 4 个问题" --> req req -- "一次响应<br/>4 个评分答案" --> normalize["<b>把评分归一化到 0–1</b><br/>在你的代码中每项除以 4"] normalize --> ic["<b>资深个人贡献者权重</b><br/>40% Python + 10% 领导力<br/>40% 设计 + 10% 通才"] normalize --> em["<b>工程经理权重</b><br/>15% Python + 40% 领导力<br/>20% 设计 + 25% 通才"] ic --> rank["给候选人排序<br/>针对每个角色"] em --> rank

第 1 步:独立地给每个维度评分

questions
{
  "questions": {
    "python_depth": {
      "type": "score",
      "instructions": "How much depth of python experience does this candidate have, based on the supplied resume?",
      "criteria": [
        "No Python experience mentioned",
        "Mentioned but no detail",
        "Used in projects, some specifics",
        "Primary language, multiple projects",
        "Deep expertise: architecture, performance, libraries"
      ]
    },
    "team_leadership": {
      "type": "score",
      "instructions": "How much experience does this candidate have managing or leading engineering teams?",
      "criteria": [
        "No management experience mentioned",
        "Informal mentorship or tech lead role",
        "Led a small team or project",
        "Managed a team with direct reports",
        "Managed multiple teams or an engineering org"
      ]
    },
    "system_design": {
      "type": "score",
      "instructions": "How much experience does this candidate have designing large-scale or distributed systems?",
      "criteria": [
        "No architecture work mentioned",
        "Contributed to design discussions",
        "Designed components of a larger system",
        "Owned architecture of a significant system",
        "Designed systems at scale across multiple domains"
      ]
    },
    "generalist": {
      "type": "score",
      "instructions": "How much evidence is there that this candidate picks up unfamiliar tools, roles, or domains outside their core specialty?",
      "criteria": [
        "Only one domain or role mentioned",
        "Some variety but within a narrow field",
        "Worked across a few different areas or tech stacks",
        "Regularly moved between domains, wore many hats",
        "Track record of ramping up in unfamiliar areas and delivering"
      ]
    }
  }
}

这个示例是可交互的;到官网原页面可以直接在 Playground 里运行。

第 2 步:用权重组合

每个维度都会被归一化到 0–1 并赋予权重。权重让你可以方便地调整每个维度的相对重要性,同时不会丢失任何单项评分中的细微差别。

scoring.py
py      = response.answers["python_depth"].score / 4
lead    = response.answers["team_leadership"].score / 4
arch    = response.answers["system_design"].score / 4
general = response.answers["generalist"].score / 4
 
# Senior IC
ic_score = (0.40 * py) + (0.10 * lead) + (0.40 * arch) + (0.10 * general)
 
# Engineering Manager
em_score = (0.15 * py) + (0.40 * lead) + (0.20 * arch) + (0.25 * general)
 

这样你就能基于组合评分给候选人排序。但更重要的是,它让你能看清最终评分究竟是如何计算出来的。如果排名最高的候选人并不符合你的预期,你可以调整权重来找到合适的平衡点。