Query Classifier¶
The query classifier routes each retrieval query to a per-type weight profile, enabling the engine to apply different retrieval strategies depending on whether the query targets an emotion state, an affect-conditioned topic, or a temporal trajectory.
See also: tutorial — query routing for end-to-end usage,
LOCOMO_ROUTING for the pre-registered weight table from Addendum L, and
QueryClassifierConfig on RetrievalConfig.query_classifier.
Protocol¶
emotional_memory.query_classifier.QueryClassifier
¶
Bases: Protocol
Classifies a query string into a named query-type label.
classify(query: str) -> str
¶
Return a query-type label (e.g. 'single_hop', 'temporal').
Unknown labels are safe — the engine falls back to default_type.
Built-in Classifiers¶
emotional_memory.query_classifier.HeuristicQueryClassifier
¶
Regex/keyword routing — ~0 overhead, deterministic.
Priority: temporal > multi_hop > single_hop > open_domain (default).
emotional_memory.query_classifier.LLMQueryClassifier(llm: LLMCallable, *, cache_size: int = 256, default_type: str = 'open_domain', fallback_on_error: bool = True)
¶
LLM-backed query classifier mirroring LLMAppraisalEngine pattern.
Thread-safe SHA-256 LRU cache; cache_size=0 disables caching. Falls back
to default_type on error when fallback_on_error=True (default);
fallbacks are never cached, so a transient LLM failure does not pin the
default type for that query.