Enhance Planning Exercise Retrieval and Suggestion with Semantic Features
Deploy Development / deploy (push) Successful in 42s
Test Suite / pytest-backend (push) Successful in 40s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m14s

- Introduced new functions to load exercise goals and variant names in chunks, improving data retrieval efficiency.
- Integrated semantic scoring into the ranking logic, allowing for more nuanced exercise suggestions based on semantic relevance.
- Updated the planning exercise suggestion process to include semantic brief handling, enriching the context for exercise recommendations.
- Adjusted the retrieval phase to incorporate dynamic retrieval weights based on semantic strength, enhancing the overall suggestion accuracy.
- Incremented version to 0.8.186 and updated changelog to reflect these significant enhancements in planning AI functionality.
This commit is contained in:
Lars committed 2026-05-23 12:02:57 +02:00
1 parent a19ed02300
commit c6b8c396ad
14 files changed
+1393 -41

No files matched your search

@@ -1,11 +1,11 @@
"""Tests Planungs-KI Phase C3 — Pfad-Vorschläge."""
from planning_exercise_path_builder import _pick_next_path_hit, _hit_to_path_step
"""Tests Planungs-KI Phase C3/E — Pfad-Vorschläge."""
from planning_exercise_path_builder import _pick_best_path_hit, _hit_to_path_step
def test_pick_next_path_hit_skips_used():
hits = [{"id": 1, "title": "A"}, {"id": 2, "title": "B"}, {"id": 3, "title": "C"}]
assert _pick_next_path_hit(hits, {1})["id"] == 2
assert _pick_next_path_hit(hits, {1, 2, 3}) is None
hits = [{"id": 1, "title": "A", "semantic_score": 0.2}, {"id": 2, "title": "B", "semantic_score": 0.2}, {"id": 3, "title": "C", "semantic_score": 0.2}]
assert _pick_best_path_hit(hits, {1})["id"] == 2
assert _pick_best_path_hit(hits, {1, 2, 3}) is None
def test_hit_to_path_step_maps_variant():
@@ -0,0 +1,16 @@
"""Tests Planungs-KI Phase E — Pfad-QA."""
from planning_exercise_path_builder import _pick_best_path_hit
def test_pick_best_path_hit_prefers_semantic_score():
hits = [
{"id": 1, "title": "Mawashi", "score": 0.9, "semantic_score": 0.1},
{"id": 2, "title": "Mae Geri", "score": 0.75, "semantic_score": 0.85},
]
chosen = _pick_best_path_hit(hits, set())
assert chosen["id"] == 2
def test_pick_best_path_hit_skips_used():
hits = [{"id": 1, "title": "A", "score": 0.5, "semantic_score": 0.5}]
assert _pick_best_path_hit(hits, {1}) is None
@@ -0,0 +1,67 @@
"""Tests Planungs-KI Phase E — Semantik-Schicht."""
from planning_exercise_semantics import (
apply_dynamic_retrieval_weights,
build_semantic_brief,
score_exercise_semantic_relevance,
step_retrieval_query,
)
def test_build_semantic_brief_mae_geri():
brief = build_semantic_brief(
"Von Erlernen bis zur Perfektion, des Fußtritts Mae Geri"
)
assert brief.primary_topic == "mae geri"
assert "mae geri" in brief.must_phrases
assert "mawashi geri" in brief.exclude_phrases
assert brief.semantic_strength >= 0.8
assert "einstieg" in brief.development_arc or "perfektion" in brief.development_arc
def test_semantic_score_prefers_mae_over_mawashi():
brief = build_semantic_brief("Mae Geri Perfektion")
mae_score, _ = score_exercise_semantic_relevance(
title="Mae Geri — Frontkick Grundstellung",
summary="Frontkick von vorn",
goal="Sauberer Mae Geri",
variant_names=[],
brief=brief,
)
mawashi_score, _ = score_exercise_semantic_relevance(
title="Mawashi Geri — Rundkick",
summary="Rundkick Technik",
goal="Mawashi Geri Höhe",
variant_names=[],
brief=brief,
)
assert mae_score > mawashi_score
def test_dynamic_weights_boost_semantic_for_query_only():
brief = build_semantic_brief("Mae Geri bis Perfektion")
base = {
"fulltext": 0.45,
"semantic": 0.0,
"progression": 0.08,
"skill": 0.08,
"plan": 0.08,
"profile": 0.15,
"repeat_unit": -0.3,
"repeat_group": -0.15,
}
out = apply_dynamic_retrieval_weights(
base,
brief,
scenario="free_search",
has_planning_reference=False,
)
assert out["semantic"] > 0.25
assert out["fulltext"] < base["fulltext"]
def test_step_retrieval_query_carries_topic_and_phase():
brief = build_semantic_brief("Mae Geri von Einstieg bis Perfektion")
q0 = step_retrieval_query(brief, brief.retrieval_query, 0, 5)
q4 = step_retrieval_query(brief, brief.retrieval_query, 4, 5)
assert "mae geri" in q0.lower()
assert q0 != q4