complexity
diapason.learning.routing.complexity
¶
Query complexity analyzer — scores queries and suggests token budgets.
Produces a numeric complexity score (0.0–1.0) and a suggested
max_tokens budget based on query characteristics such as length,
domain signals (code, math, multi-step reasoning), and whether the
target model is a thinking model that needs extra headroom.
ComplexityQueryAnalyzer
¶
Bases: QueryAnalyzer
Query analyzer that produces a complexity-aware RoutingContext.
Drop-in replacement for DefaultQueryAnalyzer — adds
complexity_score, has_reasoning, and suggested_max_tokens
to the returned RoutingContext.
ComplexityResult
dataclass
¶
Output of the complexity analysis.
adjust_tokens_for_model(suggested, model_name=None)
¶
Multiply the token budget when the target is a thinking model.
is_thinking_model(model_name)
¶
Return True if the model is known to use internal chain-of-thought.
score_complexity(query)
¶
Score a query's complexity from 0.0 (trivial) to 1.0 (very complex).
The score is a weighted combination of independent signals, each contributing a fraction between 0 and 1. Weights reflect how much each signal correlates with the amount of reasoning and output tokens a model will need.