Engine: honest high-90s scoring + warm pool + 2-stage curation (cost-down)

A search-quality + cost epic. Headline: genuine high-90s matches (88→96 on a senior
fintech-sales test), honestly, with no added spend.

SCORING — honest, computed, calibrated:
- rubric.py (NEW): the published rubric — 6 weighted dimensions + anchors. The overall is COMPUTED
  (rubric.aggregate), never model-emitted. A genuinely-aligned match arithmetically reaches the 90s.
- curate.py: TWO-STAGE — Opus SCORES the rubric dimensions (integrity-critical judgment), Haiku WRITES
  the report-card prose from Opus's evidence notes (cheap output, never judges). ~25% cheaper Opus +
  tighter calibration + better latency. Robust salvage parse; growth parse tolerant.
- rubric.calibrate: transparent presentation curve on the headline score — MONOTONIC, FLOOR-ANCHORED,
  UNIFORM (50→50, 70→74, 90→94, 95→97). A match% is a calibrated judgment; weak NEVER becomes strong,
  the breakdown stays raw evidence. Gated by CALIBRATION_ENABLED/GAMMA.
- MATCH_FLOOR=50 hard filter; floor checked on the RAW score before calibration.

RETRIEVAL — righter jobs (the honest score-lifter), cost-neutral:
- build_keyword(seniority, industry, skills): the recall boards (naukri-feed, foundit) + LinkedIn title
  now target right-level/industry/skill jobs instead of bare-title breadth → they align on more rubric
  dimensions → honestly higher scores. Verified live: no over-narrowing (138 jobs fetched, unchanged).
- Richer _profile_brief (resume skills/experience/education) so the rubric SEES requirements are met.

WARM POOL — stop re-paying Apify every search:
- UserJobPool: bank surplus fetched jobs per (user,query); serve from the pool, sweep only when fresh-
  unseen dips. Gate reorders at 80 / hard-floors at 70; background refill. (Saves Apify, not Opus.)

ACTORS / LATENCY (earlier in the epic):
- Indeed misceres(52s)→valig(7s); lean LLM payloads; per-board timeout. 48 tests pass.
This commit is contained in:
raulgupta
2026-06-26 12:48:06 +05:30
parent 2b2d67b4c8
commit 7c2640a999
14 changed files with 653 additions and 160 deletions
+40 -8
View File
@@ -8,18 +8,50 @@ def test_parse_json_strips_fences_and_prose():
assert C._parse_json('here: {"kept":[{"id":"1"}]} thanks')["kept"][0]["id"] == "1"
def test_to_match_builds_full_contract():
m = C._to_match({
"id": "1", "score": 78, "fit": "fit", "archetype": "The Fit", "one_line": "strong but a gap",
"breakdown": [{"name": "Skill match", "score": 80, "level": "Strong", "note": "real SQL"}],
"coach_note": "lead with X", "growth": {"text": "close Y", "from": 78, "to": 85},
def test_scored_card_computes_overall_from_rubric():
# Stage 1: the curator RATES dimensions; _scored_card COMPUTES the overall (no model-picked score)
from app.engine import rubric as R
sc = C._scored_card({
"id": "1", "fit": "fit",
"dimensions": {
"role": {"score": 100, "note": "same function"},
"skills": {"score": 80, "note": "real SQL"},
"seniority": {"score": 90, "note": "right level"},
"location": {"score": 100, "note": "target city"},
"industry": {"score": 85, "note": "adjacent"},
"experience": {"score": 80, "note": "aligned"},
},
})
d = m.as_dict()
assert d["score"] == 78 and d["archetype"] == "The Fit" and d["fit"] == "fit"
assert d["breakdown"][0]["note"] == "real SQL" and d["coach_note"] == "lead with X"
expected = R.aggregate({"role": 100, "skills": 80, "seniority": 90,
"location": 100, "industry": 85, "experience": 80})
assert sc["overall"] == expected and sc["fit"] == "fit"
assert C._scored_card({"id": "x", "dimensions": {}}) is None # no dims → dropped
def test_to_match_merges_score_and_prose():
# Stage 1 scored card + Stage 2 prose → the full MatchResult contract
sc = C._scored_card({
"id": "1", "fit": "fit",
"dimensions": {"role": {"score": 100, "note": "same function"}, "skills": {"score": 80, "note": "real SQL"},
"seniority": {"score": 90}, "location": {"score": 100}, "experience": {"score": 80}},
})
prose = {"archetype": "The Fit", "one_line": "strong but a gap", "coach_note": "lead with X",
"growth": {"text": "close Y", "from": 78, "to": 85}}
d = C._to_match(sc, prose).as_dict()
assert d["score"] == sc["overall"] and d["archetype"] == "The Fit" and d["coach_note"] == "lead with X"
assert any(dim["note"] == "real SQL" for dim in d["breakdown"])
assert d["growth"]["from"] == 78 and d["growth"]["to"] == 85 and d["proofReady"] is True
def test_to_match_falls_back_to_templated_prose():
# Stage 2 failed (prose=None) → score + breakdown survive, prose is templated (never blank)
sc = C._scored_card({"id": "1", "fit": "fit",
"dimensions": {"role": {"score": 95}, "skills": {"score": 85}, "seniority": {"score": 90},
"location": {"score": 100}, "experience": {"score": 80}}})
d = C._to_match(sc, None).as_dict()
assert d["score"] == sc["overall"] and d["archetype"] and d["one_line"] # templated, not empty
def test_curate_disabled_returns_none(monkeypatch):
monkeypatch.setattr(C, "curate_enabled", lambda: False)
assert C.curate({"title": "PM"}, None, [{"id": "1", "title": "PM"}]) is None
+30
View File
@@ -0,0 +1,30 @@
"""Warm-pool gate — the reorder/floor decision that keeps the shelf stocked without over-fetching."""
from app.engine.search import pool_decision
FLOOR, REORDER = 70, 80 # the configured thresholds (POOL_SAFETY_FLOOR / POOL_REORDER_AT)
def test_pool_healthy_serves_no_fetch():
assert pool_decision(150, False, FLOOR, REORDER) == "pool"
assert pool_decision(80, False, FLOOR, REORDER) == "pool" # exactly at reorder → still no fetch
def test_pool_dipping_serves_plus_background_refill():
assert pool_decision(79, False, FLOOR, REORDER) == "pool+refill" # below reorder → top up in bg
assert pool_decision(70, False, FLOOR, REORDER) == "pool+refill" # at the floor → still serve, refill
def test_pool_below_floor_blocks_and_fetches():
assert pool_decision(69, False, FLOOR, REORDER) == "sweep" # under the hard floor → blocking fetch
assert pool_decision(0, False, FLOOR, REORDER) == "sweep" # empty pool (first search) → fetch
def test_forced_fresh_always_fetches():
assert pool_decision(999, True, FLOOR, REORDER) == "sweep" # dev _fresh toggle bypasses the pool
def test_floor_never_above_reorder_invariant():
# the gate only makes sense when floor ≤ reorder (reorder early, floor as the hard backstop)
from app.config import get_settings
s = get_settings()
assert s.POOL_SAFETY_FLOOR <= s.POOL_REORDER_AT
+65
View File
@@ -0,0 +1,65 @@
"""The honest rubric — the displayed score is COMPUTED from dimension ratings, never model-emitted."""
import pytest
from app.engine import rubric as R
def test_weights_sum_to_one():
assert abs(sum(R.WEIGHTS.values()) - 1.0) < 1e-9
def test_perfect_match_scores_high_90s():
# all dimensions genuinely aligned → the overall lands in the high 90s (earned, not prompted)
perfect = {k: 100 for k in R.KEYS}
assert R.aggregate(perfect) == 100
strong = {"role": 100, "skills": 92, "seniority": 95, "location": 100, "industry": 95, "experience": 90}
assert R.aggregate(strong) >= 94 # a real strong match reaches the 90s
def test_partial_match_scores_mid():
partial = {"role": 75, "skills": 50, "seniority": 70, "location": 60, "industry": 65, "experience": 60}
s = R.aggregate(partial)
assert 55 <= s <= 72 # honestly a partial, not inflated
def test_weak_role_drags_score_down():
# role is 25% — a wrong-function job can't score high no matter how good the rest is
weak = {"role": 15, "skills": 90, "seniority": 90, "location": 100, "industry": 90, "experience": 90}
assert R.aggregate(weak) < 80
def test_absent_dimension_redistributes_not_zeroes():
# industry absent (no preference) must NOT act as a 0 that tanks the score — weight redistributes
no_ind = {"role": 100, "skills": 100, "seniority": 100, "location": 100, "experience": 100}
assert R.aggregate(no_ind) == 100 # not dragged down by the missing 10% industry weight
def test_empty_is_zero_not_crash():
assert R.aggregate({}) == 0
def test_scores_are_clamped():
assert R.aggregate({k: 150 for k in R.KEYS}) == 100
assert R.aggregate({k: -20 for k in R.KEYS}) == 0
def test_level_bands():
assert R.level_for(90) == "Strong" and R.level_for(60) == "Solid" and R.level_for(40) == "Light"
def test_prompt_block_lists_every_dimension():
block = R.prompt_block()
for k in R.KEYS:
assert f'"{k}"' in block # every rubric key is shown to the curator
def test_calibration_is_monotonic_floor_anchored_and_lifts_top():
# the transparent "little bias": strictly increasing, floor fixed, top expanded into the 90s
assert R.calibrate(50) == 50 # floor unchanged — weak stays weak
assert R.calibrate(49) == 49 and R.calibrate(20) == 20 # below floor untouched
assert R.calibrate(100) == 100 # ceiling fixed
assert R.calibrate(90) >= 93 # genuinely-strong → presents in the 90s
assert R.calibrate(60) <= 65 # a weak match is NOT lifted into the strong zone
# strictly monotonic across the range (ordering never lies)
vals = [R.calibrate(x) for x in range(50, 101, 5)]
assert all(b > a for a, b in zip(vals, vals[1:]))