Configuration

On this page

All configuration lives in router/config as a tree of dataclasses rooted at RouterConfig. Pass a fully or partially customized RouterConfig to HierarchicalRouter(config=...); any sub-config left as default uses the dataclass field defaults shown below.

Python · 7 lines
from zerda.router import RouterConfig, ScoringConfig, ExecutionConfig, ExecutionMode

config = RouterConfig(
    scoring=ScoringConfig(semantic_weight=0.8, keyword_weight=0.2, llm_weight=0.0),
    execution=ExecutionConfig(mode=ExecutionMode.SEQUENTIAL),
)
router = HierarchicalRouter(config=config)

RouterConfig

The single entry point aggregating every sub-config, plus top-level LLM fallback and no-match behavior settings.

FieldTypeDefaultPurpose
embeddingEmbeddingConfigEmbeddingConfig()Embedding model settings.
scoringScoringConfigScoringConfig()Hybrid scorer weights and confidence thresholds.
executionExecutionConfigExecutionConfig()How matched routes are executed.
cacheCacheConfigCacheConfig()Route-decision cache behavior.
feedbackFeedbackConfigFeedbackConfig()Adaptive feedback loop behavior.
observabilityObservabilityConfigObservabilityConfig()Logging, tracing, metrics.
llm_modelOptional[str]NoneModel name/endpoint passed to LLMScorer. If unset, no LLM fallback scorer is built.
llm_api_keyOptional[str]NoneAPI key passed to LLMScorer's openai.OpenAI client.
raise_on_no_matchboolFalseIf True, route_query raises LookupError when no route matches (and no fallback handler is set). If False, returns a failed RoutingResult instead.

Presets

Two classmethods construct commonly-used configurations:

RouterConfig.fast() — optimized for latency: scoring.top_k = 1, execution.mode = ExecutionMode.SINGLE, cache.enabled = True.

RouterConfig.accurate() — optimized for accuracy: scoring.top_k = 3, execution.mode = ExecutionMode.PARALLEL, scoring.llm_weight = 0.20, scoring.semantic_weight = 0.60.

Python
router = HierarchicalRouter(config=RouterConfig.fast())

EmbeddingConfig

Controls the embedding model used for semantic scoring.

FieldTypeDefaultPurpose
model_namestr"sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"Model name passed to SentenceTransformer(...).
batch_sizeint32Batch size used in encode_batch.
cache_embeddingsboolTrueDocumented as controlling embedding caching; the flag is a declared field, but EmbeddingProvider's actual use_cache parameter defaults independently per-call (encode/encode_batch default use_cache=True) rather than reading this field directly — verify against your version if you depend on this being wired through.
normalize_embeddingsboolTrueDocumented as controlling L2 normalization; EmbeddingProvider.encode calls self._model.encode(..., normalize_embeddings=True) unconditionally rather than referencing this field — same caveat as above.

[!WARNING] Fields not directly read Static analysis of routing/pipeline.py shows EmbeddingProvider hard-codes normalize_embeddings=True in its calls to SentenceTransformer.encode, rather than consulting EmbeddingConfig.normalize_embeddings. Likewise, cache usage defaults are controlled by each method's own use_cache parameter, not read from EmbeddingConfig.cache_embeddings. These fields exist on the dataclass but are not observed to be consumed by EmbeddingProvider in the analyzed source — documented here explicitly rather than assumed to work, per this documentation's no-hallucination policy.

ScoringConfig

Weights and thresholds for the hybrid scorer.

FieldTypeDefaultPurpose
semantic_weightfloat0.70Relative weight of embedding similarity.
keyword_weightfloat0.20Relative weight of keyword signals.
llm_weightfloat0.10Relative weight of the optional LLM scorer (only applied if RouterConfig.llm_model is set).
similarity_metricSimilarityMetricCOSINEWhich similarity function SemanticScorer uses.
high_confidence_thresholdfloat0.85Combined score at/above which confidence is HIGH.
medium_confidence_thresholdfloat0.60Combined score at/above which confidence is MEDIUM.
fallback_confidence_thresholdfloat0.40Combined score at/above which confidence is LOW; below this it's NONE, and it's also the trigger point for invoking the LLM scorer.
top_kint5Number of candidate routes surfaced by the pipeline (post-scoring).

The three weight fields are normalized to sum to 1 inside HybridScorer.__init__ — you don't need to make them sum to 1 yourself, but their ratios to each other determine relative influence.

ExecutionConfig

Controls how matched routes are executed.

FieldTypeDefaultPurpose
modeExecutionModeSINGLESINGLE, SEQUENTIAL, or PARALLEL.
aggregationAggregationStrategyFIRST_WINSUsed to select the aggregator (FirstWinsAggregator vs MergeAggregator) when HierarchicalRouter is constructed. Only "merge" maps to MergeAggregator; any other value (including VOTING) falls back to FirstWinsAggregator in the analyzed source — there is no dedicated voting-aggregator implementation.
parallel_timeoutfloat10.0Seconds before parallel execution (ThreadPoolExecutor.as_completed / asyncio.wait_for) times out.
max_retriesint2Max attempts per handler call (_with_retry).
retry_delayfloat0.5Seconds slept between retry attempts.
retry_on_exceptionsList[str]["RuntimeError", "TimeoutError"]Substrings checked against HandlerResponse.error; a retry only proceeds if one of these substrings appears in the error message (see _with_retry).

[!WARNING] AggregationStrategy.VOTING is declared but not implemented AggregationStrategy.VOTING = "voting" exists as an enum value, but HierarchicalRouter.__init__'s aggregator-selection logic only checks self._cfg.execution.aggregation.value == "merge"; any other value (including "voting") results in FirstWinsAggregator being used. No VotingAggregator class exists in the analyzed source.

CacheConfig

Controls the route-decision cache (CacheManager).

FieldTypeDefaultPurpose
enabledboolTrueMaster on/off switch for CacheManager.get_decision / set_decision.
ttl_secondsint300Time-to-live for cached route decisions.
max_sizeint1000Max entries before LRU eviction.
embedding_cacheboolTrueDeclared field for enabling the embedding cache; note the embedding cache in EmbeddingProvider is a separate, always-on dict cache not observed to read this flag directly — see the EmbeddingConfig warning above for the same caveat pattern.
embedding_ttlint3600Declared TTL for embedding cache entries; EmbeddingProvider's internal cache dict has no TTL/eviction logic in the analyzed source (it is only cleared in full via clear_cache()), so this field's effect could not be confirmed from the implementation.

FeedbackConfig

Controls the adaptive feedback loop (FeedbackEngine).

FieldTypeDefaultPurpose
enabledboolTrueMaster on/off switch — record() and apply_biases() both no-op when False.
score_decayfloat0.05Declared field described as controlling per-tick score shift; FeedbackEngine uses a separate alpha constructor parameter (default 0.1) for its EMA update rather than reading score_decay — not observed to be consumed in the analyzed source.
min_samples_to_adaptint10Minimum n_samples a route needs before apply_biases will update its score_bias.
persist_pathOptional[str]NoneJSON file path for FeedbackEngine.save() / auto-load on construction, and for HierarchicalRouter.__exit__'s auto-save.

ObservabilityConfig

Controls logging, tracing, and metrics.

FieldTypeDefaultPurpose
log_levelLogLevelINFOPassed to logging.getLogger(...).setLevel(...) in RouterLogger.
structured_loggingboolTrueIf True, log lines are emitted as single-line JSON via _JsonFormatter; otherwise a standard human-readable formatter is used.
enable_tracingboolTrueDeclared field; RoutingTrace objects are constructed and populated unconditionally by RoutingPipeline.run in the analyzed source — this flag was not observed to gate trace construction.
metrics_windowint1000Max length of the rolling-window deques in MetricsCollector (latencies, confidences, matches) and the cap applied to per-route latency lists.
slow_route_msfloat500.0Threshold above which RouterLogger.log_routing_decision emits a slow_route_detected warning.

Enumerations

SimilarityMetric

ValueMeaning
COSINECosine similarity (SemanticScorer._cosine).
DOT_PRODUCTRaw dot product — assumes inputs are already L2-normalized (SemanticScorer._dot_product).
EUCLIDEANEuclidean distance converted to a similarity via 1 / (1 + distance) (SemanticScorer._euclidean_to_similarity).

ExecutionMode

ValueMeaning
SINGLEExecute only the best-ranked candidate.
SEQUENTIALTry candidates in ranked order, stop at first success.
PARALLELExecute all candidates concurrently, then aggregate.

AggregationStrategy

ValueMeaning
FIRST_WINSReturn the first successful response (default; also the fallback for any unrecognized value).
VOTINGDeclared but not implemented as a distinct aggregator — see the warning under ExecutionConfig above.
MERGEMerge all successful responses' content into a list (MergeAggregator).

ConfidenceLevel

ValueMeaning
HIGHScore ≥ high_confidence_threshold — route directly.
MEDIUMScore ≥ medium_confidence_threshold — route, typically with a note.
LOWScore ≥ fallback_confidence_threshold — route via LLM fallback territory.
NONEBelow all thresholds — global fallback / no-match path.

LogLevel

DEBUG, INFO, WARNING, ERROR — maps 1:1 to Python's logging level names via getattr(logging, cfg.log_level.value, logging.INFO).

Next steps

See Advanced Usage for streaming, tool chaining, and feedback-tuning walkthroughs, or the API Reference for exhaustive per-class documentation.

Related pages