Enhance Planning Exercise Suggestion and Ranking Logic
Deploy Development / deploy (push) Successful in 46s
Test Suite / pytest-backend (push) Successful in 40s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m16s
Deploy Development / deploy (push) Successful in 46s
Test Suite / pytest-backend (push) Successful in 40s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m16s
- Introduced a new function `hybrid_ranking_ambiguous` to determine when to rerank candidates based on score proximity, improving the decision-making process for exercise suggestions. - Updated `should_run_llm_rank_pipeline` to incorporate the new ranking logic and handle scenarios with ambiguous rankings more effectively. - Adjusted the frontend to always include LLM ranking in requests, ensuring consistent behavior across different query lengths. - Incremented version to 0.8.182 and updated changelog to reflect these enhancements in planning AI capabilities.
This commit is contained in:
1 parent
a0a891e550
commit
50aff849d8
5 files changed
+95
-19
No files matched your search
@@ -10,7 +10,7 @@ Ablauf:
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Any, Dict, List, Mapping, Optional, Tuple
|
||||
from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple
|
||||
|
||||
from planning_exercise_expectation import try_build_planning_expectation_from_context
|
||||
from planning_exercise_intent import (
|
||||
@@ -135,6 +135,31 @@ def deterministic_rank_confident(hits: Sequence[Mapping[str, Any]], *, gap_thres
|
||||
return (top - fourth) >= gap_threshold
|
||||
|
||||
|
||||
def hybrid_ranking_ambiguous(
|
||||
hits: Sequence[Mapping[str, Any]],
|
||||
*,
|
||||
top_four_gap: float = 0.08,
|
||||
top_ten_gap: float = 0.055,
|
||||
) -> bool:
|
||||
"""True wenn Top-Kandidaten scores zu nah beieinander liegen — Rerank lohnt sich."""
|
||||
if len(hits) < 3:
|
||||
return False
|
||||
top = float(hits[0].get("score") or 0.0)
|
||||
if len(hits) >= 4:
|
||||
fourth = float(hits[3].get("score") or 0.0)
|
||||
if (top - fourth) < top_four_gap:
|
||||
return True
|
||||
if len(hits) >= 10:
|
||||
tenth = float(hits[9].get("score") or 0.0)
|
||||
if (top - tenth) < top_ten_gap:
|
||||
return True
|
||||
elif len(hits) >= 2:
|
||||
tail = float(hits[min(len(hits) - 1, 9)].get("score") or 0.0)
|
||||
if (top - tail) < top_four_gap:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def should_run_llm_rank_pipeline(
|
||||
query: Optional[str],
|
||||
scenario: str,
|
||||
@@ -142,26 +167,38 @@ def should_run_llm_rank_pipeline(
|
||||
include_llm_rank: bool,
|
||||
query_intent_applied: bool,
|
||||
llm_expectation_applied: bool = False,
|
||||
has_planning_reference: bool = True,
|
||||
hits: Sequence[Mapping[str, Any]],
|
||||
) -> bool:
|
||||
"""
|
||||
Maximal ein LLM-Call pro Request: wenn Intent- oder Erwartungs-LLM lief, kein Rerank.
|
||||
Rerank nur bei längerer, komplexer Anfrage und unklarem Hybrid-Ranking.
|
||||
Phase B2: Rerank bei unklarem Hybrid-Ranking — auch nach Erwartungs-/Intent-LLM.
|
||||
|
||||
Budget: max. 2 LLM-Calls pro Suche (Profil-LLM + optional Rerank).
|
||||
"""
|
||||
if not include_llm_rank:
|
||||
return False
|
||||
if query_intent_applied or llm_expectation_applied:
|
||||
if len(hits) < 3:
|
||||
return False
|
||||
if scenario == SCENARIO_PRESET_NEXT:
|
||||
if not hybrid_ranking_ambiguous(hits):
|
||||
return False
|
||||
|
||||
q = _normalize_query(query)
|
||||
if not q:
|
||||
return False
|
||||
profile_llm = query_intent_applied or llm_expectation_applied
|
||||
|
||||
if scenario == SCENARIO_PRESET_NEXT:
|
||||
return has_planning_reference
|
||||
|
||||
if scenario == SCENARIO_FREE_SEARCH:
|
||||
if len(q) < 10 and not profile_llm:
|
||||
return False
|
||||
return True
|
||||
|
||||
if scenario == SCENARIO_ADDITIVE:
|
||||
return len(q) >= 12 and not deterministic_rank_confident(hits)
|
||||
if len(q) < 22:
|
||||
return False
|
||||
return not deterministic_rank_confident(hits)
|
||||
return len(q) >= 8 or profile_llm
|
||||
|
||||
if profile_llm:
|
||||
return True
|
||||
return len(q) >= 14
|
||||
|
||||
|
||||
def _recalculate_skill_gap(target: PlanningTargetProfile) -> PlanningTargetProfile:
|
||||
@@ -420,4 +457,5 @@ __all__ = [
|
||||
"should_run_llm_intent_pipeline",
|
||||
"should_run_llm_rank_pipeline",
|
||||
"deterministic_rank_confident",
|
||||
"hybrid_ranking_ambiguous",
|
||||
]
|
||||
Reference in new issue
Block a user