Enhance Progression Path Suggestion with Retrieval Boost and Slot Assignment Logic
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 44s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m14s
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 44s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m14s
- Added `preserve_slot_assignments` and `retrieval_boost_exercise_ids` to `ProgressionPathSuggestRequest` for improved handling of exercise suggestions. - Refactored `_supplemental_exercise_ids_from_body` to incorporate retrieval boost exercise IDs, ensuring they are prioritized over slot assignments. - Updated `_build_steps_roadmap_first` to conditionally preserve slot assignments based on the new flag. - Enhanced tests to validate the new retrieval boost logic and its integration with existing slot assignment handling.
This commit is contained in:
1 parent
b464047c3a
commit
ad051c015f
6 files changed
+133
-38
No files matched your search
@@ -120,6 +120,8 @@ class ProgressionPathSuggestRequest(BaseModel):
|
||||
evaluate_only: bool = False
|
||||
evaluate_steps: Optional[List[EvaluateStepPayload]] = None
|
||||
slot_assignments: Optional[List[EvaluateStepPayload]] = None
|
||||
preserve_slot_assignments: bool = False
|
||||
retrieval_boost_exercise_ids: Optional[List[int]] = None
|
||||
roadmap_override: Optional[RoadmapOverridePayload] = None
|
||||
start_situation: Optional[str] = Field(default=None, max_length=2000)
|
||||
target_state: Optional[str] = Field(default=None, max_length=2000)
|
||||
@@ -267,18 +269,53 @@ def _build_path_target_profile(
|
||||
return target, query_intent_summary, intent
|
||||
|
||||
|
||||
def _supplemental_exercise_ids_from_body(body: ProgressionPathSuggestRequest) -> List[int]:
|
||||
"""Verankerte Graph-Slots immer im Retriever-Kandidatenpool halten."""
|
||||
def _graph_edge_exercise_ids(cur, graph_id: Optional[int]) -> List[int]:
|
||||
"""Übungs-IDs aus gespeicherten Graph-Kanten (für Re-Match-Boost)."""
|
||||
if not graph_id or int(graph_id) < 1:
|
||||
return []
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT from_exercise_id AS eid FROM exercise_progression_edges
|
||||
WHERE graph_id = %s AND from_exercise_id IS NOT NULL
|
||||
UNION
|
||||
SELECT to_exercise_id AS eid FROM exercise_progression_edges
|
||||
WHERE graph_id = %s AND to_exercise_id IS NOT NULL
|
||||
""",
|
||||
(int(graph_id), int(graph_id)),
|
||||
)
|
||||
out: List[int] = []
|
||||
for row in cur.fetchall() or []:
|
||||
try:
|
||||
eid = int(row.get("eid") or 0)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
if eid > 0:
|
||||
out.append(eid)
|
||||
return out
|
||||
|
||||
|
||||
def _supplemental_exercise_ids_from_body(
|
||||
cur,
|
||||
body: ProgressionPathSuggestRequest,
|
||||
) -> List[int]:
|
||||
"""Kandidatenpool erweitern — ohne automatisches Slot-Pinning."""
|
||||
ids: List[int] = []
|
||||
for coll in (body.slot_assignments, body.evaluate_steps):
|
||||
for raw in coll or []:
|
||||
if raw.exercise_id is not None:
|
||||
try:
|
||||
eid = int(raw.exercise_id)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
if eid > 0:
|
||||
ids.append(eid)
|
||||
for raw in body.evaluate_steps or []:
|
||||
if raw.exercise_id is not None:
|
||||
try:
|
||||
eid = int(raw.exercise_id)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
if eid > 0:
|
||||
ids.append(eid)
|
||||
for eid in body.retrieval_boost_exercise_ids or []:
|
||||
try:
|
||||
val = int(eid)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
if val > 0:
|
||||
ids.append(val)
|
||||
ids.extend(_graph_edge_exercise_ids(cur, body.progression_graph_id))
|
||||
return list(dict.fromkeys(ids))
|
||||
|
||||
|
||||
@@ -845,7 +882,7 @@ def _match_roadmap_slot(
|
||||
path_context_note=path_context_note,
|
||||
path_primary_topic=path_primary or None,
|
||||
path_technique_excludes=path_tech_excludes or None,
|
||||
supplemental_exercise_ids=_supplemental_exercise_ids_from_body(body),
|
||||
supplemental_exercise_ids=_supplemental_exercise_ids_from_body(cur, body),
|
||||
)
|
||||
|
||||
hit = _pick_best_path_hit(
|
||||
@@ -1026,7 +1063,11 @@ def _build_steps_roadmap_first(
|
||||
anchor_variant_id: Optional[int] = None
|
||||
unfilled: List[Tuple[int, StageSpecArtifact]] = []
|
||||
stage_count = len(stage_specs)
|
||||
assignments = _slot_assignments_by_major_index(body.slot_assignments)
|
||||
assignments = (
|
||||
_slot_assignments_by_major_index(body.slot_assignments)
|
||||
if body.preserve_slot_assignments
|
||||
else {}
|
||||
)
|
||||
majors_by_index: Dict[int, MajorStep] = {}
|
||||
if roadmap_ctx.roadmap:
|
||||
majors_by_index = {m.index: m for m in roadmap_ctx.roadmap.major_steps}
|
||||
@@ -1579,7 +1620,7 @@ def suggest_progression_path(
|
||||
semantic_brief=semantic_brief,
|
||||
path_target_profile=path_target_profile,
|
||||
path_intent=path_intent,
|
||||
supplemental_exercise_ids=_supplemental_exercise_ids_from_body(body),
|
||||
supplemental_exercise_ids=_supplemental_exercise_ids_from_body(cur, body),
|
||||
)
|
||||
|
||||
hit = _pick_best_path_hit(hits, used, semantic_brief=semantic_brief)
|
||||
@@ -1640,7 +1681,7 @@ def suggest_progression_path(
|
||||
planned_ids=planned_ids,
|
||||
path_target_profile=path_target_profile,
|
||||
path_intent=path_intent,
|
||||
supplemental_exercise_ids=_supplemental_exercise_ids_from_body(body),
|
||||
supplemental_exercise_ids=_supplemental_exercise_ids_from_body(cur, body),
|
||||
)
|
||||
steps, bridge_inserts, unfilled_gaps = insert_bridge_exercises(
|
||||
cur,
|
||||
@@ -1683,7 +1724,11 @@ def suggest_progression_path(
|
||||
goal_query=goal_query,
|
||||
)
|
||||
off_topic_before_strip = list(off_topic_steps)
|
||||
steps, stripped_off_topic = strip_off_topic_steps_from_path(steps, off_topic_steps)
|
||||
steps, stripped_off_topic = strip_off_topic_steps_from_path(
|
||||
steps,
|
||||
off_topic_steps,
|
||||
min_remaining=0 if roadmap_first else 2,
|
||||
)
|
||||
if stripped_off_topic:
|
||||
off_topic_steps = []
|
||||
gaps = detect_path_gaps(
|
||||
|
||||
Reference in new issue
Block a user