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.
69 lines
2.6 KiB
Python
69 lines
2.6 KiB
Python
"""The vibe-engineer — embedding similarity (ENGINE_DESIGN §3 embedding ranker).
|
|
|
|
Cosine(profile-text, job-text) via `text-embedding-3-small`: one batched call (profile + all jobs),
|
|
the profile embedded alongside. Returns id → cosine in [0,1]; `None` when embeddings are unavailable
|
|
(no key / API error / empty profile) so the sift degrades to white-box only.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from app.config import get_settings
|
|
from app.engine.llm import embed_client
|
|
|
|
|
|
def _job_text(job: dict) -> str:
|
|
# The embedding is the best semantic matcher — feed it the FULL signal, not a 600-char stub.
|
|
# role_category + industry anchor non-tech JDs (narrative prose, few repeated title tokens).
|
|
d = job.get("details") or {}
|
|
parts = [
|
|
job.get("title", ""),
|
|
job.get("organization", ""),
|
|
d.get("role_category") or "",
|
|
d.get("industry") or "",
|
|
" ".join(d.get("skills") or job.get("required_skills") or []),
|
|
(d.get("description") or "")[:1000], # JD signal is front-loaded; 1k keeps embeds lean + cheap
|
|
]
|
|
return " · ".join(p for p in parts if p)
|
|
|
|
|
|
def _profile_text(prefs: dict, ctx: dict | None) -> str:
|
|
ctx = ctx or {}
|
|
# Embed the candidate richly too — current_role + experience summary + seniority, not just title+skills.
|
|
exp = ctx.get("experience_summary") or ctx.get("summary") or ""
|
|
parts = [
|
|
prefs.get("title", ""),
|
|
" ".join(prefs.get("role") or []),
|
|
ctx.get("current_role", "") or "",
|
|
" ".join(ctx.get("skills") or []),
|
|
" ".join(prefs.get("industry") or []),
|
|
" ".join(prefs.get("experience") or []),
|
|
str(exp)[:1200],
|
|
]
|
|
return " · ".join(p for p in parts if p)
|
|
|
|
|
|
def _cos(a, b) -> float:
|
|
import numpy as np
|
|
|
|
a, b = np.asarray(a, dtype=float), np.asarray(b, dtype=float)
|
|
n = float(np.linalg.norm(a) * np.linalg.norm(b))
|
|
return float(a @ b / n) if n else 0.0
|
|
|
|
|
|
def vibe_scores(prefs: dict, ctx: dict | None, jobs: list[dict]) -> dict[str, float] | None:
|
|
"""id → cosine sim (0..1). None if embeddings can't run (caller falls back to white-box only)."""
|
|
client = embed_client()
|
|
if not client or not jobs:
|
|
return None
|
|
ptext = _profile_text(prefs, ctx)
|
|
if not ptext.strip():
|
|
return None
|
|
s = get_settings()
|
|
texts = [ptext] + [_job_text(j) for j in jobs]
|
|
try:
|
|
resp = client.embeddings.create(model=s.EMBED_MODEL, input=texts)
|
|
except Exception:
|
|
return None
|
|
vecs = [d.embedding for d in resp.data]
|
|
pvec, jvecs = vecs[0], vecs[1:]
|
|
return {job["id"]: max(0.0, min(1.0, _cos(pvec, jv))) for job, jv in zip(jobs, jvecs)}
|