Per-agent ranking: votes, affinity and a taste term; settings are three sub-tabs
Votes on roles and company affinity move to role_votes and agent_companies, one row per search agent, so two agents rank the same roles differently. The score gains taste, the cosine to mean(liked) - mean(passed) of the agent's votes, as newsdesk ranks articles. The API takes agent on roles, votes and companies and falls back to the default agent, the enabled one with the lowest id. Settings become Search agents (a list again, with New and Delete), Sources (job boards, company boards and runs with the message log, one section per plugin) and Account. Old paths answer 301 to their section. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
515d2250fc
commit
a0772519b3
28 files changed
+1461
-668
No files matched your search
+55
-20
@@ -10,13 +10,19 @@ good for a given search. For each agent:
|
||||
the roles this agent scores in this run: the closest is 1,
|
||||
the farthest 0, a lone role 1
|
||||
recency 0.5 ** (days since first_seen / 14)
|
||||
affinity (companies.affinity + 1) / 3
|
||||
affinity (the agent's affinity for the company + 1) / 3
|
||||
taste cos(role vector, liked direction), min-max scaled like fit,
|
||||
where the direction is mean(liked vectors) - mean(passed vectors)
|
||||
over this agent's votes; with only likes it is the liked mean,
|
||||
with only passes the negated passed mean; no votes, no term
|
||||
|
||||
Every term is 0..1. The score is the weighted sum over the sum of the weights
|
||||
(the agent's three and its prefer gates'), so it stays 0..1. A favourite
|
||||
company (`affinity = 2`) skips the gates and is floored at 0.9; a muted one
|
||||
(`-1`) is not scored at all. A role with no vector is scored without `fit`,
|
||||
unless `fit` is all there is, when it is gated as "no vector".
|
||||
(the agent's four and its prefer gates'), so it stays 0..1. A favourite
|
||||
company (`affinity = 2`) skips the gates and is floored at 0.9; a hidden one
|
||||
(`-1`) is not scored at all. A role with no vector is scored without `fit`
|
||||
and `taste`, unless `fit` is all there is, when it is gated as "no vector".
|
||||
An agent with no votes scores every role without `taste`; the direction is
|
||||
newsdesk's `centroid(liked) - centroid(disliked)`.
|
||||
|
||||
Recomputed in full on every run, and each agent's rows are replaced in one
|
||||
transaction: nothing is incremental, so nothing can drift.
|
||||
@@ -75,6 +81,24 @@ def cosine(role: np.ndarray, intent: np.ndarray) -> float:
|
||||
return float(np.dot(role, intent)) / norms
|
||||
|
||||
|
||||
def taste_direction(vectors: dict[str, np.ndarray],
|
||||
votes: dict[str, int]) -> np.ndarray | None:
|
||||
"""`mean(liked) - mean(passed)` over the voted roles that have a vector.
|
||||
A side with no votes is zero, so likes alone point at the liked mean and
|
||||
passes alone away from the passed mean. None when neither side has a
|
||||
vector: no votes, no direction. A neutral vote says nothing."""
|
||||
liked = [vectors[uid] for uid, vote in votes.items() if vote == 1 and uid in vectors]
|
||||
passed = [vectors[uid] for uid, vote in votes.items() if vote == -1 and uid in vectors]
|
||||
if not liked and not passed:
|
||||
return None
|
||||
direction = np.zeros_like(liked[0] if liked else passed[0], dtype=np.float64)
|
||||
if liked:
|
||||
direction += np.mean(liked, axis=0)
|
||||
if passed:
|
||||
direction -= np.mean(passed, axis=0)
|
||||
return direction
|
||||
|
||||
|
||||
def scale(cosines: dict[str, float]) -> dict[str, float]:
|
||||
"""Min-max to 0..1 across one agent's run, so `fit` ranks roles rather
|
||||
than stating a level.
|
||||
@@ -111,11 +135,12 @@ def failed_gates(candidate: Candidate, gates: Sequence[Gate]) -> list[str]:
|
||||
|
||||
|
||||
def score_one(candidate: Candidate, gates: Sequence[Gate], weights: Weights,
|
||||
fit: float | None, now: datetime, *,
|
||||
fit: float | None, now: datetime, *, taste: float | None = None,
|
||||
missing: str = "no vector") -> tuple[float, str]:
|
||||
"""One role for one agent: `(score, gated_reason)`. `fit` is already
|
||||
scaled to 0..1 (see `scale`), or None when the role or the intent has no
|
||||
vector; `missing` says which."""
|
||||
"""One role for one agent: `(score, gated_reason)`. `fit` and `taste` are
|
||||
already scaled to 0..1 (see `scale`), or None when there is nothing to
|
||||
measure: no role vector, no intent vector, no votes. A None term leaves
|
||||
the denominator; `missing` says why fit is out."""
|
||||
favourite = candidate.affinity == 2
|
||||
if failed := failed_gates(candidate, gates):
|
||||
return 0.0, ", ".join(failed)
|
||||
@@ -126,6 +151,8 @@ def score_one(candidate: Candidate, gates: Sequence[Gate], weights: Weights,
|
||||
for g, state in zip(gates, candidate.gates, strict=True) if g.mode == "prefer"]
|
||||
if fit is not None:
|
||||
terms.append((weights.fit, fit))
|
||||
if taste is not None:
|
||||
terms.append((weights.taste, taste))
|
||||
total = sum(w for w, _ in terms)
|
||||
if not total:
|
||||
if favourite:
|
||||
@@ -183,23 +210,31 @@ def _intent(store: Store, agent: Agent, model: str,
|
||||
|
||||
def score_agent(store: Store, agent: Agent, vectors: dict[str, np.ndarray],
|
||||
intent: np.ndarray | None, now: datetime) -> dict[str, int]:
|
||||
"""Two passes: the cosines of the roles this agent scores, then every
|
||||
score with fit scaled across them. A gated role is left out of the
|
||||
scaling, so a role that fails a require gate cannot stretch the range the
|
||||
ranked roles share."""
|
||||
candidates = store.score_candidates(agent.gates)
|
||||
"""Two passes: the cosines of the roles this agent scores, to its intent
|
||||
and to its taste direction, then every score with both scaled across
|
||||
them. A gated role is left out of the scaling, so 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."""
|
||||
candidates = store.score_candidates(agent.id, agent.gates)
|
||||
direction = taste_direction(vectors, store.votes(agent.id))
|
||||
cosines: dict[str, float] = {}
|
||||
if intent is not None:
|
||||
for candidate in candidates:
|
||||
role_vec = vectors.get(candidate.uid)
|
||||
if role_vec is not None and not failed_gates(candidate, agent.gates):
|
||||
cosines[candidate.uid] = cosine(role_vec, intent)
|
||||
fits = scale(cosines)
|
||||
tastes: dict[str, float] = {}
|
||||
for candidate in candidates:
|
||||
role_vec = vectors.get(candidate.uid)
|
||||
if role_vec is None or failed_gates(candidate, agent.gates):
|
||||
continue
|
||||
if intent is not None:
|
||||
cosines[candidate.uid] = cosine(role_vec, intent)
|
||||
if direction is not None:
|
||||
tastes[candidate.uid] = cosine(role_vec, direction)
|
||||
fits, tastes = scale(cosines), scale(tastes)
|
||||
rows: list[tuple[str, float, str]] = []
|
||||
gated = 0
|
||||
for candidate in candidates:
|
||||
value, reason = score_one(
|
||||
candidate, agent.gates, agent.weights, fits.get(candidate.uid), now,
|
||||
taste=tastes.get(candidate.uid),
|
||||
missing="no vector" if intent is not None else "no intent vector")
|
||||
gated += bool(reason)
|
||||
rows.append((candidate.uid, round(value, 6), reason))
|
||||
|
||||
Reference in new issue
Block a user