The sift was feeding Opus a magnitude-blind, under-trusted, truncated shortlist — only 68% of the genuinely-best jobs reached the curator. Fixes: - embed.py: embed the FULL description (was desc[:600]) + role_category + industry; richer profile text (current_role + experience summary + seniority). The best semantic signal, fed real content. - sift.py: magnitude-preserving min-max fusion (was rank-position, which flattened cosine 0.95 vs 0.72) and embedding-LED weights (W_VIBE 0.6 / W_WHITEBOX 0.4). Embed runs FIRST so the white-box f_semantic reuses the real cosine (threaded as job["_vibe_cosine"]) instead of token overlap. - config.py: SIFT_TOP_K 18 → 28 (the gate was cutting good jobs before Opus). - curate.py: richer Opus briefs — full responsibilities (was desc[:500]) + role_category/industry/ seniority/pay, so even the shortlist is fully described. Regression (120 pairs): sift membership recall 0.68 → 0.92, score MAE 24.7 → 18.4. 31 tests pass.
27 lines
1.4 KiB
Python
27 lines
1.4 KiB
Python
"""A1 — sift: magnitude-fusion math + graceful degradation when the vibe-engineer is unavailable.
|
|
(Offline — no network; the embedding path is exercised in the cached e2e verification.)"""
|
|
from app.engine import sift as S
|
|
|
|
|
|
def test_minmax_normalization():
|
|
# magnitude-preserving (min-max), NOT rank-position: a much-better score stays much better.
|
|
r = S._minmax({"a": 0.9, "b": 0.5, "c": 0.1})
|
|
assert r["a"] == 1.0 and r["c"] == 0.0 and abs(r["b"] - 0.5) < 1e-9
|
|
assert S._minmax({"x": 0.5}) == {"x": 1.0} # single item / no range → top
|
|
|
|
|
|
def test_sift_degrades_to_whitebox_when_no_vibe(monkeypatch):
|
|
monkeypatch.setattr(S._embed, "vibe_scores", lambda *a, **k: None) # embeddings unavailable
|
|
jobs = [{"id": str(i), "title": "Product Manager", "organization": "X",
|
|
"location_city": "New Delhi", "location_country": "India",
|
|
"details": {"description": "product manager roadmap"}} for i in range(30)]
|
|
prefs = {"title": "Product Manager", "location": ["New Delhi · India"]}
|
|
top, dbg = S.sift(prefs, None, jobs, k=18)
|
|
assert dbg["mode"] == "whitebox-only" and len(top) == 18
|
|
assert all("match" in j for j in top) # white-box match block rides along
|
|
|
|
|
|
def test_sift_empty_input():
|
|
top, dbg = S.sift({"title": "PM"}, None, [], k=18)
|
|
assert top == [] and dbg["mode"] == "empty"
|