Implement Roadmap-First Retrieval and Enhance Planning AI Features
Deploy Development / deploy (push) Successful in 43s
Test Suite / pytest-backend (push) Successful in 43s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m26s
Deploy Development / deploy (push) Successful in 43s
Test Suite / pytest-backend (push) Successful in 43s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m26s
- Introduced a roadmap-first approach for retrieval, allowing for structured exercise suggestions based on stage specifications and major steps. - Added functionality to generate gap-fill offers for unfilled roadmap stages, improving the relevance of exercise recommendations. - Updated the `ExerciseProgressionPathBuilder` to support the new roadmap-first feature, enhancing user experience with clearer exercise paths. - Incremented application version to 0.8.206 and updated the database schema version to reflect these changes.
This commit is contained in:
1 parent
7411543a97
commit
d4e9bded23
10 files changed
+431
-52
No files matched your search
@@ -23,7 +23,11 @@ from planning_exercise_path_qa import (
|
||||
strip_off_topic_steps_from_path,
|
||||
try_llm_qa_progression_path,
|
||||
)
|
||||
from planning_exercise_path_ai_fill import apply_gap_fill_after_qa, collect_gap_fill_specs
|
||||
from planning_exercise_path_ai_fill import (
|
||||
apply_gap_fill_after_qa,
|
||||
build_gap_fill_offer,
|
||||
collect_gap_fill_specs,
|
||||
)
|
||||
from planning_exercise_retrieval import run_multistage_planning_retrieval
|
||||
from planning_exercise_semantics import (
|
||||
PlanningSemanticBrief,
|
||||
@@ -47,8 +51,14 @@ from planning_exercise_suggest import (
|
||||
resolve_planning_exercise_intent,
|
||||
)
|
||||
from planning_progression_roadmap import (
|
||||
MajorStep,
|
||||
ProgressionRoadmapContext,
|
||||
StageSpecArtifact,
|
||||
build_roadmap_unfilled_gap_specs,
|
||||
progression_roadmap_to_api_dict,
|
||||
resolve_step_exercise_kind_filter,
|
||||
run_progression_roadmap_pipeline,
|
||||
stage_spec_retrieval_query,
|
||||
)
|
||||
from routers.training_planning import _has_planning_role
|
||||
|
||||
@@ -169,8 +179,12 @@ def _run_path_step_retrieval(
|
||||
step_b: Optional[Dict[str, Any]] = None,
|
||||
path_target_profile: Optional[PlanningTargetProfile] = None,
|
||||
path_intent: Optional[str] = None,
|
||||
step_query_override: Optional[str] = None,
|
||||
step_phase_override: Optional[str] = None,
|
||||
) -> Tuple[List[Dict[str, Any]], PlanningTargetProfile, Dict[str, Any], str]:
|
||||
step_query = step_retrieval_query(semantic_brief, goal_query, step_index, max_steps)
|
||||
step_query = step_query_override or step_retrieval_query(
|
||||
semantic_brief, goal_query, step_index, max_steps
|
||||
)
|
||||
if bridge_mode and step_a and step_b:
|
||||
phase = step_phase_for_index(semantic_brief, step_index, max_steps)
|
||||
parts = [semantic_brief.primary_topic or semantic_brief.retrieval_query or goal_query]
|
||||
@@ -200,7 +214,8 @@ def _run_path_step_retrieval(
|
||||
"has_planning_reference": bool(planned_ids or anchor_id or bridge_mode),
|
||||
"semantic_brief": semantic_brief,
|
||||
"retrieval_query": step_query,
|
||||
"path_step_phase": step_phase_for_index(semantic_brief, step_index, max_steps),
|
||||
"path_step_phase": step_phase_override
|
||||
or step_phase_for_index(semantic_brief, step_index, max_steps),
|
||||
}
|
||||
pack = apply_progression_context_to_pack(
|
||||
cur,
|
||||
@@ -331,6 +346,130 @@ def _make_bridge_search_fn(
|
||||
return _bridge_search
|
||||
|
||||
|
||||
def _annotate_roadmap_step(
|
||||
step: Dict[str, Any],
|
||||
*,
|
||||
stage_spec: StageSpecArtifact,
|
||||
major_step: Optional[MajorStep],
|
||||
) -> Dict[str, Any]:
|
||||
reasons = list(step.get("reasons") or [])
|
||||
learning_goal = (stage_spec.learning_goal or "").strip()
|
||||
if learning_goal:
|
||||
roadmap_reason = f"Roadmap: {learning_goal[:120]}"
|
||||
if roadmap_reason not in reasons:
|
||||
reasons.insert(0, roadmap_reason)
|
||||
step["reasons"] = reasons[:4]
|
||||
step["roadmap_major_step_index"] = stage_spec.major_step_index
|
||||
step["roadmap_phase"] = major_step.phase if major_step else None
|
||||
step["roadmap_learning_goal"] = learning_goal or None
|
||||
step["roadmap_match_source"] = "stage_spec"
|
||||
return step
|
||||
|
||||
|
||||
def _build_steps_roadmap_first(
|
||||
cur,
|
||||
*,
|
||||
tenant: TenantContext,
|
||||
body: ProgressionPathSuggestRequest,
|
||||
goal_query: str,
|
||||
max_steps: int,
|
||||
semantic_brief: PlanningSemanticBrief,
|
||||
path_target_profile: PlanningTargetProfile,
|
||||
path_intent: str,
|
||||
roadmap_ctx: ProgressionRoadmapContext,
|
||||
) -> Tuple[List[Dict[str, Any]], List[Tuple[int, StageSpecArtifact]]]:
|
||||
"""Retrieval pro stage_spec statt iterativem Pfad-Bau (Phase F3)."""
|
||||
stage_specs = list(roadmap_ctx.stage_specs or [])[:max_steps]
|
||||
if not stage_specs and roadmap_ctx.roadmap:
|
||||
stage_specs = [
|
||||
StageSpecArtifact(
|
||||
major_step_index=m.index,
|
||||
learning_goal=m.learning_goal,
|
||||
)
|
||||
for m in roadmap_ctx.roadmap.major_steps[:max_steps]
|
||||
]
|
||||
|
||||
major_by_index: Dict[int, MajorStep] = {}
|
||||
if roadmap_ctx.roadmap:
|
||||
major_by_index = {m.index: m for m in roadmap_ctx.roadmap.major_steps}
|
||||
|
||||
used: Set[int] = set()
|
||||
steps: List[Dict[str, Any]] = []
|
||||
planned_ids: List[int] = []
|
||||
anchor_id: Optional[int] = None
|
||||
anchor_variant_id: Optional[int] = None
|
||||
unfilled: List[Tuple[int, StageSpecArtifact]] = []
|
||||
|
||||
for step_index, stage_spec in enumerate(stage_specs):
|
||||
major = major_by_index.get(stage_spec.major_step_index)
|
||||
step_query = stage_spec_retrieval_query(
|
||||
semantic_brief=semantic_brief,
|
||||
goal_query=goal_query,
|
||||
stage_spec=stage_spec,
|
||||
major_step=major,
|
||||
)
|
||||
step_kind = resolve_step_exercise_kind_filter(stage_spec, body.exercise_kind_any)
|
||||
|
||||
hits, _, _, _ = _run_path_step_retrieval(
|
||||
cur,
|
||||
tenant=tenant,
|
||||
goal_query=goal_query,
|
||||
step_index=step_index,
|
||||
max_steps=max_steps,
|
||||
planned_ids=planned_ids,
|
||||
anchor_id=anchor_id,
|
||||
anchor_variant_id=anchor_variant_id,
|
||||
progression_graph_id=body.progression_graph_id,
|
||||
include_llm_intent=body.include_llm_intent and step_index == 0,
|
||||
exercise_kind_any=step_kind,
|
||||
semantic_brief=semantic_brief,
|
||||
path_target_profile=path_target_profile,
|
||||
path_intent=path_intent,
|
||||
step_query_override=step_query,
|
||||
step_phase_override=major.phase if major else None,
|
||||
)
|
||||
|
||||
hit = _pick_best_path_hit(hits, used, semantic_brief=semantic_brief)
|
||||
if not hit and step_query != goal_query:
|
||||
hits, _, _, _ = _run_path_step_retrieval(
|
||||
cur,
|
||||
tenant=tenant,
|
||||
goal_query=goal_query,
|
||||
step_index=step_index,
|
||||
max_steps=max_steps,
|
||||
planned_ids=planned_ids,
|
||||
anchor_id=anchor_id,
|
||||
anchor_variant_id=anchor_variant_id,
|
||||
progression_graph_id=body.progression_graph_id,
|
||||
include_llm_intent=False,
|
||||
exercise_kind_any=step_kind,
|
||||
semantic_brief=semantic_brief,
|
||||
path_target_profile=path_target_profile,
|
||||
path_intent=path_intent,
|
||||
step_query_override=goal_query,
|
||||
step_phase_override=major.phase if major else None,
|
||||
)
|
||||
hit = _pick_best_path_hit(hits, used, semantic_brief=semantic_brief)
|
||||
|
||||
if not hit:
|
||||
unfilled.append((step_index, stage_spec))
|
||||
continue
|
||||
|
||||
step = _annotate_roadmap_step(
|
||||
_hit_to_path_step(hit),
|
||||
stage_spec=stage_spec,
|
||||
major_step=major,
|
||||
)
|
||||
steps.append(step)
|
||||
eid = int(step["exercise_id"])
|
||||
used.add(eid)
|
||||
planned_ids.append(eid)
|
||||
anchor_id = eid
|
||||
anchor_variant_id = step.get("variant_id")
|
||||
|
||||
return steps, unfilled
|
||||
|
||||
|
||||
def suggest_progression_path(
|
||||
cur,
|
||||
*,
|
||||
@@ -360,41 +499,98 @@ def suggest_progression_path(
|
||||
include_llm_intent=body.include_llm_intent,
|
||||
)
|
||||
|
||||
roadmap_first = bool(body.roadmap_first)
|
||||
include_roadmap = roadmap_first or body.include_roadmap_preview
|
||||
progression_roadmap: Optional[Dict[str, Any]] = None
|
||||
roadmap_ctx: Optional[ProgressionRoadmapContext] = None
|
||||
roadmap_unfilled: List[Tuple[int, StageSpecArtifact]] = []
|
||||
roadmap_gap_offers: List[Dict[str, Any]] = []
|
||||
|
||||
if include_roadmap:
|
||||
roadmap_ctx = run_progression_roadmap_pipeline(
|
||||
goal_query,
|
||||
max_steps=max_steps,
|
||||
semantic_brief=semantic_brief,
|
||||
cur=cur,
|
||||
include_llm_roadmap=body.include_llm_roadmap,
|
||||
)
|
||||
progression_roadmap = progression_roadmap_to_api_dict(roadmap_ctx)
|
||||
|
||||
used: Set[int] = set()
|
||||
steps: List[Dict[str, Any]] = []
|
||||
planned_ids: List[int] = []
|
||||
anchor_id: Optional[int] = None
|
||||
anchor_variant_id: Optional[int] = None
|
||||
|
||||
for step_index in range(max_steps):
|
||||
hits, _tp, _qis, _intent = _run_path_step_retrieval(
|
||||
if roadmap_first and roadmap_ctx is not None:
|
||||
steps, roadmap_unfilled = _build_steps_roadmap_first(
|
||||
cur,
|
||||
tenant=tenant,
|
||||
body=body,
|
||||
goal_query=goal_query,
|
||||
step_index=step_index,
|
||||
max_steps=max_steps,
|
||||
planned_ids=planned_ids,
|
||||
anchor_id=anchor_id,
|
||||
anchor_variant_id=anchor_variant_id,
|
||||
progression_graph_id=body.progression_graph_id,
|
||||
include_llm_intent=body.include_llm_intent,
|
||||
exercise_kind_any=body.exercise_kind_any,
|
||||
semantic_brief=semantic_brief,
|
||||
path_target_profile=path_target_profile,
|
||||
path_intent=path_intent,
|
||||
roadmap_ctx=roadmap_ctx,
|
||||
)
|
||||
planned_ids = [int(s["exercise_id"]) for s in steps if s.get("exercise_id") is not None]
|
||||
if planned_ids:
|
||||
anchor_id = planned_ids[-1]
|
||||
anchor_variant_id = steps[-1].get("variant_id")
|
||||
if body.include_ai_gap_fill and roadmap_unfilled:
|
||||
major_by_index = (
|
||||
{m.index: m for m in roadmap_ctx.roadmap.major_steps}
|
||||
if roadmap_ctx.roadmap
|
||||
else {}
|
||||
)
|
||||
roadmap_gap_specs = build_roadmap_unfilled_gap_specs(
|
||||
unfilled_specs=roadmap_unfilled,
|
||||
major_steps_by_index=major_by_index,
|
||||
steps=steps,
|
||||
brief=semantic_brief,
|
||||
goal_query=goal_query,
|
||||
)
|
||||
for spec in roadmap_gap_specs:
|
||||
roadmap_gap_offers.append(
|
||||
build_gap_fill_offer(
|
||||
spec=spec,
|
||||
steps=steps,
|
||||
goal_query=goal_query,
|
||||
brief=semantic_brief,
|
||||
proposal=None,
|
||||
)
|
||||
)
|
||||
else:
|
||||
for step_index in range(max_steps):
|
||||
hits, _tp, _qis, _intent = _run_path_step_retrieval(
|
||||
cur,
|
||||
tenant=tenant,
|
||||
goal_query=goal_query,
|
||||
step_index=step_index,
|
||||
max_steps=max_steps,
|
||||
planned_ids=planned_ids,
|
||||
anchor_id=anchor_id,
|
||||
anchor_variant_id=anchor_variant_id,
|
||||
progression_graph_id=body.progression_graph_id,
|
||||
include_llm_intent=body.include_llm_intent,
|
||||
exercise_kind_any=body.exercise_kind_any,
|
||||
semantic_brief=semantic_brief,
|
||||
path_target_profile=path_target_profile,
|
||||
path_intent=path_intent,
|
||||
)
|
||||
|
||||
hit = _pick_best_path_hit(hits, used, semantic_brief=semantic_brief)
|
||||
if not hit:
|
||||
break
|
||||
hit = _pick_best_path_hit(hits, used, semantic_brief=semantic_brief)
|
||||
if not hit:
|
||||
break
|
||||
|
||||
step = _hit_to_path_step(hit)
|
||||
steps.append(step)
|
||||
eid = int(step["exercise_id"])
|
||||
used.add(eid)
|
||||
planned_ids.append(eid)
|
||||
anchor_id = eid
|
||||
anchor_variant_id = step.get("variant_id")
|
||||
step = _hit_to_path_step(hit)
|
||||
steps.append(step)
|
||||
eid = int(step["exercise_id"])
|
||||
used.add(eid)
|
||||
planned_ids.append(eid)
|
||||
anchor_id = eid
|
||||
anchor_variant_id = step.get("variant_id")
|
||||
|
||||
if len(steps) < 2:
|
||||
raise HTTPException(
|
||||
@@ -490,6 +686,12 @@ def suggest_progression_path(
|
||||
auto_insert_proposals=False,
|
||||
)
|
||||
|
||||
if roadmap_gap_offers:
|
||||
seen_offer_ids = {o.get("offer_id") for o in gap_fill_offers}
|
||||
for offer in roadmap_gap_offers:
|
||||
if offer.get("offer_id") not in seen_offer_ids:
|
||||
gap_fill_offers.append(offer)
|
||||
|
||||
path_qa = build_path_qa_summary(
|
||||
gaps=gaps,
|
||||
bridge_inserts=bridge_inserts,
|
||||
@@ -505,6 +707,8 @@ def suggest_progression_path(
|
||||
|
||||
target_profile_summary = path_target_profile.to_summary_dict(cur)
|
||||
retrieval_parts = ["profile_v1", "full_library", "path_builder", "semantics"]
|
||||
if roadmap_first:
|
||||
retrieval_parts.append("roadmap_first")
|
||||
if body.include_path_qa:
|
||||
retrieval_parts.append("path_qa")
|
||||
if llm_qa_applied:
|
||||
@@ -515,20 +719,10 @@ def suggest_progression_path(
|
||||
retrieval_parts.append("ai_gap_fill")
|
||||
if gap_fill_offers:
|
||||
retrieval_parts.append("gap_fill_offers")
|
||||
|
||||
progression_roadmap: Optional[Dict[str, Any]] = None
|
||||
if body.include_roadmap_preview or body.roadmap_first:
|
||||
roadmap_ctx = run_progression_roadmap_pipeline(
|
||||
goal_query,
|
||||
max_steps=max_steps,
|
||||
semantic_brief=semantic_brief,
|
||||
cur=cur,
|
||||
include_llm_roadmap=body.include_llm_roadmap,
|
||||
)
|
||||
progression_roadmap = progression_roadmap_to_api_dict(roadmap_ctx)
|
||||
if include_roadmap:
|
||||
retrieval_parts.append("roadmap_preview")
|
||||
if body.roadmap_first:
|
||||
retrieval_parts.append("roadmap_first_pending")
|
||||
if roadmap_unfilled:
|
||||
retrieval_parts.append("roadmap_unfilled")
|
||||
|
||||
return {
|
||||
"goal_query": goal_query,
|
||||
@@ -543,7 +737,8 @@ def suggest_progression_path(
|
||||
"path_qa": path_qa,
|
||||
"gap_fill_offers": gap_fill_offers,
|
||||
"progression_roadmap": progression_roadmap,
|
||||
"roadmap_first": body.roadmap_first,
|
||||
"roadmap_first": roadmap_first,
|
||||
"roadmap_unfilled_count": len(roadmap_unfilled),
|
||||
"retrieval_phase": "+".join(retrieval_parts),
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user