Make the three CV match weights a per-agent setting, applied when a role is served
cv_skills, cv_experience and cv_career live in agents.weights (30, 25, 30 by default), edited on the Search agents page beside fit and recency. cv_score is worked out at read time in the feed order, the row and the reader, so changing them asks the model for nothing and leaves the judge's input_key alone. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d5df707148
commit
585c332d74
8 files changed
+147
-28
No files matched your search
+54
-14
@@ -119,14 +119,31 @@ _VOTED_SCORE = ("MIN(1.0, s.score * CASE v.vote WHEN -1 THEN 0.5 "
|
||||
#: nothing, so `vote` and `voted_at` are NULL: one query shape either way.
|
||||
_WITH_VOTES = "LEFT JOIN role_votes v ON v.uid = roles.uid AND v.agent_id = ?"
|
||||
|
||||
#: The agent's `judge` readings beside every role, the same way: `j.cv_score`
|
||||
#: is NULL for a role not judged and with no agent.
|
||||
#: The agent's `judge` readings beside every role, the same way: `j.skills`,
|
||||
#: `j.experience` and `j.career` are NULL for a role not judged and with no
|
||||
#: agent.
|
||||
_WITH_JUDGEMENTS = ("LEFT JOIN role_judgements j ON j.uid = roles.uid AND j.agent_id = ? "
|
||||
"AND j.judged_at IS NOT NULL")
|
||||
|
||||
#: The order of Best CV match: the judged roles by `cv_score`, then the rest
|
||||
#: by score, as `roles` orders them.
|
||||
_BY_CV = "j.cv_score IS NULL, j.cv_score DESC, "
|
||||
|
||||
|
||||
def _cv_sql(weights: Weights | None) -> str:
|
||||
"""`cv_score` as SQL for one agent's weights, unrounded (`app.models.cv_score`
|
||||
rounds it): NULL for a role not judged, and for all three weights 0. The
|
||||
numbers are the model's validated, finite floats, so they are written in
|
||||
rather than bound, the select's placeholders being then no concern."""
|
||||
w = weights or Weights()
|
||||
total = w.cv_skills + w.cv_experience + w.cv_career
|
||||
if not total:
|
||||
return "NULL"
|
||||
return (f"(({w.cv_skills!r} * j.skills + {w.cv_experience!r} * j.experience "
|
||||
f"+ {w.cv_career!r} * j.career) / {total!r})")
|
||||
|
||||
|
||||
def _by_cv(expression: str) -> str:
|
||||
"""The order of Best CV match: the judged roles by `cv_score` (its SQL
|
||||
`expression`), then the rest by score, as `roles` orders them."""
|
||||
return f"{expression} IS NULL, {expression} DESC, "
|
||||
|
||||
#: How many days after today the feed's Closing soon filter reaches.
|
||||
CLOSING_DAYS = 4
|
||||
@@ -880,7 +897,8 @@ class Store:
|
||||
def role(self, uid: str, agent_id: int | None = None) -> ScoredRole | None:
|
||||
"""One role with its tags, and with `vote`, `voted_at`, `score`,
|
||||
`gated_reason` and `prompt` as `agent_id` judged and scored it, and
|
||||
its `judgement`, `cv_score` and language flag for that agent; None
|
||||
its `judgement`, `cv_score` (under the agent's weights as they are
|
||||
now) and language flag for that agent; None
|
||||
(unjudged, unscored) without an agent. The score is moved by the vote
|
||||
as `roles` serves it."""
|
||||
row = self._row(
|
||||
@@ -1122,7 +1140,8 @@ class Store:
|
||||
|
||||
With `by_cv` as well, the roles the agent's `judge` read come first
|
||||
by `cv_score`, then the others by score (Best CV match). Every row
|
||||
carries the agent's `cv_score` (None when not judged) and the
|
||||
carries the agent's `cv_score` (None when not judged), computed
|
||||
from the three numbers under the agent's weights at read time, and the
|
||||
language flag of its languages against the agent's
|
||||
(`language_flag`). `closing` keeps the roles whose `deadline` falls
|
||||
today or in the next `CLOSING_DAYS` days.
|
||||
@@ -1138,12 +1157,14 @@ class Store:
|
||||
judged=judged, pay=pay, company_keys=company_keys, places=places,
|
||||
seniority=seniority, seniority_unknown=seniority_unknown, pay_unknown=pay_unknown,
|
||||
closing=closing)
|
||||
select = "SELECT roles.*, v.vote, v.voted_at, j.cv_score"
|
||||
weights = self._weights_of(agent)
|
||||
cv = _cv_sql(weights)
|
||||
select = f"SELECT roles.*, v.vote, v.voted_at, {cv} AS cv_score"
|
||||
order = "roles.posted_at DESC, roles.uid"
|
||||
scored = agent is not None and by_score
|
||||
if scored:
|
||||
select += f", {_VOTED_SCORE} AS score, s.gated_reason, s.prompt"
|
||||
order = (_BY_CV if by_cv else "") + "score DESC, " + order
|
||||
order = (_by_cv(cv) if by_cv else "") + "score DESC, " + order
|
||||
elif open_only:
|
||||
# Newest first, open only: idx_roles_posted covers this exactly
|
||||
# (posted_at DESC, uid, WHERE closed_at IS NULL), so it earns the
|
||||
@@ -1162,8 +1183,15 @@ class Store:
|
||||
r.tags = by_uid.get(r.uid, [])
|
||||
r.remote_where = areas.get(r.uid, "")
|
||||
r.lang_flag, r.lang_note = language_flag(r.languages_required, mine)
|
||||
if r.cv_score is not None:
|
||||
r.cv_score = round(r.cv_score, 1)
|
||||
return found
|
||||
|
||||
def _weights_of(self, agent_id: int | None) -> Weights | None:
|
||||
"""The agent's weights, None with no agent."""
|
||||
found = self.agent(agent_id) if agent_id is not None else None
|
||||
return found.weights if found else None
|
||||
|
||||
def _languages_of(self, agent_id: int | None) -> list[CvLanguage]:
|
||||
"""The languages the agent's CV states, [] with no agent."""
|
||||
found = self.agent(agent_id) if agent_id is not None else None
|
||||
@@ -1201,18 +1229,19 @@ class Store:
|
||||
judged=judged, pay=pay, company_keys=company_keys, places=places,
|
||||
seniority=seniority, seniority_unknown=seniority_unknown, pay_unknown=pay_unknown,
|
||||
closing=closing)
|
||||
cv = _cv_sql(self._weights_of(agent))
|
||||
select = (
|
||||
"SELECT roles.uid, roles.company_key, roles.company, roles.title, roles.place, "
|
||||
"roles.country, roles.remote, roles.function, roles.seniority, roles.salary_min, "
|
||||
"roles.salary_max, roles.currency, roles.salary_text, roles.original_url, "
|
||||
"roles.posting_url, roles.posted_at, roles.read_at, roles.deadline, "
|
||||
"roles.languages_required, v.vote, v.voted_at, j.cv_score, "
|
||||
f"roles.languages_required, v.vote, v.voted_at, {cv} AS cv_score, "
|
||||
f"SUBSTR({_EXCERPT_SOURCE}, 1, {_EXCERPT_RAW}) AS excerpt")
|
||||
order = "roles.posted_at DESC, roles.uid"
|
||||
scored = agent is not None and by_score
|
||||
if scored:
|
||||
select += f", {_VOTED_SCORE} AS score, s.gated_reason, s.prompt"
|
||||
order = (_BY_CV if by_cv else "") + "score DESC, " + order
|
||||
order = (_by_cv(cv) if by_cv else "") + "score DESC, " + order
|
||||
elif open_only:
|
||||
# Same reasoning as `roles`: the planner otherwise sorts every
|
||||
# open role before applying LIMIT.
|
||||
@@ -1224,6 +1253,8 @@ class Store:
|
||||
for r in rows:
|
||||
row = dict(r)
|
||||
row["excerpt"] = excerpt(row["excerpt"])
|
||||
if row["cv_score"] is not None:
|
||||
row["cv_score"] = round(row["cv_score"], 1)
|
||||
row["lang_flag"], row["lang_note"] = language_flag(
|
||||
role_languages(row.pop("languages_required")), mine)
|
||||
found.append(RoleRow.from_row(row))
|
||||
@@ -1859,7 +1890,8 @@ class Store:
|
||||
experience: int, career: int, strengths: Sequence[str],
|
||||
gaps: Sequence[str]) -> bool:
|
||||
"""Store `judge`'s reading of one role for one agent, replacing the
|
||||
one before, with `cv_score` (`app.models.cv_score`) and its tries
|
||||
one before, with `cv_score` (`app.models.cv_score`, at the default weights: the
|
||||
table's column is not read, see `judgement`) and its tries
|
||||
back at 0. False for an unknown role or agent."""
|
||||
try:
|
||||
with self.transaction() as conn:
|
||||
@@ -1901,12 +1933,20 @@ class Store:
|
||||
return int(crossed)
|
||||
|
||||
def judgement(self, agent_id: int | None, uid: str) -> Judgement | None:
|
||||
"""The agent's judgement of one role, None when it has none."""
|
||||
"""The agent's judgement of one role, None when it has none, its
|
||||
`cv_score` the three numbers under the agent's weights as they are
|
||||
now, not as stored."""
|
||||
if agent_id is None:
|
||||
return None
|
||||
row = self._row("SELECT * FROM role_judgements WHERE agent_id = ? AND uid = ? "
|
||||
"AND judged_at IS NOT NULL", (agent_id, uid))
|
||||
return Judgement.from_row(row) if row else None
|
||||
if row is None:
|
||||
return None
|
||||
found = Judgement.from_row(row)
|
||||
agent = self.agent(agent_id)
|
||||
found.cv_score = cv_score(found.skills, found.experience, found.career,
|
||||
agent.weights if agent else None)
|
||||
return found
|
||||
|
||||
def set_article_text(self, uid: str, text: str) -> Role | None:
|
||||
"""Store the posting page as plain text and stamp `article_at`. The
|
||||
|
||||
Reference in new issue
Block a user