Eng-Musa commited on
Commit
75ec4b3
Β·
1 Parent(s): 7f344b6

add distance modifer to punish and award

Browse files
Files changed (1) hide show
  1. services/job_matcher.py +33 -1
services/job_matcher.py CHANGED
@@ -47,6 +47,7 @@ class ScoreBreakdown(BaseModel):
47
  category_score: float
48
  seniority_score: float
49
  experience_score: float
 
50
 
51
 
52
  class MismatchAnalysis(BaseModel):
@@ -389,7 +390,7 @@ class JobMatcher:
389
  experience = _experience_fit(cv_years, job.min_years_experience)
390
 
391
  # ── Weighted aggregation ─────────────────────────────────────────
392
- final = (
393
  0.42 * skill
394
  + 0.23 * semantic
395
  + 0.12 * title
@@ -398,6 +399,10 @@ class JobMatcher:
398
  + 0.05 * experience
399
  ) * 100
400
 
 
 
 
 
401
  # Guardrails
402
  if job_technical and not matched_technical:
403
  final = min(final, 34.0)
@@ -442,6 +447,7 @@ class JobMatcher:
442
  category_score=round(cat_score * 100, 2),
443
  seniority_score=round(seniority * 100, 2),
444
  experience_score=round(experience * 100, 2),
 
445
  ),
446
  mismatch_analysis=MismatchAnalysis(
447
  reason=reason,
@@ -508,3 +514,29 @@ class JobMatcher:
508
  cv_vec = self._embed(f"job title: {cv_title}")
509
  job_vec = self._embed(f"job title: {job_title}")
510
  return max(0.2, min(1.0, _cosine_similarity(cv_vec, job_vec)))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  category_score: float
48
  seniority_score: float
49
  experience_score: float
50
+ category_distance_modifier: float = 0.0
51
 
52
 
53
  class MismatchAnalysis(BaseModel):
 
390
  experience = _experience_fit(cv_years, job.min_years_experience)
391
 
392
  # ── Weighted aggregation ─────────────────────────────────────────
393
+ base_final = (
394
  0.42 * skill
395
  + 0.23 * semantic
396
  + 0.12 * title
 
399
  + 0.05 * experience
400
  ) * 100
401
 
402
+ # Category Distance Booster / Punisher
403
+ cat_modifier = self._category_distance_modifier(cv_category, job.category)
404
+ final = base_final + cat_modifier
405
+
406
  # Guardrails
407
  if job_technical and not matched_technical:
408
  final = min(final, 34.0)
 
447
  category_score=round(cat_score * 100, 2),
448
  seniority_score=round(seniority * 100, 2),
449
  experience_score=round(experience * 100, 2),
450
+ category_distance_modifier=round(cat_modifier, 2),
451
  ),
452
  mismatch_analysis=MismatchAnalysis(
453
  reason=reason,
 
514
  cv_vec = self._embed(f"job title: {cv_title}")
515
  job_vec = self._embed(f"job title: {job_title}")
516
  return max(0.2, min(1.0, _cosine_similarity(cv_vec, job_vec)))
517
+
518
+ def _category_distance_modifier(self, cv_category: str, job_category: str) -> float:
519
+ """
520
+ Calculate a score modifier between -20 and +20 based on how far apart
521
+ the CV category and Job category are semantically.
522
+ """
523
+ if not cv_category or not job_category:
524
+ return 0.0
525
+
526
+ cv_cat_clean = cv_category.strip().lower()
527
+ job_cat_clean = job_category.strip().lower()
528
+
529
+ if cv_cat_clean == job_cat_clean:
530
+ return 20.0
531
+
532
+ cv_vec = self._embed(f"industry sector: {cv_cat_clean}")
533
+ job_vec = self._embed(f"industry sector: {job_cat_clean}")
534
+
535
+ similarity = _cosine_similarity(cv_vec, job_vec)
536
+
537
+ # Map similarity [0, 1] to [-20, 20]
538
+ # Assuming similarity < 0.5 is distant (-20 to 0)
539
+ # Assuming similarity > 0.5 is close (0 to 20)
540
+ modifier = (similarity - 0.5) * 40.0
541
+
542
+ return max(-20.0, min(20.0, modifier))