Score each role's closeness to the agent's CV, let the judge also read the 50 closest the score leaves out, and order CV match's unjudged roles by it
The CV is cut into chunks inside e5's window, embedded like a prompt and cached per agent under a hash of the model, chunking and text. A role's cv_fit (scores.cv_fit, migration 31) is its best chunk cosine, scaled with its own calibration band: fit's clipped 88 of agent 2's ungated roles to 1. It is no term of the Agent match score. judge_cv_top (default 50) sits beside judge_top and judge_min on the agents page and card. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b481cb5692
commit
c23594507a
23 files changed
+603
-85
No files matched your search
+25
-9
@@ -72,8 +72,9 @@ class JudgeConfig(ModelTaskConfig):
|
||||
"""Each search agent's best roles read against its CV, as three numbers
|
||||
and a total. See app/jobs/judge.py. Off by default like extract; on, a
|
||||
pull judges the best of each enabled agent with a CV, as deep and as low
|
||||
as that agent's own `limits` say (`judge_top`, `judge_min`), and only
|
||||
the roles whose judgement is missing or was read from another CV or
|
||||
as that agent's own `limits` say (`judge_top`, `judge_min`), and the
|
||||
`judge_cv_top` ungated ones closest to its CV that those leave out, and
|
||||
only the roles whose judgement is missing or was read from another CV or
|
||||
text."""
|
||||
|
||||
enabled: bool = False
|
||||
@@ -103,21 +104,30 @@ class EnrichConfig(Section):
|
||||
|
||||
|
||||
class Calibration(Section):
|
||||
"""Where one embedding model's cosines sit, as `(lo, hi)` for fit and for
|
||||
taste: `score.scale` maps `lo` to 0 and `hi` to 1 and clips outside, so a
|
||||
term is a level rather than a rank within the run."""
|
||||
"""Where one embedding model's cosines sit, as `(lo, hi)` for fit, for
|
||||
taste and for a role's closeness to a CV (`cv`, fit's when not given):
|
||||
`score.scale` maps `lo` to 0 and `hi` to 1 and clips outside, so a term
|
||||
is a level rather than a rank within the run."""
|
||||
|
||||
fit: tuple[float, float]
|
||||
taste: tuple[float, float]
|
||||
cv: tuple[float, float] | None = None
|
||||
|
||||
@field_validator("fit", "taste")
|
||||
@field_validator("fit", "taste", "cv")
|
||||
@classmethod
|
||||
def _lo_below_hi(cls, band: tuple[float, float]) -> tuple[float, float]:
|
||||
def _lo_below_hi(cls, band: tuple[float, float] | None) -> tuple[float, float] | None:
|
||||
if band is None:
|
||||
return band
|
||||
lo, hi = band
|
||||
if not -1 <= lo < hi <= 1:
|
||||
raise ValueError(f"needs -1 <= lo < hi <= 1, got [{lo}, {hi}]")
|
||||
return band
|
||||
|
||||
@property
|
||||
def cv_band(self) -> tuple[float, float]:
|
||||
"""The band `cv_fit` is scaled with: `cv`, else fit's."""
|
||||
return self.cv or self.fit
|
||||
|
||||
|
||||
#: The built-in calibration, by embedding model. Measured on a copy of the
|
||||
#: live database, 16,841 open roles (see docs/decisions.md). fit: pooled over
|
||||
@@ -125,9 +135,15 @@ class Calibration(Section):
|
||||
#: every single intent's p99.9, so only about 5 of the starter agent's 4,156
|
||||
#: ungated roles clip to 1. taste: from synthetic votes, 30 liked and 30
|
||||
#: passed roles for each of three intents, since the copy had none (pooled p1
|
||||
#: -0.140, p99.9 0.192); re-measure it once real votes exist.
|
||||
#: -0.140, p99.9 0.192); re-measure it once real votes exist. cv: the best
|
||||
#: cosine over the chunks of the one CV in the copy of 2026-10-03, over that
|
||||
#: agent's 7,270 ungated roles: p1 0.770, median 0.832, p99.9 0.891, max
|
||||
#: 0.902. A CV chunk is a longer text than a prompt and sits closer to every
|
||||
#: posting, so fit's band clipped 88 of them to 1 and the 50 closest tied;
|
||||
#: with this one, 1 clips. Re-measure it once more agents hold a CV.
|
||||
CALIBRATION: dict[str, Calibration] = {
|
||||
"intfloat/multilingual-e5-small": Calibration(fit=(0.75, 0.88), taste=(-0.14, 0.19)),
|
||||
"intfloat/multilingual-e5-small": Calibration(fit=(0.75, 0.88), taste=(-0.14, 0.19),
|
||||
cv=(0.77, 0.90)),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -77,6 +77,62 @@ def intent_text(model: str, intent: str) -> str:
|
||||
return f"query: {intent}" if wants_e5_prefix(model) else intent
|
||||
|
||||
|
||||
#: The most of a CV one vector reads. multilingual-e5-small reads 512 tokens
|
||||
#: and cuts the rest; on the owner's English CV a paragraph runs about four
|
||||
#: characters a token (1,896 characters were 471 tokens with "query: "), so
|
||||
#: 1,200 characters stay inside the window with room for a denser language.
|
||||
CV_CHUNK_CHARS = 1200
|
||||
|
||||
#: The version of `cv_chunks`, part of the CV vectors' cache key
|
||||
#: (`score.cv_key`): a change to how a CV is cut embeds every CV again.
|
||||
CV_CHUNKING = 1
|
||||
|
||||
#: Where a long paragraph is cut, coarsest first, and what joins its pieces
|
||||
#: again: lines, then sentences.
|
||||
_CUTS = ((re.compile(r"\n+"), "\n"), (re.compile(r"(?<=[.!?;])\s+"), " "))
|
||||
|
||||
|
||||
def _pieces(text: str, limit: int) -> list[str]:
|
||||
"""`text` cut to pieces of at most `limit` characters: by line, then by
|
||||
sentence, then at the last space before the limit, else at the limit."""
|
||||
if len(text) <= limit:
|
||||
return [text]
|
||||
for pattern, glue in _CUTS:
|
||||
parts = [p.strip() for p in pattern.split(text) if p.strip()]
|
||||
if len(parts) > 1:
|
||||
return _merge([piece for part in parts for piece in _pieces(part, limit)],
|
||||
limit, glue)
|
||||
cut = text.rfind(" ", 0, limit + 1)
|
||||
cut = cut if cut > 0 else limit
|
||||
return [text[:cut].strip(), *_pieces(text[cut:].strip(), limit)]
|
||||
|
||||
|
||||
def _merge(pieces: list[str], limit: int, glue: str) -> list[str]:
|
||||
"""Neighbouring pieces joined with `glue` while the join fits `limit`."""
|
||||
merged: list[str] = []
|
||||
for piece in pieces:
|
||||
if merged and len(merged[-1]) + len(glue) + len(piece) <= limit:
|
||||
merged[-1] += glue + piece
|
||||
else:
|
||||
merged.append(piece)
|
||||
return merged
|
||||
|
||||
|
||||
def cv_chunks(cv_text: str, limit: int | None = None) -> list[str]:
|
||||
"""A CV as the texts its vectors are made from: its paragraphs (blank
|
||||
lines apart), a longer one cut by line, then by sentence, and neighbours
|
||||
joined again while they fit `limit` (`CV_CHUNK_CHARS`), so a heading
|
||||
travels with what follows it and no chunk runs past what the model
|
||||
reads."""
|
||||
limit = limit or CV_CHUNK_CHARS
|
||||
pieces = []
|
||||
for paragraph in re.split(r"\n\s*\n", cv_text):
|
||||
lines = "\n".join(" ".join(line.split()) for line in paragraph.splitlines()).strip()
|
||||
if lines:
|
||||
pieces += _pieces(lines, limit)
|
||||
return _merge(pieces, limit, "\n\n")
|
||||
|
||||
|
||||
def load_embedder(model: str) -> embedding.Embedder:
|
||||
"""The encoder. A seam of its own so a test hands in a fake and nothing
|
||||
downloads a model; `score` loads through it too."""
|
||||
|
||||
+4
-3
@@ -14,9 +14,10 @@ is guessed from ad text, the second is what the gates do.
|
||||
|
||||
The work is pairs, `(agent, role)`: an enabled agent with a CV, and a role
|
||||
among its best ungated scores as deep and as low as its own `limits` say
|
||||
(`judge_top`, `judge_min`) with some text, that has no judgement yet, or one
|
||||
read from another CV, prompts, like, avoid or must text or role text than today's
|
||||
(`input_key`). A pair is named by the composite key `"<agent_id>:<uid>"`,
|
||||
(`judge_top`, `judge_min`), or among the `judge_cv_top` ungated roles closest
|
||||
to its CV (`scores.cv_fit`) that those leave out, with some text, that has
|
||||
no judgement yet, or one read from another CV, prompts, like, avoid or must
|
||||
text or role text than today's (`input_key`). A pair is named by the composite key `"<agent_id>:<uid>"`,
|
||||
which is what `desk.modeltask` hands round as a uid, so `desk/` is untouched.
|
||||
A batch holds one agent's pairs, since the profile is in the system prompt;
|
||||
the finder cuts per agent (`_finder`) and the job runs one call per agent it
|
||||
|
||||
+61
-6
@@ -29,6 +29,12 @@ roles out of extract's reach for good.
|
||||
over this agent's votes; with only likes it is the liked mean,
|
||||
with only passes the negated passed mean; no votes, no term
|
||||
|
||||
Beside the score, for an agent with a CV, `cv_fit`: how close the role is to
|
||||
the CV, the best cosine between the role and the CV's chunks
|
||||
(`embed.cv_chunks`, embedded as the prompts are), scaled like fit. It is no
|
||||
term of the score; the judge reads the closest roles the score leaves out
|
||||
(`Store.judge_rows`) and CV match orders the roles not judged yet by it.
|
||||
|
||||
Every term is 0..1. The score is the weighted sum over the sum of the weights
|
||||
(the agent's four and its prefer gates'), so it stays 0..1. A favourite
|
||||
company (`affinity = 2`) skips the `any` group but not the `require` or
|
||||
@@ -208,6 +214,21 @@ def intent_key(model: str, intent: str) -> str:
|
||||
return hashlib.sha1(f"{model}\n{intent}".encode()).hexdigest()
|
||||
|
||||
|
||||
def cv_key(model: str, cv_text: str) -> str:
|
||||
"""What the CV's vectors are cached under: the model, how the CV is cut
|
||||
(`embed.CV_CHUNKING`) and the text."""
|
||||
return hashlib.sha1(f"{model}\n{embed.CV_CHUNKING}\n{cv_text}".encode()).hexdigest()
|
||||
|
||||
|
||||
def closeness(role: np.ndarray, chunks: np.ndarray) -> float:
|
||||
"""The best raw cosine between a role and the CV's chunks, -1..1, with
|
||||
`chunks` one unit-length row each (`_cv`); 0 for a zero role vector."""
|
||||
norm = float(np.linalg.norm(role))
|
||||
if norm == 0 or not len(chunks):
|
||||
return 0.0
|
||||
return float(np.max(chunks @ role)) / norm
|
||||
|
||||
|
||||
class _Encoder:
|
||||
"""The embedder, loaded on first use only: an agent whose prompt vectors
|
||||
are cached costs no model load at all."""
|
||||
@@ -219,6 +240,10 @@ class _Encoder:
|
||||
self.failed = False
|
||||
|
||||
def encode(self, text: str) -> np.ndarray | None:
|
||||
found = self.encode_many([text])
|
||||
return None if found is None else found[0]
|
||||
|
||||
def encode_many(self, texts: Sequence[str]) -> np.ndarray | None:
|
||||
if self.failed:
|
||||
return None
|
||||
if self._embedder is None:
|
||||
@@ -228,7 +253,7 @@ class _Encoder:
|
||||
self.failed = True
|
||||
self.context.notice(embed.unavailable(exc))
|
||||
return None
|
||||
return np.asarray(self._embedder.encode([text])[0])
|
||||
return np.asarray(self._embedder.encode(list(texts)))
|
||||
|
||||
|
||||
def _prompts(store: Store, agent: Agent, model: str,
|
||||
@@ -251,6 +276,27 @@ def _prompts(store: Store, agent: Agent, model: str,
|
||||
return found
|
||||
|
||||
|
||||
def _cv(store: Store, agent: Agent, model: str, encoder: _Encoder) -> np.ndarray | None:
|
||||
"""The agent's CV as one unit-length row per chunk (`embed.cv_chunks`),
|
||||
each encoded as the prompts are ("query: " for an e5 model), or None
|
||||
without a CV or an embedder. Cached under `cv_key`, so a run embeds the
|
||||
CV only after it changed."""
|
||||
if not agent.cv_text.strip():
|
||||
return None
|
||||
key = cv_key(model, agent.cv_text)
|
||||
found = store.cv_vectors(agent.id, key)
|
||||
if found is None:
|
||||
chunks = embed.cv_chunks(agent.cv_text)
|
||||
made = encoder.encode_many([embed.intent_text(model, c) for c in chunks])
|
||||
if made is None or not len(made):
|
||||
return None
|
||||
found = list(made)
|
||||
store.set_cv_vectors(agent.id, key, found)
|
||||
rows = np.vstack(found).astype(np.float64)
|
||||
norms = np.linalg.norm(rows, axis=1, keepdims=True)
|
||||
return rows / np.where(norms == 0, 1.0, norms)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------- the job
|
||||
|
||||
def no_intent(names: Sequence[str]) -> Notice:
|
||||
@@ -267,7 +313,8 @@ def no_intent(names: Sequence[str]) -> Notice:
|
||||
|
||||
def score_agent(store: Store, agent: Agent, vectors: dict[str, np.ndarray],
|
||||
prompts: Sequence[tuple[str, np.ndarray]], now: datetime,
|
||||
calibration: Calibration | None = None) -> dict[str, int]:
|
||||
calibration: Calibration | None = None,
|
||||
cv: np.ndarray | None = None) -> dict[str, int]:
|
||||
"""Two passes: the cosines of the roles this agent scores, to each of its
|
||||
`prompts` and to its taste direction, then every score with both scaled
|
||||
by the model's `calibration`, or across the run without one. A role's fit
|
||||
@@ -278,11 +325,14 @@ def score_agent(store: Store, agent: Agent, vectors: dict[str, np.ndarray],
|
||||
A gated role is left out of the cosines, so under the fallback a role
|
||||
that fails a require gate cannot stretch the range the ranked roles
|
||||
share. The voted roles are scored like any other; a liked one sits near
|
||||
the direction it helped make, which is what a like should do."""
|
||||
the direction it helped make, which is what a like should do. With `cv`
|
||||
(`_cv`), each of those roles also gets its `cv_fit`, its `closeness` to
|
||||
the CV scaled like fit, beside the score and not in it."""
|
||||
candidates = store.score_candidates(agent.id, agent.gates)
|
||||
direction = taste_direction(vectors, store.votes(agent.id))
|
||||
cosines: dict[str, dict[str, float]] = {name: {} for name, _ in prompts}
|
||||
tastes: dict[str, float] = {}
|
||||
near: dict[str, float] = {}
|
||||
for candidate in candidates:
|
||||
role_vec = vectors.get(candidate.uid)
|
||||
if role_vec is None or failed_gates(candidate, agent.gates):
|
||||
@@ -291,6 +341,8 @@ def score_agent(store: Store, agent: Agent, vectors: dict[str, np.ndarray],
|
||||
cosines[name][candidate.uid] = cosine(role_vec, prompt_vec)
|
||||
if direction is not None:
|
||||
tastes[candidate.uid] = cosine(role_vec, direction)
|
||||
if cv is not None:
|
||||
near[candidate.uid] = closeness(role_vec, cv)
|
||||
fits: dict[str, float] = {}
|
||||
best: dict[str, str] = {}
|
||||
for name, levels in cosines.items():
|
||||
@@ -298,7 +350,8 @@ def score_agent(store: Store, agent: Agent, vectors: dict[str, np.ndarray],
|
||||
if uid not in fits or value > fits[uid]:
|
||||
fits[uid], best[uid] = value, name
|
||||
tastes = scale(tastes, calibration.taste if calibration else None)
|
||||
rows: list[tuple[str, float, str, str]] = []
|
||||
near = scale(near, calibration.cv_band if calibration else None)
|
||||
rows: list[tuple[str, float, str, str, float | None]] = []
|
||||
gated = 0
|
||||
for candidate in candidates:
|
||||
fit = fits.get(candidate.uid)
|
||||
@@ -308,8 +361,10 @@ def score_agent(store: Store, agent: Agent, vectors: dict[str, np.ndarray],
|
||||
missing="no vector" if prompts else "no prompt vector")
|
||||
gated += bool(reason)
|
||||
counted = fit is not None and agent.weights.fit and not reason
|
||||
cv_fit = near.get(candidate.uid)
|
||||
rows.append((candidate.uid, round(value, 6), reason,
|
||||
best[candidate.uid] if counted else ""))
|
||||
best[candidate.uid] if counted else "",
|
||||
None if cv_fit is None else round(cv_fit, 6)))
|
||||
store.replace_scores(agent.id, rows)
|
||||
return {"scored": len(rows), "gated": gated}
|
||||
|
||||
@@ -336,7 +391,7 @@ def run_score(config: Config, store: Store, *,
|
||||
context.check()
|
||||
context.progress(n, len(agents), f"scoring for {agent.name}, {n + 1} of {len(agents)}")
|
||||
counts = score_agent(store, agent, vectors, _prompts(store, agent, model, encoder),
|
||||
now, calibration)
|
||||
now, calibration, cv=_cv(store, agent, model, encoder))
|
||||
scored += counts["scored"]
|
||||
gated += counts["gated"]
|
||||
log.info("%-20s %6d scored, %6d gated", agent.name, counts["scored"], counts["gated"])
|
||||
|
||||
@@ -1244,6 +1244,9 @@ class ScoredRole(Role):
|
||||
#: judged; `cv_score` is its total.
|
||||
judgement: Judgement | None = None
|
||||
cv_score: float | None = None
|
||||
#: How close the role is to the agent's CV, 0..1 (`scores.cv_fit`), None
|
||||
#: without a CV, a vector or a score, and for a gated role.
|
||||
cv_fit: float | None = None
|
||||
#: The posting's languages against the agent's (`language_flag`).
|
||||
lang_flag: LangFlag = ""
|
||||
lang_note: str = ""
|
||||
@@ -1328,6 +1331,8 @@ class RoleRow(Model):
|
||||
lang_flag: LangFlag = ""
|
||||
lang_note: str = ""
|
||||
cv_score: float | None = None
|
||||
#: As `ScoredRole.cv_fit`: how close the role is to the agent's CV, 0..1.
|
||||
cv_fit: float | None = None
|
||||
|
||||
@computed_field # type: ignore[prop-decorator]
|
||||
@property
|
||||
@@ -1490,6 +1495,10 @@ class Limits(Model):
|
||||
#: so between summarise's 30 and extract's 500.
|
||||
judge_top: int = Field(150, ge=0)
|
||||
judge_min: float = Field(0.55, ge=0, le=1)
|
||||
#: And the agent's ungated roles closest to its CV (`scores.cv_fit`, see
|
||||
#: `app.jobs.score`) that the pair above leaves out, as many as this:
|
||||
#: a role the prompts rank low can still be one the CV fits.
|
||||
judge_cv_top: int = Field(50, ge=0)
|
||||
|
||||
|
||||
class Prompt(Model):
|
||||
|
||||
@@ -43,9 +43,11 @@
|
||||
// What the model reads after a pull, per agent: the best `extract_top`
|
||||
// roles scoring at least `extract_min` get their gate columns filled, the
|
||||
// best `summarise_top` at `summarise_min` or more a summary, and so does any
|
||||
// role that is saved or liked, whatever its score.
|
||||
// role that is saved or liked, whatever its score. The judge reads the best
|
||||
// `judge_top` at `judge_min` or more and the `judge_cv_top` ungated roles
|
||||
// closest to the CV that those leave out.
|
||||
const DEFAULT_LIMITS = { extract_top: 500, extract_min: 0.55, summarise_top: 30, summarise_min: 0.65,
|
||||
judge_top: 150, judge_min: 0.55 };
|
||||
judge_top: 150, judge_min: 0.55, judge_cv_top: 50 };
|
||||
// The levels of a language, the order of the server's ladder, and how big a
|
||||
// CV file the browser reads into the box.
|
||||
const LEVELS = ["basic", "conversational", "professional", "fluent", "native"];
|
||||
@@ -301,10 +303,12 @@
|
||||
function limitsLine(row) {
|
||||
const l = Object.assign({}, DEFAULT_LIMITS, row.limits);
|
||||
const p = el("p", "agent-limits");
|
||||
const judged = `${l.judge_top} at ${l.judge_min}`
|
||||
+ (l.judge_cv_top ? ` and the ${l.judge_cv_top} closest to the CV` : "");
|
||||
const clauses = [
|
||||
["extract", `reads ${l.extract_top} at ${l.extract_min}`, `${l.extract_top} at ${l.extract_min}`],
|
||||
["summarise", `summarises ${l.summarise_top} at ${l.summarise_min}`, `${l.summarise_top} at ${l.summarise_min}`],
|
||||
["judge", `judges ${l.judge_top} at ${l.judge_min}`, `${l.judge_top} at ${l.judge_min}`],
|
||||
["judge", `judges ${judged}`, judged],
|
||||
];
|
||||
clauses.forEach(([name, on, would], i) => {
|
||||
if (i) p.append(" · ");
|
||||
@@ -788,6 +792,7 @@
|
||||
$("#a-summarise-min", f).value = limits.summarise_min;
|
||||
$("#a-judge-top", f).value = limits.judge_top;
|
||||
$("#a-judge-min", f).value = limits.judge_min;
|
||||
$("#a-judge-cv-top", f).value = limits.judge_cv_top;
|
||||
$("#a-delete", f).hidden = !row;
|
||||
f.addEventListener("input", () => { f.dataset.dirty = "true"; view(); });
|
||||
f.addEventListener("change", view);
|
||||
@@ -899,6 +904,7 @@
|
||||
summarise_min: Number($("#a-summarise-min", f).value),
|
||||
judge_top: Number($("#a-judge-top", f).value),
|
||||
judge_min: Number($("#a-judge-min", f).value),
|
||||
judge_cv_top: Number($("#a-judge-cv-top", f).value),
|
||||
},
|
||||
fetch_terms: read.terms(),
|
||||
cv_text: $("#a-cv-text", f).value,
|
||||
|
||||
@@ -717,6 +717,9 @@ body[data-reader="open"] .row[data-open="true"] {
|
||||
padding-top: .2rem; text-align: right;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
/* Under CV match, a role not judged yet shows its closeness to the CV,
|
||||
fainter, beside an empty bar: a measure, not the model's reading. */
|
||||
.score.near { color: var(--faint); font-style: italic; }
|
||||
|
||||
/* Newest hides the score, because in that order it is not what put the
|
||||
row where it is. Done here rather than in the row template so the markup is
|
||||
|
||||
+18
-7
@@ -1041,15 +1041,26 @@
|
||||
}
|
||||
|
||||
/* The gutter's number, of 100, and what it says: the agent's score, or
|
||||
under CV match the CV match, where a role `judge` has not read yet
|
||||
shows a dash and an empty bar. */
|
||||
under CV match the CV match. A role `judge` has not read yet has an
|
||||
empty bar and, faint, how close it is to the CV (`cv_fit`), which is
|
||||
what orders it there, else a dash. */
|
||||
function gutterOf(role) {
|
||||
if (sortShown() === "cv") {
|
||||
const judged = role.cv_score !== null && role.cv_score !== undefined;
|
||||
if (judged) {
|
||||
return {
|
||||
pct: Math.round(Math.min(100, Math.max(0, role.cv_score))),
|
||||
shown: String(Math.round(role.cv_score)),
|
||||
title: "How well it matches the CV, of 100",
|
||||
};
|
||||
}
|
||||
const near = role.cv_fit !== null && role.cv_fit !== undefined;
|
||||
return {
|
||||
pct: judged ? Math.round(Math.min(100, Math.max(0, role.cv_score))) : 0,
|
||||
shown: judged ? String(Math.round(role.cv_score)) : "–",
|
||||
title: judged ? "How well it matches the CV, of 100" : "Not judged against the CV yet",
|
||||
pct: 0,
|
||||
shown: near ? String(Math.round(Math.min(1, Math.max(0, role.cv_fit)) * 100)) : "–",
|
||||
title: near ? "Not judged against the CV yet; how close it is to the CV, of 100"
|
||||
: "Not judged against the CV yet",
|
||||
near,
|
||||
};
|
||||
}
|
||||
const scored = role.score !== null && role.score !== undefined;
|
||||
@@ -1058,11 +1069,11 @@
|
||||
}
|
||||
|
||||
function drawRow(el, role) {
|
||||
const { pct, shown, title } = gutterOf(role);
|
||||
const { pct, shown, title, near } = gutterOf(role);
|
||||
const text = excerpt(role);
|
||||
el.innerHTML = `
|
||||
<div class="gutter"><i style="height:${pct}%"></i></div>
|
||||
<div class="score" title="${esc(title)}">${esc(shown)}</div>
|
||||
<div class="score${near ? " near" : ""}" title="${esc(title)}">${esc(shown)}</div>
|
||||
<div class="body">
|
||||
<a class="headline" href="${esc(pathFor(role.uid))}">${esc(role.title || "(untitled)")}</a>
|
||||
<div class="meta">
|
||||
|
||||
@@ -387,6 +387,8 @@ CREATE TABLE IF NOT EXISTS role_votes (
|
||||
|
||||
-- A role is scored per agent. A gated role keeps its row, with the reason.
|
||||
-- prompt names the agent's prompt that gave the fit, '' when fit did not count.
|
||||
-- cv_fit is how close the role is to the agent's CV, 0..1, NULL without a CV
|
||||
-- or a vector and for a gated role; it is no term of score.
|
||||
CREATE TABLE IF NOT EXISTS scores (
|
||||
uid TEXT NOT NULL REFERENCES roles(uid) ON DELETE CASCADE,
|
||||
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||
@@ -394,9 +396,21 @@ CREATE TABLE IF NOT EXISTS scores (
|
||||
gated_reason TEXT NOT NULL DEFAULT '',
|
||||
scored_at TEXT NOT NULL,
|
||||
prompt TEXT NOT NULL DEFAULT '',
|
||||
cv_fit REAL,
|
||||
PRIMARY KEY (uid, agent_id)
|
||||
);
|
||||
|
||||
-- The vectors of an agent's CV, one per chunk in order, for scores.cv_fit.
|
||||
-- vec_key is sha1 of the embedding model, the chunking and the CV text, the
|
||||
-- same on every row of an agent, so an unchanged CV is not embedded again.
|
||||
CREATE TABLE IF NOT EXISTS agent_cv_vectors (
|
||||
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||
position INTEGER NOT NULL,
|
||||
vec_key TEXT NOT NULL,
|
||||
vec BLOB NOT NULL,
|
||||
PRIMARY KEY (agent_id, position)
|
||||
);
|
||||
|
||||
-- One agent's judge reading of a role against its CV. Its own table, since
|
||||
-- replace_scores rewrites scores every run and a judgement outlives that
|
||||
-- and the role closing. skills, experience and career are 0 to 100,
|
||||
@@ -713,6 +727,10 @@ UPDATE roles SET seniority = COALESCE(NULLIF(seniority_model, ''),
|
||||
# reads every role again (judge.FORMAT).
|
||||
(30, "agents.like_text: what the person likes, beside what they do not like",
|
||||
lambda conn: _add_like_text(conn)),
|
||||
# A Python step: it adds the column and the table only where they are
|
||||
# missing. The next score fills them.
|
||||
(31, "scores.cv_fit and agent_cv_vectors: how close each role is to the agent's CV",
|
||||
lambda conn: _add_cv_fit(conn)),
|
||||
)
|
||||
|
||||
#: What a file created from `SCHEMA` today is already at.
|
||||
@@ -1061,6 +1079,21 @@ def _add_like_text(conn: sqlite3.Connection) -> None:
|
||||
conn.execute("ALTER TABLE agents ADD COLUMN like_text TEXT NOT NULL DEFAULT ''")
|
||||
|
||||
|
||||
def _add_cv_fit(conn: sqlite3.Connection) -> None:
|
||||
"""Migration 31's step: `scores.cv_fit`, NULL on every row until the
|
||||
next score, and `agent_cv_vectors`, empty until then. Runs twice without
|
||||
harm."""
|
||||
columns = {r[1] for r in conn.execute("PRAGMA table_info(scores)")}
|
||||
if "cv_fit" not in columns:
|
||||
conn.execute("ALTER TABLE scores ADD COLUMN cv_fit REAL")
|
||||
conn.execute("""CREATE TABLE IF NOT EXISTS agent_cv_vectors (
|
||||
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||
position INTEGER NOT NULL,
|
||||
vec_key TEXT NOT NULL,
|
||||
vec BLOB NOT NULL,
|
||||
PRIMARY KEY (agent_id, position))""")
|
||||
|
||||
|
||||
def _add_all_roles(conn: sqlite3.Connection) -> None:
|
||||
"""Migration 21's step. The column; the tag for every company that is a
|
||||
favourite of any agent, since favourite no longer widens what a pull
|
||||
|
||||
+67
-27
@@ -146,8 +146,10 @@ def _cv_sql(weights: Weights | None) -> str:
|
||||
|
||||
def _by_cv(expression: str) -> str:
|
||||
"""The order of 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, "
|
||||
`expression`), then the rest by how close they are to the CV
|
||||
(`scores.cv_fit`), then by score, as `roles` orders them."""
|
||||
return (f"{expression} IS NULL, {expression} DESC, "
|
||||
"s.cv_fit IS NULL, s.cv_fit DESC, ")
|
||||
|
||||
#: How many days after today the feed's Closing soon filter reaches.
|
||||
CLOSING_DAYS = 4
|
||||
@@ -900,15 +902,15 @@ 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` (under the agent's weights as they are
|
||||
now) and language flag for that agent; None
|
||||
`gated_reason`, `prompt` and `cv_fit` as `agent_id` judged and scored
|
||||
it, and 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(
|
||||
f"SELECT roles.*, v.vote, v.voted_at, {_VOTED_SCORE} AS score, "
|
||||
"COALESCE(s.gated_reason, '') AS gated_reason, COALESCE(s.prompt, '') AS prompt "
|
||||
f"FROM roles {_WITH_VOTES} "
|
||||
"COALESCE(s.gated_reason, '') AS gated_reason, COALESCE(s.prompt, '') AS prompt, "
|
||||
f"s.cv_fit FROM roles {_WITH_VOTES} "
|
||||
"LEFT JOIN scores s ON s.uid = roles.uid AND s.agent_id = ? WHERE roles.uid=?",
|
||||
(agent_id, agent_id, uid))
|
||||
if row is None:
|
||||
@@ -1143,7 +1145,8 @@ class Store:
|
||||
no score.
|
||||
|
||||
With `by_cv` as well, the roles the agent's `judge` read come first
|
||||
by `cv_score`, then the others by score (CV match). Every row
|
||||
by `cv_score`, then the others by how close they are to the CV
|
||||
(`cv_fit`), then by score (CV match). Every row
|
||||
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
|
||||
@@ -1167,7 +1170,7 @@ class Store:
|
||||
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"
|
||||
select += f", {_VOTED_SCORE} AS score, s.gated_reason, s.prompt, s.cv_fit"
|
||||
order = (_by_cv(cv) if by_cv else "") + "score DESC, " + order
|
||||
elif open_only:
|
||||
# Newest first, open only: idx_roles_posted covers this exactly
|
||||
@@ -1221,7 +1224,8 @@ class Store:
|
||||
by uid, see `role`.
|
||||
|
||||
`lang_flag` and `lang_note` are the role's languages against the
|
||||
agent's (`language_flag`), and `cv_score` its `judge` total.
|
||||
agent's (`language_flag`), `cv_score` its `judge` total and `cv_fit`
|
||||
how close it is to the agent's CV.
|
||||
|
||||
`excerpt` is `app.models.excerpt` over a `SUBSTR` of `_EXCERPT_SOURCE`
|
||||
(`_EXCERPT_RAW` characters, trimmed further in Python), so the source
|
||||
@@ -1244,7 +1248,7 @@ class Store:
|
||||
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"
|
||||
select += f", {_VOTED_SCORE} AS score, s.gated_reason, s.prompt, s.cv_fit"
|
||||
order = (_by_cv(cv) if by_cv else "") + "score DESC, " + order
|
||||
elif open_only:
|
||||
# Same reasoning as `roles`: the planner otherwise sorts every
|
||||
@@ -1259,6 +1263,8 @@ class Store:
|
||||
row["excerpt"] = excerpt(row["excerpt"])
|
||||
if row["cv_score"] is not None:
|
||||
row["cv_score"] = round(row["cv_score"], 1)
|
||||
if row.get("cv_fit") is not None:
|
||||
row["cv_fit"] = round(row["cv_fit"], 3)
|
||||
row["lang_flag"], row["lang_note"] = language_flag(
|
||||
role_languages(row.pop("languages_required")), mine)
|
||||
found.append(RoleRow.from_row(row))
|
||||
@@ -1871,8 +1877,10 @@ class Store:
|
||||
def judge_rows(self, agent: Agent, uids: Sequence[str] | None = None) -> list[sqlite3.Row]:
|
||||
"""What `judge` may read for one agent: its best ungated scores of
|
||||
open roles that are no copy, as deep and as low as its `limits` say
|
||||
(`judge_top`, `judge_min`), best first, each with some text
|
||||
(`article_text` or `description`). Given `uids`, those of them with
|
||||
(`judge_top`, `judge_min`), best first, then the `judge_cv_top`
|
||||
ungated ones closest to its CV (`scores.cv_fit`) that the first set
|
||||
leaves out, closest first, each with some text (`article_text` or
|
||||
`description`). Given `uids`, those of them with
|
||||
text, whatever their rank or state. Each row carries `uid`,
|
||||
`title`, `company`, `place`, `article_text`, `description`, and the
|
||||
stored judgement's `input_key`, `judged_at` and `tries` (NULL, NULL
|
||||
@@ -1887,16 +1895,23 @@ class Store:
|
||||
return self._rows(
|
||||
f"{select} roles r {joined} WHERE r.uid IN (SELECT value FROM json_each(?)) "
|
||||
f"AND {text} ORDER BY r.uid", (agent.id, json.dumps(list(uids))))
|
||||
ranked = ("FROM scores s JOIN roles top ON top.uid = s.uid AND top.closed_at IS NULL "
|
||||
"AND top.dup_of IS NULL WHERE s.agent_id = ? AND s.gated_reason = ''")
|
||||
return self._rows(
|
||||
f"""{select} (SELECT s.uid, s.score FROM scores s
|
||||
JOIN roles top ON top.uid = s.uid AND top.closed_at IS NULL
|
||||
AND top.dup_of IS NULL
|
||||
WHERE s.agent_id = ? AND s.gated_reason = ''
|
||||
ORDER BY s.score DESC, top.posted_at DESC, s.uid LIMIT ?) best
|
||||
JOIN roles r ON r.uid = best.uid {joined}
|
||||
WHERE best.score >= ? AND {text}
|
||||
ORDER BY best.score DESC, r.posted_at DESC, r.uid""",
|
||||
(agent.id, agent.limits.judge_top, agent.id, agent.limits.judge_min))
|
||||
f"""WITH best AS (SELECT s.uid, s.score {ranked}
|
||||
ORDER BY s.score DESC, top.posted_at DESC, s.uid LIMIT ?),
|
||||
by_score AS (SELECT uid, 0 AS part, score AS rank FROM best
|
||||
WHERE score >= ?),
|
||||
by_cv AS (SELECT s.uid, 1 AS part, s.cv_fit AS rank {ranked}
|
||||
AND s.cv_fit IS NOT NULL
|
||||
AND s.uid NOT IN (SELECT uid FROM by_score)
|
||||
ORDER BY s.cv_fit DESC, top.posted_at DESC, s.uid LIMIT ?)
|
||||
{select} (SELECT * FROM by_score UNION ALL SELECT * FROM by_cv) w
|
||||
JOIN roles r ON r.uid = w.uid {joined}
|
||||
WHERE {text}
|
||||
ORDER BY w.part, w.rank DESC, r.posted_at DESC, r.uid""",
|
||||
(agent.id, agent.limits.judge_top, agent.limits.judge_min, agent.id,
|
||||
agent.limits.judge_cv_top, agent.id))
|
||||
|
||||
def set_judgement(self, agent_id: int, uid: str, input_key: str, skills: int,
|
||||
experience: int, career: int, strengths: Sequence[str],
|
||||
@@ -2189,6 +2204,27 @@ class Store:
|
||||
self._write("UPDATE agent_prompts SET vec_key=?, vec=? WHERE agent_id=? AND name=?",
|
||||
(key, pack(vec), agent_id, name))
|
||||
|
||||
def cv_vectors(self, agent_id: int, key: str) -> list[np.ndarray] | None:
|
||||
"""The cached vectors of the agent's CV, one per chunk in order, if
|
||||
they were made under `key`; None otherwise."""
|
||||
rows = self._rows("SELECT vec_key, vec FROM agent_cv_vectors WHERE agent_id=? "
|
||||
"ORDER BY position", (agent_id,))
|
||||
if not rows or any(r["vec_key"] != key for r in rows):
|
||||
return None
|
||||
return [unpack(r["vec"]) for r in rows]
|
||||
|
||||
def set_cv_vectors(self, agent_id: int, key: str, vectors: Sequence[np.ndarray]) -> None:
|
||||
"""Replace the agent's CV vectors with these, made under `key`. An
|
||||
agent deleted meanwhile gets nothing written, as in `replace_scores`."""
|
||||
with self.transaction() as conn:
|
||||
if conn.execute("SELECT 1 FROM agents WHERE id=?", (agent_id,)).fetchone() is None:
|
||||
return
|
||||
conn.execute("DELETE FROM agent_cv_vectors WHERE agent_id=?", (agent_id,))
|
||||
conn.executemany(
|
||||
"INSERT INTO agent_cv_vectors (agent_id, position, vec_key, vec) "
|
||||
"VALUES (?,?,?,?)",
|
||||
[(agent_id, n, key, pack(vec)) for n, vec in enumerate(vectors)])
|
||||
|
||||
# --------------------------------------------------------------- scores
|
||||
|
||||
def score_candidates(self, agent_id: int, gates: Sequence[Gate]) -> list[Candidate]:
|
||||
@@ -2226,11 +2262,13 @@ class Store:
|
||||
for r in rows]
|
||||
|
||||
def replace_scores(self, agent_id: int,
|
||||
rows: Sequence[tuple[str, float, str] | tuple[str, float, str, str]]
|
||||
rows: Sequence[tuple[str, float, str] | tuple[str, float, str, str]
|
||||
| tuple[str, float, str, str, float | None]]
|
||||
) -> int:
|
||||
"""`(uid, score, gated_reason)` for every role this agent scored,
|
||||
with the name of the prompt that gave the fit as a fourth item ('' when
|
||||
left out), replacing whatever it had: a role closed or muted since the last run
|
||||
left out) and the role's closeness to the agent's CV as a fifth (None
|
||||
when left out), replacing whatever it had: a role closed or muted since the last run
|
||||
drops out rather than keeping a stale score. One transaction, so a
|
||||
reader sees the old list or the new one. An agent deleted while its
|
||||
run was scoring gets nothing written and 0 back: its rows are gone
|
||||
@@ -2241,9 +2279,11 @@ class Store:
|
||||
return 0
|
||||
conn.execute("DELETE FROM scores WHERE agent_id=?", (agent_id,))
|
||||
conn.executemany(
|
||||
"""INSERT INTO scores (uid, agent_id, score, gated_reason, prompt, scored_at)
|
||||
VALUES (?,?,?,?,?,?)""",
|
||||
[(row[0], agent_id, row[1], row[2], row[3] if len(row) > 3 else "", stamp)
|
||||
"""INSERT INTO scores (uid, agent_id, score, gated_reason, prompt, cv_fit,
|
||||
scored_at)
|
||||
VALUES (?,?,?,?,?,?,?)""",
|
||||
[(row[0], agent_id, row[1], row[2], row[3] if len(row) > 3 else "",
|
||||
row[4] if len(row) > 4 else None, stamp)
|
||||
for row in rows])
|
||||
return len(rows)
|
||||
|
||||
|
||||
@@ -121,8 +121,9 @@
|
||||
<label>down to a score of <input type="number" id="a-summarise-min" min="0" max="1" step="0.05" value="0.65"></label>
|
||||
<label>Judge against the CV the best <input type="number" id="a-judge-top" min="0" step="10" value="150"></label>
|
||||
<label>down to a score of <input type="number" id="a-judge-min" min="0" max="1" step="0.05" value="0.55"></label>
|
||||
<label>and the closest to the CV <input type="number" id="a-judge-cv-top" min="0" step="10" value="50"></label>
|
||||
</fieldset>
|
||||
<span class="hint">Every pull scores every open role for free; these bound what the model then reads, per agent. The count is the backstop, the score the real stop. Fit is a level, the same in every run: a new role with the worst fit scores about 0.27, a perfect one about 0.87. Roles you saved or liked are summarised too, whatever their score. An agent with no prompt feeds neither extract nor summarise, and one with no CV feeds not the judge.</span>
|
||||
<span class="hint">Every pull scores every open role for free; these bound what the model then reads, per agent. The count is the backstop, the score the real stop. Fit is a level, the same in every run: a new role with the worst fit scores about 0.27, a perfect one about 0.87. Roles you saved or liked are summarised too, whatever their score. The judge also reads that many of the roles closest to the CV which the score leaves out, so a role the prompts rank low but the CV fits still gets read; closeness is a free local measure and no part of the score. An agent with no prompt feeds neither extract nor summarise, and one with no CV feeds not the judge.</span>
|
||||
<details class="advanced">
|
||||
<summary>Advanced</summary>
|
||||
<div class="advanced-body">
|
||||
|
||||
+3
-2
@@ -155,11 +155,12 @@ sources: {}
|
||||
# top N (the backstop) and a minimum score (the real stop): extract reads the
|
||||
# best extract_top roles at extract_min or more, summarise the best
|
||||
# summarise_top at summarise_min or more, and judge the best judge_top at
|
||||
# judge_min or more for an agent with a CV. Fit is a calibrated level, so a bar
|
||||
# judge_min or more for an agent with a CV, and the judge_cv_top ungated roles
|
||||
# closest to the CV that those leave out. Fit is a calibrated level, so a bar
|
||||
# means the same in every run: a fresh role with the worst fit scores about
|
||||
# 0.27 on the default weights, a perfect one about 0.87. The defaults are
|
||||
# {extract_top: 500, extract_min: 0.55, summarise_top: 30, summarise_min:
|
||||
# 0.65, judge_top: 150, judge_min: 0.55}; measured for "Copenhagen engineering" on 16,841 open roles, 0.55
|
||||
# 0.65, judge_top: 150, judge_min: 0.55, judge_cv_top: 50}; measured for "Copenhagen engineering" on 16,841 open roles, 0.55
|
||||
# admits about 300 roles to extract and 0.65 about 35 to summarise. A wide
|
||||
# monitoring search lowers the bars and raises the counts, a narrow hunt the
|
||||
# reverse. An agent without a prompt that has text has no fit and feeds
|
||||
|
||||
+1
-1
@@ -208,7 +208,7 @@ What was decided for roledesk and the one reason for each. The longer reasoning
|
||||
|
||||
**`extract_batch` and `summarise_batch` are `isolate=True`, with a timeout.** `context.check()` only runs between the calls `modeltask.one` makes, not inside one, so a call that hangs on either backend was otherwise unkillable short of restarting the server; a process boundary is what lets a Kill, or the timeout itself, actually end it. One call is already bounded at `agent.timeout`, so the deadline is a few calls' worth (30 minutes for extract, 15 for summarise): a batch still running after that is stuck, not slow. The cost: an isolated job's context has no working `stop`, `task` or `fan_out` (see `pipeline/child.py`'s `context_for`), so a refusal or an account-level failure inside a batch can no longer stop the rest of that task's queued siblings, which run on to the same failure instead of being spared it.
|
||||
|
||||
**A third order, CV match, from a model reading each agent's best roles against its CV (2026-10-03).** Taken from the `/rank` of github.com/MadsLorentzen/ai-job-search, which has a model score a posting against a written profile on five dimensions. Fit compares topics; it cannot tell a step down, years of experience or a stated deal-breaker, which a model reading both texts can. An agent may hold a CV (pasted, or a `.md`/`.txt` file the browser reads into the box), its languages with a level (suggested from the CV by one model call, then edited), and a soft profile of two free texts, "What I like" (`like_text`) and "What I don't like" (`avoid_text`, the column keeps its name), each covering the work, the workplace and situations, with no split into tasks versus environment; the prompts stay what the owner wants. Both texts feed the career score, which the rubric judges against what the person wants (the prompts), what they like and what they do not like, and whether the tasks and the setting would energise them. A deal-breaker is a hard rule and lives in the agent's gates, so the form has no must-haves box; `must_text` stays a column that only the API sets, and the verdicts and the cap below apply whenever it is non-empty. The stage `judge` (after summarise in the pull, switched under Runs like extract, Haiku by default) reads the pairs of an enabled agent with a CV within its `judge_top` and `judge_min` limits, once per `input_key` (a hash of the CV, prompts, both texts and the role's text), and stores skills, experience and career (0 to 100, their rubric bands verbatim), 1 to 3 strengths and gaps in `role_judgements`, which rescoring and closing never touch. The CV match is the weighted mean of the three, with the weights per agent (`cv_skills`, `cv_experience`, `cv_career` in `agents.weights`, default 30, 25, 30) applied when a role is served, so changing them needs no model call. Culture is left out (guessed from ad text) and location too (the gates do it): a must-haves text (set through the API) that names a place makes the model mark location down, so places belong in the Where rules. The model reports facts and code applies the rules: the must-haves text, when set, is read as one must-have per line (leading bullets and numbers dropped), the judge's profile (`<likes>`, `<dislikes>` and, when set, `<must>`) numbers them M1..Mn, and for each judgement the model answers `musts`, a verdict per must-have, "met", "broken" only when the posting text clearly contradicts it, or "unclear" when the text does not say (never inferred from silence; a must-have the model leaves out counts as unclear). It scores career on its rubric as before and the career is stored as given. The cap is code's: when a role is served, any "broken" verdict makes career count as `min(career, BROKEN_CAP)` with `BROKEN_CAP = 39` (`app.models`), in `cv_score`, in `Store.judgement` (which serves the model's career, `career_capped` and the must-haves with their text) and in `store._cv_sql`, which reads a `broken` count stored beside the verdicts (`role_judgements.musts` and `.broken`, migration 29), so CV match orders by the capped value too. The verdicts store each line's text, so the reader still shows the must-haves a judgement was made against after the text is edited. The judge's `input_key` carries a format version (`judge.FORMAT`, 3) and the likes text (`agents.like_text`, migration 30), so judgements made before the verdicts or the likes existed are made again; until then they serve with the verdicts they have, or none and no cap. The reader shows each must-have with ✓ met, ✗ broken or ? unclear, and career as "39 (capped: breaks a must-have; model said 55)". Their scale is ten postings a run; ours is the top of a ranking that has already scored every role for free.
|
||||
**A third order, CV match, from a model reading each agent's best roles against its CV (2026-10-03).** Taken from the `/rank` of github.com/MadsLorentzen/ai-job-search, which has a model score a posting against a written profile on five dimensions. Fit compares topics; it cannot tell a step down, years of experience or a stated deal-breaker, which a model reading both texts can. An agent may hold a CV (pasted, or a `.md`/`.txt` file the browser reads into the box), its languages with a level (suggested from the CV by one model call, then edited), and a soft profile of two free texts, "What I like" (`like_text`) and "What I don't like" (`avoid_text`, the column keeps its name), each covering the work, the workplace and situations, with no split into tasks versus environment; the prompts stay what the owner wants. Both texts feed the career score, which the rubric judges against what the person wants (the prompts), what they like and what they do not like, and whether the tasks and the setting would energise them. A deal-breaker is a hard rule and lives in the agent's gates, so the form has no must-haves box; `must_text` stays a column that only the API sets, and the verdicts and the cap below apply whenever it is non-empty. The stage `judge` (after summarise in the pull, switched under Runs like extract, Haiku by default) reads the pairs of an enabled agent with a CV within its `judge_top` and `judge_min` limits and the `judge_cv_top` closest to the CV (below), once per `input_key` (a hash of the CV, prompts, both texts and the role's text), and stores skills, experience and career (0 to 100, their rubric bands verbatim), 1 to 3 strengths and gaps in `role_judgements`, which rescoring and closing never touch. The CV match is the weighted mean of the three, with the weights per agent (`cv_skills`, `cv_experience`, `cv_career` in `agents.weights`, default 30, 25, 30) applied when a role is served, so changing them needs no model call. Culture is left out (guessed from ad text) and location too (the gates do it): a must-haves text (set through the API) that names a place makes the model mark location down, so places belong in the Where rules. The model reports facts and code applies the rules: the must-haves text, when set, is read as one must-have per line (leading bullets and numbers dropped), the judge's profile (`<likes>`, `<dislikes>` and, when set, `<must>`) numbers them M1..Mn, and for each judgement the model answers `musts`, a verdict per must-have, "met", "broken" only when the posting text clearly contradicts it, or "unclear" when the text does not say (never inferred from silence; a must-have the model leaves out counts as unclear). It scores career on its rubric as before and the career is stored as given. The cap is code's: when a role is served, any "broken" verdict makes career count as `min(career, BROKEN_CAP)` with `BROKEN_CAP = 39` (`app.models`), in `cv_score`, in `Store.judgement` (which serves the model's career, `career_capped` and the must-haves with their text) and in `store._cv_sql`, which reads a `broken` count stored beside the verdicts (`role_judgements.musts` and `.broken`, migration 29), so CV match orders by the capped value too. The verdicts store each line's text, so the reader still shows the must-haves a judgement was made against after the text is edited. The judge's `input_key` carries a format version (`judge.FORMAT`, 3) and the likes text (`agents.like_text`, migration 30), so judgements made before the verdicts or the likes existed are made again; until then they serve with the verdicts they have, or none and no cap. The reader shows each must-have with ✓ met, ✗ broken or ? unclear, and career as "39 (capped: breaks a must-have; model said 55)". CV closeness (2026-10-03) is a free, local signal beside the judge, never in its place: the score run cuts the CV into chunks (`embed.cv_chunks`: paragraphs, a longer one cut by line, then sentence, then word, neighbours joined again up to `CV_CHUNK_CHARS` = 1,200 characters, inside e5's 512 tokens), embeds each as a prompt is ("query: " for an e5 model), caches them in `agent_cv_vectors` under sha1 of the model, the chunking version and the CV text, and stores each ungated role's best cosine over the chunks, scaled to 0..1, as `scores.cv_fit` (migration 31). It is no term of the Agent match score. It has its own band, `Calibration.cv`, fit's when a model has none: a CV chunk is longer than a prompt and sits closer to every posting, so on the copy of 2026-10-03 fit's band (0.75, 0.88) clipped 88 of agent 2's 7,270 ungated roles to 1 and the 50 closest tied on posting date; (0.77, 0.90) clips one. The judge then also reads the `judge_cv_top` (default 50, per agent beside `judge_top` and `judge_min`) ungated roles closest to the CV that the first set leaves out, closest first, under the same `input_key`, give-up and text rules; a gated role stays out however close. On that copy 43 of agent 2's 50 closest roles were outside itsLine truncated
|
||||
|
||||
**A posting's languages and deadline, and a flag rather than a score.** Extract reads `languages_required` as objects (language, level on the ladder basic, conversational, professional, fluent, native, and required or plus) and a deadline, from the opening and the closing lines of the text, since both usually sit at the end. Jobnet and Jobbank state a deadline, kept as `deadline_host`; prep composes `deadline` host first. The language flag is computed when a role is served from the posting's languages and the agent's: ⚠ when a required one is missing or its level is above the agent's, ★ when a plus one is the agent's; it never changes a score. Closing soon is the deadline from today to today plus four days, in UTC.
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ def test_migration_20_seeds_an_old_file_and_leaves_collisions(tmp_path: Path) ->
|
||||
"VALUES (?, ?, '', '')", (key, name))
|
||||
conn.execute("PRAGMA user_version = 19")
|
||||
reopened = Store(path)
|
||||
assert reopened.migrations_applied == [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
|
||||
assert reopened.migrations_applied == [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
||||
assert reopened.duplicate_companies() == [("orsted", ["orsted", "ørsted"])]
|
||||
assert len(reopened.companies()) == 3
|
||||
|
||||
@@ -186,7 +186,7 @@ def test_migration_21_tags_the_favourites_and_the_boards_that_read_all_roles(tmp
|
||||
conn.execute("ALTER TABLE companies DROP COLUMN all_countries")
|
||||
conn.execute("PRAGMA user_version = 20")
|
||||
reopened = Store(path)
|
||||
assert reopened.migrations_applied == [21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
|
||||
assert reopened.migrations_applied == [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
||||
# The tag of 21 is All countries and All roles since 24.
|
||||
tagged = {"mistral-ai": 1, "acme": 0, "black-forest-labs": 1, "liked": 0}
|
||||
assert {c.key: c.all_roles for c in reopened.companies()} == tagged
|
||||
|
||||
@@ -96,7 +96,7 @@ def test_v28_adds_the_cv_columns_and_the_host_deadline_and_runs_twice(tmp_path:
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [28, 29, 30]
|
||||
assert migrated.migrations_applied == [28, 29, 30, 31]
|
||||
rows = {r["source_id"]: r for r in migrated._rows(
|
||||
"SELECT source_id, languages_required, deadline_host, deadline FROM roles")}
|
||||
assert (rows["a"]["deadline_host"], rows["a"]["deadline"]) == ("2026-10-18", None)
|
||||
@@ -108,7 +108,7 @@ def test_v28_adds_the_cv_columns_and_the_host_deadline_and_runs_twice(tmp_path:
|
||||
assert migrated.role(posting("a").uid).deadline == "2026-10-18"
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("PRAGMA user_version = 27")
|
||||
assert Store(path).migrations_applied == [28, 29, 30]
|
||||
assert Store(path).migrations_applied == [28, 29, 30, 31]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- deadline
|
||||
@@ -249,12 +249,12 @@ def test_v29_adds_the_musts_and_broken_columns_and_runs_twice(tmp_path: Path) ->
|
||||
conn.execute(f"ALTER TABLE role_judgements DROP COLUMN {column}")
|
||||
conn.execute("PRAGMA user_version = 28")
|
||||
|
||||
assert Store(path).migrations_applied == [29, 30]
|
||||
assert Store(path).migrations_applied == [29, 30, 31]
|
||||
with sqlite3.connect(path) as conn:
|
||||
columns = {r[1] for r in conn.execute("PRAGMA table_info(role_judgements)")}
|
||||
assert {"musts", "broken"} <= columns
|
||||
conn.execute("PRAGMA user_version = 28")
|
||||
assert Store(path).migrations_applied == [29, 30]
|
||||
assert Store(path).migrations_applied == [29, 30, 31]
|
||||
|
||||
|
||||
def test_v30_adds_like_text_and_runs_twice(tmp_path: Path) -> None:
|
||||
@@ -266,12 +266,12 @@ def test_v30_adds_like_text_and_runs_twice(tmp_path: Path) -> None:
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [30]
|
||||
assert migrated.migrations_applied == [30, 31]
|
||||
[data] = migrated.agents()
|
||||
assert (data.like_text, data.avoid_text) == ("", "Reporting.")
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("PRAGMA user_version = 29")
|
||||
assert Store(path).migrations_applied == [30]
|
||||
assert Store(path).migrations_applied == [30, 31]
|
||||
|
||||
|
||||
def test_the_musts_text_is_one_must_have_per_line() -> None:
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
"""CV closeness: the CV cut into chunks, embedded and cached like the
|
||||
prompts, each role's `cv_fit` beside its score, the judge window it widens and
|
||||
the CV match order of the roles not judged yet. The embedder is a fake;
|
||||
nothing here downloads a model or reaches a board."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlite3
|
||||
from collections.abc import Iterator, Sequence
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from app.config import CALIBRATION, Calibration, Config
|
||||
from app.jobs import embed, judge, score
|
||||
from app.models import Gate, Limits, Prompt
|
||||
from app.storage import Store
|
||||
from app.storage.schema import MIGRATIONS
|
||||
from desk.models import Item
|
||||
from pipeline import RunContext
|
||||
from prepped import upsert
|
||||
|
||||
NOW = datetime(2026, 10, 3, 9, 0, tzinfo=UTC)
|
||||
E5 = CALIBRATION["intfloat/multilingual-e5-small"]
|
||||
WORDS = ("backend", "python", "frontend", "react", "data")
|
||||
|
||||
|
||||
class FakeEmbedder:
|
||||
"""One dimension per word of `WORDS` and a constant one, as in
|
||||
test_score; records what it was asked to encode."""
|
||||
|
||||
model_id = "fake"
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.calls: list[list[str]] = []
|
||||
|
||||
def encode(self, texts: Sequence[str]) -> np.ndarray:
|
||||
self.calls.append(list(texts))
|
||||
rows = []
|
||||
for text in texts:
|
||||
lower = text.lower()
|
||||
vec = np.asarray([lower.count(w) for w in WORDS] + [0.1], dtype=np.float32)
|
||||
rows.append(vec / np.linalg.norm(vec))
|
||||
return np.vstack(rows)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake(monkeypatch: pytest.MonkeyPatch) -> FakeEmbedder:
|
||||
embedder = FakeEmbedder()
|
||||
monkeypatch.setattr(embed, "load_embedder", lambda model: embedder)
|
||||
return embedder
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def store(tmp_path: Path) -> Iterator[Store]:
|
||||
s = Store(tmp_path / "roledesk.db")
|
||||
s.clock = lambda: NOW
|
||||
yield s
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config(tmp_path: Path) -> Config:
|
||||
return Config(database=str(tmp_path / "roledesk.db"),
|
||||
embed={"model": "fake", "calibration": {"fake": E5.model_dump()}})
|
||||
|
||||
|
||||
def role(store: Store, source_id: str, title: str, body: str = "", **raw: Any) -> str:
|
||||
item = Item(source_id=source_id, location=f"https://boards.example/{source_id}",
|
||||
title=title, body=body or title, published_at=datetime(2026, 9, 30, tzinfo=UTC),
|
||||
raw={"company": "Acme", **raw})
|
||||
item.source = "ats"
|
||||
upsert(store, item)
|
||||
return item.uid
|
||||
|
||||
|
||||
def run(config: Config, store: Store, job: Any) -> dict[str, Any]:
|
||||
return dict(job(config, store, context=RunContext()))
|
||||
|
||||
|
||||
def cv_fits(store: Store, agent_id: int) -> dict[str, float | None]:
|
||||
with store.transaction() as conn:
|
||||
return dict(conn.execute(
|
||||
"SELECT uid, cv_fit FROM scores WHERE agent_id = ?", (agent_id,)).fetchall())
|
||||
|
||||
|
||||
def level(text: str, against: str) -> float:
|
||||
role_vec, other = FakeEmbedder().encode([text, against])
|
||||
lo, hi = E5.cv_band
|
||||
return min(max((score.cosine(role_vec, other) - lo) / (hi - lo), 0.0), 1.0)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ chunks
|
||||
|
||||
def test_a_cv_is_cut_at_paragraphs_and_joined_again_up_to_the_limit() -> None:
|
||||
cv = "Experience\n\nLed data.\n\n\n Skills: Python \n\n"
|
||||
assert embed.cv_chunks(cv, limit=40) == ["Experience\n\nLed data.\n\nSkills: Python"]
|
||||
assert embed.cv_chunks(cv, limit=21) == ["Experience\n\nLed data.", "Skills: Python"]
|
||||
assert embed.cv_chunks(" \n\n ") == []
|
||||
|
||||
|
||||
def test_a_long_paragraph_is_cut_by_line_then_sentence_then_word() -> None:
|
||||
lines = "\n".join(["a" * 30, "b" * 30, "c" * 30])
|
||||
assert embed.cv_chunks(lines, limit=65) == ["a" * 30 + "\n" + "b" * 30, "c" * 30]
|
||||
sentences = "One two three. Four five six. Seven eight nine."
|
||||
assert embed.cv_chunks(sentences, limit=30) == ["One two three. Four five six.",
|
||||
"Seven eight nine."]
|
||||
words = " ".join(["word"] * 20)
|
||||
found = embed.cv_chunks(words, limit=24)
|
||||
assert all(len(c) <= 24 for c in found) and " ".join(found) == words
|
||||
assert embed.cv_chunks("x" * 50, limit=20) == ["x" * 20, "x" * 20, "x" * 10]
|
||||
|
||||
|
||||
def test_no_chunk_of_a_long_cv_runs_past_the_model_window() -> None:
|
||||
cv = "\n\n".join(f"Role {n}. " + "Built Python data platforms. " * 60 for n in range(5))
|
||||
found = embed.cv_chunks(cv)
|
||||
assert found and all(len(c) <= embed.CV_CHUNK_CHARS for c in found)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------- score
|
||||
|
||||
def test_the_cv_band_is_its_own_and_falls_back_to_fits() -> None:
|
||||
assert E5.cv is not None and E5.cv_band == E5.cv != E5.fit
|
||||
assert Calibration(fit=(0.7, 0.9), taste=(-0.1, 0.2)).cv_band == (0.7, 0.9)
|
||||
with pytest.raises(ValueError):
|
||||
Calibration(fit=(0.7, 0.9), taste=(-0.1, 0.2), cv=(0.9, 0.8))
|
||||
|
||||
|
||||
def test_cv_fit_is_the_best_chunk_scaled_with_the_cv_band_and_no_term_of_the_score(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
backend = role(store, "1", "Backend Python")
|
||||
frontend = role(store, "2", "Frontend React")
|
||||
cv = "Backend engineer, python services.\n\nSome react on the side."
|
||||
plain = store.save_agent("Plain", prompts=[Prompt(name="Data", text="data")])
|
||||
with_cv = store.save_agent("With CV", prompts=[Prompt(name="Data", text="data")],
|
||||
cv_text=cv)
|
||||
run(config, store, embed.run_embed)
|
||||
run(config, store, score.run_score)
|
||||
|
||||
texts = {uid: embed.document(r) for uid in (backend, frontend)
|
||||
if (r := store.role(uid)) is not None}
|
||||
chunks = embed.cv_chunks(cv)
|
||||
assert len(chunks) == 1, "two short paragraphs are one chunk"
|
||||
fits = cv_fits(store, with_cv.id)
|
||||
for uid in (backend, frontend):
|
||||
assert fits[uid] == pytest.approx(max(level(texts[uid], c) for c in chunks), abs=1e-6)
|
||||
assert fits[backend] > fits[frontend]
|
||||
assert set(cv_fits(store, plain.id).values()) == {None}, "no CV, no closeness"
|
||||
assert store.scores(plain.id) == store.scores(with_cv.id), "not a term of the score"
|
||||
|
||||
|
||||
def test_the_best_chunk_wins(store: Store, config: Config, fake: FakeEmbedder,
|
||||
monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(embed, "CV_CHUNK_CHARS", 20)
|
||||
uid = role(store, "1", "Frontend React")
|
||||
owner = store.save_agent("CV", prompts=[Prompt(name="P", text="data")],
|
||||
cv_text="Backend python python.\n\nFrontend react work.")
|
||||
run(config, store, embed.run_embed)
|
||||
run(config, store, score.run_score)
|
||||
text = embed.document(store.role(uid)) # type: ignore[arg-type]
|
||||
assert cv_fits(store, owner.id)[uid] == pytest.approx(
|
||||
level(text, "Frontend react work."), abs=1e-6)
|
||||
|
||||
|
||||
def test_a_gated_role_and_a_role_without_a_vector_have_no_cv_fit(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
kept = role(store, "1", "Backend Python", country="DK")
|
||||
gated = role(store, "2", "Backend Python", country="SE")
|
||||
owner = store.save_agent("CV", prompts=[Prompt(name="P", text="python")],
|
||||
gates=[Gate(field="country", values=["DK"])],
|
||||
cv_text="Backend python.")
|
||||
run(config, store, embed.run_embed)
|
||||
later = role(store, "3", "Backend Python later", country="DK")
|
||||
run(config, store, score.run_score)
|
||||
fits = cv_fits(store, owner.id)
|
||||
assert fits[kept] is not None and fits[gated] is None and fits[later] is None
|
||||
|
||||
|
||||
def test_the_cv_is_embedded_once_per_text_with_the_query_prefix(
|
||||
store: Store, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
embedder = FakeEmbedder()
|
||||
monkeypatch.setattr(embed, "load_embedder", lambda model: embedder)
|
||||
config = Config(database=str(tmp_path / "roledesk.db"),
|
||||
embed={"model": "intfloat/multilingual-e5-small"})
|
||||
role(store, "1", "Backend Python")
|
||||
owner = store.save_agent("CV", prompts=[Prompt(name="P", text="python")],
|
||||
cv_text="Backend python.")
|
||||
run(config, store, score.run_score)
|
||||
assert embedder.calls == [["query: python"], ["query: Backend python."]]
|
||||
|
||||
embedder.calls.clear()
|
||||
run(config, store, score.run_score)
|
||||
assert embedder.calls == [], "an unchanged CV is read from the cache"
|
||||
|
||||
store.save_agent("CV", prompts=owner.prompts, agent_id=owner.id, cv_text="Frontend react.")
|
||||
run(config, store, score.run_score)
|
||||
assert embedder.calls == [["query: Frontend react."]]
|
||||
key = score.cv_key("intfloat/multilingual-e5-small", "Frontend react.")
|
||||
assert store.cv_vectors(owner.id, key) is not None
|
||||
assert store.cv_vectors(owner.id, "stale") is None
|
||||
|
||||
|
||||
# ------------------------------------------------------------------- judge
|
||||
|
||||
def ranked(store: Store, owner: Any, rows: Sequence[tuple[str, float, str, float | None]]
|
||||
) -> list[str]:
|
||||
uids = [role(store, sid, f"Head of AI {sid}", "Lead the data science team.")
|
||||
for sid, _, _, _ in rows]
|
||||
store.replace_scores(owner.id, [(uid, value, reason, "", fit)
|
||||
for uid, (_, value, reason, fit) in zip(uids, rows,
|
||||
strict=True)])
|
||||
return uids
|
||||
|
||||
|
||||
def window(store: Store) -> list[str]:
|
||||
return [row["uid"] for _, row, _, _ in judge.waiting(store)]
|
||||
|
||||
|
||||
def test_the_judge_also_reads_the_closest_to_the_cv_the_score_leaves_out(
|
||||
store: Store) -> None:
|
||||
owner = store.save_agent("Data", prompts=[Prompt(name="AI", text="Head of AI")],
|
||||
cv_text="VP Data.",
|
||||
limits=Limits(judge_top=2, judge_min=0.5, judge_cv_top=2))
|
||||
top, second, low, near, nearer, nearest_gated, far = ranked(store, owner, [
|
||||
("top", 0.9, "", 0.1), ("second", 0.8, "", 0.99), ("low", 0.4, "", 0.2),
|
||||
("near", 0.3, "", 0.6), ("nearer", 0.2, "", 0.7), ("gated", 0.0, "country SE", None),
|
||||
("far", 0.1, "", 0.05)])
|
||||
assert window(store) == [top, second, nearer, near]
|
||||
|
||||
store.save_agent("Data", prompts=owner.prompts, agent_id=owner.id,
|
||||
limits=Limits(judge_top=2, judge_min=0.85, judge_cv_top=2))
|
||||
assert window(store) == [top, second, nearer], \
|
||||
"a role under the bar is no part of the first set, so it may come in by the CV"
|
||||
|
||||
store.save_agent("Data", prompts=owner.prompts, agent_id=owner.id,
|
||||
limits=Limits(judge_top=2, judge_min=0.5, judge_cv_top=0))
|
||||
assert window(store) == [top, second]
|
||||
assert low and far and nearest_gated
|
||||
|
||||
|
||||
def test_a_gated_role_stays_out_of_the_window_however_close(store: Store) -> None:
|
||||
owner = store.save_agent("Data", prompts=[Prompt(name="AI", text="Head of AI")],
|
||||
cv_text="VP Data.",
|
||||
limits=Limits(judge_top=1, judge_min=0.5, judge_cv_top=5))
|
||||
top, _gated = ranked(store, owner, [("top", 0.9, "", 0.1), ("gated", 0.0, "remote", 1.0)])
|
||||
assert window(store) == [top]
|
||||
|
||||
|
||||
# ------------------------------------------------------------------- order
|
||||
|
||||
def test_cv_match_orders_the_unjudged_by_closeness_then_score(store: Store) -> None:
|
||||
owner = store.save_agent("Data", prompts=[Prompt(name="AI", text="Head of AI")],
|
||||
cv_text="VP Data.")
|
||||
judged, close, far, none_a, none_b = ranked(store, owner, [
|
||||
("judged", 0.1, "", 0.1), ("close", 0.2, "", 0.9), ("far", 0.9, "", 0.3),
|
||||
("none_a", 0.5, "", None), ("none_b", 0.6, "", None)])
|
||||
store.set_judgement(owner.id, judged, "k", 50, 50, 50, ["One."], ["Two."])
|
||||
page = store.roles_page(agent=owner.id, by_cv=True)
|
||||
assert [r.uid for r in page] == [judged, close, far, none_b, none_a]
|
||||
assert [r.cv_fit for r in page] == [0.1, 0.9, 0.3, None, None]
|
||||
assert [r.uid for r in store.roles(agent=owner.id, by_cv=True)] == [
|
||||
judged, close, far, none_b, none_a]
|
||||
assert [r.uid for r in store.roles_page(agent=owner.id)] == [
|
||||
far, none_b, none_a, close, judged], "Agent match ignores it"
|
||||
found = store.role(close, owner.id)
|
||||
assert found is not None and found.cv_fit == 0.9
|
||||
|
||||
|
||||
# --------------------------------------------------------------- migration
|
||||
|
||||
def test_migration_31_adds_the_column_and_the_table_and_runs_twice(tmp_path: Path) -> None:
|
||||
path = tmp_path / "old.db"
|
||||
Store(path)
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("DROP TABLE agent_cv_vectors")
|
||||
conn.execute("ALTER TABLE scores DROP COLUMN cv_fit")
|
||||
conn.execute("PRAGMA user_version = 30")
|
||||
assert Store(path).migrations_applied == [31]
|
||||
step = {v: s for v, _, s in MIGRATIONS}[31]
|
||||
with sqlite3.connect(path) as conn:
|
||||
assert callable(step)
|
||||
step(conn)
|
||||
assert "cv_fit" in {r[1] for r in conn.execute("PRAGMA table_info(scores)")}
|
||||
assert conn.execute("SELECT COUNT(*) FROM agent_cv_vectors").fetchone() == (0,)
|
||||
@@ -278,7 +278,7 @@ def test_a_v17_file_gains_dup_of_with_its_first_rebuild(tmp_path: Path) -> None:
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
|
||||
assert migrated.migrations_applied == [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
||||
assert dup_of(migrated) == {first.uid: None, second.uid: first.uid}
|
||||
with sqlite3.connect(path) as conn:
|
||||
assert conn.execute("SELECT 1 FROM sqlite_master WHERE name = 'idx_roles_dup_of'"
|
||||
|
||||
@@ -434,7 +434,7 @@ def test_migration_23_gives_every_agent_no_terms(tmp_path: Path) -> None:
|
||||
conn.execute("ALTER TABLE agents DROP COLUMN fetch_terms")
|
||||
conn.execute("PRAGMA user_version = 22")
|
||||
migrated = Store(path)
|
||||
assert migrated.migrations_applied == [23, 24, 25, 26, 27, 28, 29, 30]
|
||||
assert migrated.migrations_applied == [23, 24, 25, 26, 27, 28, 29, 30, 31]
|
||||
assert migrated.agents()[0].fetch_terms == []
|
||||
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ def test_migration_24_splits_the_tag_and_moves_terms_off(tmp_path: Path) -> None
|
||||
conn.execute("UPDATE companies SET all_roles=1 WHERE key='mistral-ai'")
|
||||
conn.execute("PRAGMA user_version = 23")
|
||||
migrated = Store(path)
|
||||
assert migrated.migrations_applied == [24, 25, 26, 27, 28, 29, 30]
|
||||
assert migrated.migrations_applied == [24, 25, 26, 27, 28, 29, 30, 31]
|
||||
flags = {c.key: (c.all_countries, c.all_roles) for c in migrated.companies()}
|
||||
assert flags == {"mistral-ai": (1, 1), "acme": (0, 1), "plain": (0, 0)}
|
||||
params = {s.target: s.params for s in migrated.subscriptions(source="ats")}
|
||||
|
||||
+1
-1
@@ -316,7 +316,7 @@ def test_migration_22_fills_the_host_words_from_raw(tmp_path: Path) -> None:
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [22, 23, 24, 25, 26, 27, 28, 29, 30]
|
||||
assert migrated.migrations_applied == [22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
||||
one = row(migrated, "1")
|
||||
assert (one["seniority_host"], one["employment_host"], one["remote_host"],
|
||||
one["country_host"]) == ("senior", "full_time", "true", "DK")
|
||||
|
||||
@@ -530,7 +530,7 @@ def test_migration_27_keeps_an_older_readers_remote_as_the_hosts_word(tmp_path:
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [27, 28, 29, 30]
|
||||
assert migrated.migrations_applied == [27, 28, 29, 30, 31]
|
||||
assert migrated.gazetteer().anywhere is not None
|
||||
row = migrated._row("SELECT remote_host, remote_model, remote_where_model FROM roles "
|
||||
"WHERE uid = ?", (board,))
|
||||
@@ -540,7 +540,7 @@ def test_migration_27_keeps_an_older_readers_remote_as_the_hosts_word(tmp_path:
|
||||
assert area(migrated, search.uid) == ("", "")
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("PRAGMA user_version = 26")
|
||||
assert Store(path).migrations_applied == [27, 28, 29, 30]
|
||||
assert Store(path).migrations_applied == [27, 28, 29, 30, 31]
|
||||
|
||||
|
||||
def test_a_role_waits_for_extract_until_it_was_asked_where(store: Store) -> None:
|
||||
|
||||
@@ -70,7 +70,7 @@ def test_schema_creates_on_an_empty_file(tmp_path: Path) -> None:
|
||||
"application_events", "agents", "scores", "state"} <= tables
|
||||
assert "idx_roles_cluster" in indexes
|
||||
assert store.migrations_applied == []
|
||||
assert LATEST == 30
|
||||
assert LATEST == 31
|
||||
# A second open finds it current and applies nothing.
|
||||
assert Store(path).migrations_applied == []
|
||||
|
||||
@@ -190,7 +190,7 @@ def test_a_v14_file_gains_the_watchlist_columns_and_leaves_companies_unrated(
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
|
||||
assert migrated.migrations_applied == [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
||||
acme = migrated.company("acme")
|
||||
assert acme is not None
|
||||
assert (acme.ats, acme.careers_url) == ("teamtailor", "https://a.example")
|
||||
@@ -395,7 +395,7 @@ def test_v14_makes_each_intent_the_agents_one_prompt_with_its_vector(tmp_path: P
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
|
||||
assert migrated.migrations_applied == [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
||||
assert migrated.agent(backend.id).prompts == [ # type: ignore[union-attr]
|
||||
Prompt(name="Backend", text="python backend")]
|
||||
assert migrated.agent(blank.id).prompts == [] # type: ignore[union-attr]
|
||||
@@ -419,7 +419,7 @@ def test_v16_gives_a_company_no_reason_and_keeps_its_row(tmp_path: Path) -> None
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
|
||||
assert migrated.migrations_applied == [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
||||
acme = migrated.company("acme")
|
||||
assert acme is not None
|
||||
assert (acme.careers_url, acme.notes, acme.hand_reason) == (
|
||||
@@ -448,7 +448,7 @@ def test_v17_folds_every_place_and_levels_the_titles_extract_has_not_read(
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
|
||||
assert migrated.migrations_applied == [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
||||
with sqlite3.connect(path) as conn:
|
||||
rows = {uid: (fold, level) for uid, fold, level in conn.execute(
|
||||
"SELECT uid, place_fold, seniority FROM roles")}
|
||||
@@ -691,7 +691,7 @@ def test_v19_gives_every_role_its_places_and_splits_its_level(tmp_path: Path) ->
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
|
||||
assert migrated.migrations_applied == [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
||||
assert [p.name for p in migrated.role_places(joined.uid)] == ["Copenhagen", "Malmö"]
|
||||
assert [p.name for p in migrated.role_places(detailed.uid)] == ["Aarhus"]
|
||||
assert migrated.role_places(stated.uid) == []
|
||||
@@ -733,7 +733,7 @@ def test_v25_clears_the_model_levels_the_ladder_splits_and_sets_the_level(
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [25, 26, 27, 28, 29, 30]
|
||||
assert migrated.migrations_applied == [25, 26, 27, 28, 29, 30, 31]
|
||||
with sqlite3.connect(path) as conn:
|
||||
found = {sid: rest for sid, *rest in conn.execute(
|
||||
"SELECT source_id, seniority_model, seniority_stated, seniority_title, seniority "
|
||||
@@ -751,12 +751,12 @@ def test_v26_adds_posting_url_empty_and_runs_twice_without_harm(tmp_path: Path)
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [26, 27, 28, 29, 30]
|
||||
assert migrated.migrations_applied == [26, 27, 28, 29, 30, 31]
|
||||
role = migrated.role(posting("a").uid)
|
||||
assert role is not None and role.posting_url == ""
|
||||
with sqlite3.connect(path) as conn:
|
||||
conn.execute("PRAGMA user_version = 25") # the column is there already
|
||||
assert Store(path).migrations_applied == [26, 27, 28, 29, 30]
|
||||
assert Store(path).migrations_applied == [26, 27, 28, 29, 30, 31]
|
||||
|
||||
|
||||
def test_a_pull_keeps_the_posting_url(store: Store) -> None:
|
||||
|
||||
+3
-3
@@ -1184,9 +1184,9 @@ def test_an_agents_limits_are_saved_listed_and_checked(client: TestClient) -> No
|
||||
default = client.post("/api/agents", json={"name": "Wide"}).json()
|
||||
assert default["limits"] == {"extract_top": 500, "extract_min": 0.55,
|
||||
"summarise_top": 30, "summarise_min": 0.65,
|
||||
"judge_top": 150, "judge_min": 0.55}
|
||||
"judge_top": 150, "judge_min": 0.55, "judge_cv_top": 50}
|
||||
narrow = {"extract_top": 50, "extract_min": 0.6, "summarise_top": 5, "summarise_min": 0.7,
|
||||
"judge_top": 20, "judge_min": 0.6}
|
||||
"judge_top": 20, "judge_min": 0.6, "judge_cv_top": 10}
|
||||
saved = client.post("/api/agents", json={"name": "Narrow", "limits": narrow})
|
||||
assert saved.status_code == 200 and saved.json()["limits"] == narrow
|
||||
assert [a["limits"]["extract_top"] for a in client.get("/api/agents").json()] == [50, 500]
|
||||
@@ -1231,7 +1231,7 @@ def test_list_roles_serves_the_row_projection_and_not_the_big_columns(
|
||||
"seniority", "salary_min", "salary_max", "currency", "salary_text", "salary_state",
|
||||
"original_url", "posting_url", "posted_at", "score", "gated_reason", "prompt", "vote",
|
||||
"voted_at", "read_at", "tags", "excerpt", "copies", "remote_where", "deadline",
|
||||
"lang_flag", "lang_note", "cv_score",
|
||||
"lang_flag", "lang_note", "cv_score", "cv_fit",
|
||||
}
|
||||
assert row["uid"] == uid
|
||||
assert row["company"] == "Acme" and row["place"] == "Berlin, Germany"
|
||||
|
||||
Reference in new issue
Block a user