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:
WolfandClaude Fable 5.1 committed 2026-09-28 12:53:41 +02:00
1 parent 515d2250fc
commit a0772519b3
28 files changed
+1461 -668

No files matched your search

+86 -3
View File
@@ -179,9 +179,10 @@ def test_a_prefer_gate_adds_its_weight_to_the_score(
def test_a_favourite_skips_the_gates_and_is_floored(
store: Store, config: Config, fake: FakeEmbedder) -> None:
store.add_company("Fave", affinity=2)
store.add_company("Fave")
fave = role(store, "1", company="Fave", place="Munich")
agent = store.save_agent("Berlin", "", [Gate(field="place", values=["Berlin"])])
store.set_affinity(agent.id, "fave", 2)
run(config, store, score.run_score)
@@ -189,17 +190,21 @@ def test_a_favourite_skips_the_gates_and_is_floored(
assert reason == "" and value >= 0.9
def test_a_muted_company_is_never_scored(
def test_a_hidden_company_is_never_scored_for_the_agent_that_hid_it(
store: Store, config: Config, fake: FakeEmbedder) -> None:
store.add_company("Muted", affinity=-1)
store.add_company("Muted")
muted = role(store, "1", company="Muted")
kept = role(store, "2")
agent = store.save_agent("Any")
other = store.save_agent("Other")
store.set_affinity(agent.id, "muted", -1)
run(config, store, score.run_score)
assert set(store.scores(agent.id)) == {kept}
assert muted not in {r.uid for r in store.roles(agent=agent.id, gated=True)}
# The other agent did not hide it, so it is scored for that one.
assert set(store.scores(other.id)) == {muted, kept}
def test_an_older_role_scores_lower(
@@ -235,6 +240,84 @@ def test_two_agents_rank_the_same_roles_the_other_way_round(
assert store.scores(frontend.id)[back][0] == 0.0
# ------------------------------------------------------------------ taste
def _unit(*words: str) -> np.ndarray:
return FakeEmbedder().encode([" ".join(words)])[0]
def test_taste_direction_is_liked_minus_passed_and_none_without_votes() -> None:
vectors = {"a": _unit("backend"), "b": _unit("frontend"), "c": _unit("data")}
assert score.taste_direction(vectors, {}) is None
assert score.taste_direction(vectors, {"a": 0}) is None # neutral says nothing
assert score.taste_direction(vectors, {"gone": 1}) is None # no vector to point at
liked_only = score.taste_direction(vectors, {"a": 1, "c": 1})
assert liked_only is not None
assert liked_only == pytest.approx((vectors["a"] + vectors["c"]) / 2)
passed_only = score.taste_direction(vectors, {"b": -1})
assert passed_only is not None
assert passed_only == pytest.approx(-vectors["b"])
both = score.taste_direction(vectors, {"a": 1, "b": -1, "c": 0})
assert both is not None
assert both == pytest.approx(vectors["a"] - vectors["b"])
def test_taste_ranks_a_role_near_the_liked_one_above_one_near_the_passed(
store: Store, config: Config, fake: FakeEmbedder) -> None:
liked = role(store, "1", "Backend Engineer", body="Python backend")
passed = role(store, "2", "Frontend Engineer", body="React frontend")
near_liked = role(store, "3", "Platform Engineer", body="Python backend services")
near_passed = role(store, "4", "Web Engineer", body="React frontend apps")
# No intent: with taste alone weighted, the votes are all that orders them.
agent = store.save_agent("Taste", "", weights=Weights(fit=0, recency=0, affinity=0,
taste=1))
store.set_vote(agent.id, liked, 1)
store.set_vote(agent.id, passed, -1)
run(config, store, embed.run_embed)
run(config, store, score.run_score)
scores = store.scores(agent.id)
assert scores[near_liked][0] > scores[near_passed][0]
assert scores[liked][0] == 1.0 and scores[passed][0] == 0.0
assert all(reason == "" for _, reason in scores.values())
def test_without_votes_taste_leaves_the_denominator(
store: Store, config: Config, fake: FakeEmbedder) -> None:
uid = role(store, "1")
agent = store.save_agent("Any", weights=Weights(fit=0, recency=0, affinity=0, taste=1))
run(config, store, embed.run_embed)
run(config, store, score.run_score)
# Taste is the only weighted term and there is no taste, so no weights.
assert store.scores(agent.id)[uid] == (0.0, "no weights")
def test_a_closed_liked_role_still_shapes_the_taste(
store: Store, config: Config, fake: FakeEmbedder) -> None:
liked = role(store, "1", "Backend Engineer", body="Python backend")
near = role(store, "2", "Platform Engineer", body="Python backend")
far = role(store, "3", "Web Engineer", body="React frontend")
agent = store.save_agent("Taste", "", weights=Weights(fit=0, recency=0, affinity=0,
taste=1))
run(config, store, embed.run_embed)
store.set_vote(agent.id, liked, 1)
with store.transaction() as conn:
conn.execute("UPDATE roles SET closed_at = ? WHERE uid = ?", (NOW.isoformat(), liked))
run(config, store, score.run_score)
scores = store.scores(agent.id)
assert liked not in scores
assert scores[near][0] == 1.0 and scores[far][0] == 0.0
# ------------------------------------------------------------ fit scaling
def test_scale_maps_the_closest_to_one_and_the_farthest_to_zero() -> None: