Refactor Planning Exercise Path Logic and Enhance Semantic Gating
Deploy Development / deploy (push) Successful in 42s
Test Suite / pytest-backend (push) Successful in 41s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m13s
Test Suite / pytest-backend (pull_request) Successful in 38s
Test Suite / lint-backend (pull_request) Successful in 0s
Test Suite / build-frontend (pull_request) Successful in 13s
Test Suite / k6 /health Baseline (pull_request) Successful in 33s
Test Suite / playwright-tests (pull_request) Successful in 1m13s
Deploy Development / deploy (push) Successful in 42s
Test Suite / pytest-backend (push) Successful in 41s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m13s
Test Suite / pytest-backend (pull_request) Successful in 38s
Test Suite / lint-backend (pull_request) Successful in 0s
Test Suite / build-frontend (pull_request) Successful in 13s
Test Suite / k6 /health Baseline (pull_request) Successful in 33s
Test Suite / playwright-tests (pull_request) Successful in 1m13s
- Replaced the manual path selection logic with a new `pick_best_path_hit` function to streamline the process of selecting the best exercise based on semantic scores and gating criteria. - Updated the semantic gating logic to apply a soft penalty for off-topic exercises, improving the flexibility of exercise selection. - Enhanced the handling of title, summary, and goal parameters in semantic checks to ensure more accurate relevance assessments. - Incremented version to 0.8.189 and updated changelog to reflect these improvements in planning AI functionality.
This commit is contained in:
1 parent
5b73d1a1f5
commit
8d1dd59c3c
5 files changed
+143
-32
No files matched your search
@@ -421,15 +421,22 @@ def _blob_from_fields(
|
||||
return " ".join(p for p in parts if p).lower()
|
||||
|
||||
|
||||
def _compact_alpha(text: str) -> str:
|
||||
return re.sub(r"[^a-z0-9äöüß]+", "", (text or "").lower())
|
||||
|
||||
|
||||
def _phrase_in_blob(phrase: str, blob: str) -> bool:
|
||||
ph = _normalize_phrase(phrase)
|
||||
if not ph or not blob:
|
||||
return False
|
||||
if ph in blob:
|
||||
low = blob.lower()
|
||||
if ph in low:
|
||||
return True
|
||||
if _compact_alpha(ph) and _compact_alpha(ph) in _compact_alpha(low):
|
||||
return True
|
||||
if " " not in ph:
|
||||
return bool(re.search(rf"\b{re.escape(ph)}\b", blob))
|
||||
return ph in blob
|
||||
return bool(re.search(rf"\b{re.escape(ph)}\b", low))
|
||||
return ph in low
|
||||
|
||||
|
||||
def score_exercise_semantic_relevance(
|
||||
@@ -602,17 +609,95 @@ def exercise_passes_path_semantic_gate(
|
||||
semantic_score: float,
|
||||
title: str,
|
||||
brief: PlanningSemanticBrief,
|
||||
summary: str = "",
|
||||
goal: str = "",
|
||||
strict: bool = True,
|
||||
) -> bool:
|
||||
if brief.semantic_strength < 0.55:
|
||||
return True
|
||||
if semantic_score >= 0.20:
|
||||
|
||||
blob = _blob_from_fields(title, summary, goal, [])
|
||||
min_score = 0.18 if strict else 0.06
|
||||
if semantic_score >= min_score:
|
||||
return True
|
||||
|
||||
topic = brief.primary_topic or ""
|
||||
if topic and _phrase_in_blob(topic, (title or "").lower()):
|
||||
if topic and _phrase_in_blob(topic, blob):
|
||||
return True
|
||||
|
||||
if not strict:
|
||||
# Mae Geri oft im Fließtext, nicht im Titel
|
||||
if semantic_score >= 0.04 and topic and _phrase_in_blob(topic, blob):
|
||||
return True
|
||||
parts = topic.split()
|
||||
if len(parts) >= 2 and all(_phrase_in_blob(p, blob) for p in parts):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def pick_best_path_hit(
|
||||
hits: List[Dict[str, Any]],
|
||||
used_exercise_ids: Set[int],
|
||||
*,
|
||||
semantic_brief: Optional[PlanningSemanticBrief] = None,
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
"""Gestufte Auswahl: strikt → relaxed → bester Semantik-Score."""
|
||||
if not hits:
|
||||
return None
|
||||
|
||||
def _scan(*, strict: bool) -> Optional[Dict[str, Any]]:
|
||||
best: Optional[Dict[str, Any]] = None
|
||||
best_key: Tuple[float, float] = (-1.0, -1.0)
|
||||
for hit in hits:
|
||||
eid = int(hit["id"])
|
||||
if eid in used_exercise_ids:
|
||||
continue
|
||||
sem = float(hit.get("semantic_score") or 0.0)
|
||||
if semantic_brief and not exercise_passes_path_semantic_gate(
|
||||
semantic_score=sem,
|
||||
title=str(hit.get("title") or ""),
|
||||
summary=str(hit.get("summary") or ""),
|
||||
goal="",
|
||||
brief=semantic_brief,
|
||||
strict=strict,
|
||||
):
|
||||
continue
|
||||
score = float(hit.get("score") or 0.0)
|
||||
key = (sem, score)
|
||||
if key > best_key:
|
||||
best_key = key
|
||||
best = hit
|
||||
return best
|
||||
|
||||
chosen = _scan(strict=True)
|
||||
if chosen:
|
||||
return chosen
|
||||
chosen = _scan(strict=False)
|
||||
if chosen:
|
||||
return chosen
|
||||
|
||||
# Notfall: bester verbleibender Treffer mit Semantik > 0 (Thema trotzdem priorisieren)
|
||||
fallback: Optional[Dict[str, Any]] = None
|
||||
fallback_key: Tuple[float, float] = (-1.0, -1.0)
|
||||
for hit in hits:
|
||||
eid = int(hit["id"])
|
||||
if eid in used_exercise_ids:
|
||||
continue
|
||||
sem = float(hit.get("semantic_score") or 0.0)
|
||||
score = float(hit.get("score") or 0.0)
|
||||
if sem <= 0 and semantic_brief and semantic_brief.primary_topic:
|
||||
topic = semantic_brief.primary_topic
|
||||
blob = (str(hit.get("title") or "") + " " + str(hit.get("summary") or "")).lower()
|
||||
if not _phrase_in_blob(topic, blob):
|
||||
continue
|
||||
key = (sem, score)
|
||||
if key > fallback_key:
|
||||
fallback_key = key
|
||||
fallback = hit
|
||||
return fallback
|
||||
|
||||
|
||||
__all__ = [
|
||||
"PlanningSemanticBrief",
|
||||
"apply_dynamic_retrieval_weights",
|
||||
@@ -622,6 +707,7 @@ __all__ = [
|
||||
"enrich_target_with_semantic_expectations",
|
||||
"exercise_passes_path_semantic_gate",
|
||||
"merge_semantic_brief_llm",
|
||||
"pick_best_path_hit",
|
||||
"resolve_semantic_skill_weights",
|
||||
"score_exercise_semantic_relevance",
|
||||
"semantic_core_phrases",
|
||||
|
||||
Reference in new issue
Block a user