feat: implement matching router with support for retrieval, reranking, and candidate explanation workflows
Browse files- backend/src/routers/matching.py +27 -19
backend/src/routers/matching.py
CHANGED
|
@@ -90,30 +90,30 @@ async def trigger_match(
|
|
| 90 |
MatchResult.session_id == session_id if session_id else MatchResult.session_id.is_(None),
|
| 91 |
)
|
| 92 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
except Exception:
|
| 94 |
await db.rollback()
|
| 95 |
raise
|
| 96 |
|
| 97 |
from ..workers.explain import generate_top_explanations
|
| 98 |
|
| 99 |
-
inserted_mrs = []
|
| 100 |
-
for i, item in enumerate(final_ranked):
|
| 101 |
-
mr = MatchResult(
|
| 102 |
-
id=uuid.uuid4(), jd_id=jd_id,
|
| 103 |
-
candidate_id=uuid.UUID(item["candidate_id"]),
|
| 104 |
-
session_id=session_id,
|
| 105 |
-
rank=i + 1,
|
| 106 |
-
stage1_score=item.get("stage1_score", 0),
|
| 107 |
-
stage2_score=item.get("stage2_score"),
|
| 108 |
-
final_score=item.get("final_score", 0),
|
| 109 |
-
component_scores=item.get("component_scores", {}),
|
| 110 |
-
gaps=item.get("gaps", []),
|
| 111 |
-
)
|
| 112 |
-
db.add(mr)
|
| 113 |
-
inserted_mrs.append(mr)
|
| 114 |
-
|
| 115 |
-
await db.commit()
|
| 116 |
-
|
| 117 |
# Pre-generate LLM explanations async for the top 20 matches implicitly in background
|
| 118 |
top_20_ids = [str(mr.id) for mr in inserted_mrs[:20]]
|
| 119 |
if top_20_ids:
|
|
@@ -163,7 +163,15 @@ async def get_match_results(
|
|
| 163 |
rows = result.all()
|
| 164 |
|
| 165 |
if not rows:
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
results = []
|
| 169 |
for mr, cand in rows:
|
|
|
|
| 90 |
MatchResult.session_id == session_id if session_id else MatchResult.session_id.is_(None),
|
| 91 |
)
|
| 92 |
)
|
| 93 |
+
|
| 94 |
+
inserted_mrs = []
|
| 95 |
+
for i, item in enumerate(final_ranked):
|
| 96 |
+
mr = MatchResult(
|
| 97 |
+
id=uuid.uuid4(), jd_id=jd_id,
|
| 98 |
+
candidate_id=uuid.UUID(item["candidate_id"]),
|
| 99 |
+
session_id=session_id,
|
| 100 |
+
rank=i + 1,
|
| 101 |
+
stage1_score=item.get("stage1_score", 0),
|
| 102 |
+
stage2_score=item.get("stage2_score"),
|
| 103 |
+
final_score=item.get("final_score", 0),
|
| 104 |
+
component_scores=item.get("component_scores", {}),
|
| 105 |
+
gaps=item.get("gaps", []),
|
| 106 |
+
)
|
| 107 |
+
db.add(mr)
|
| 108 |
+
inserted_mrs.append(mr)
|
| 109 |
+
|
| 110 |
+
await db.commit()
|
| 111 |
except Exception:
|
| 112 |
await db.rollback()
|
| 113 |
raise
|
| 114 |
|
| 115 |
from ..workers.explain import generate_top_explanations
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
# Pre-generate LLM explanations async for the top 20 matches implicitly in background
|
| 118 |
top_20_ids = [str(mr.id) for mr in inserted_mrs[:20]]
|
| 119 |
if top_20_ids:
|
|
|
|
| 163 |
rows = result.all()
|
| 164 |
|
| 165 |
if not rows:
|
| 166 |
+
return MatchResponse(
|
| 167 |
+
jd_id=jd_id,
|
| 168 |
+
jd_title=jd.title,
|
| 169 |
+
jd_quality=jd.jd_quality or {},
|
| 170 |
+
weights_used=jd.custom_weights or {},
|
| 171 |
+
total_matched=0,
|
| 172 |
+
results=[],
|
| 173 |
+
session_id=session_id,
|
| 174 |
+
)
|
| 175 |
|
| 176 |
results = []
|
| 177 |
for mr, cand in rows:
|