[Router] 2381 semantic_similarity classifier (M5)#2482
[Router] 2381 semantic_similarity classifier (M5)#2482SlawomirNowaczyk wants to merge 2 commits into
Conversation
eddierichter-amd
left a comment
There was a problem hiding this comment.
This looks great! Only feedback is can you add the RoutingPolicySemanticTest to the CI?
Thanks, I forgot about it. Should be done now :) |
|
Thanks for this — it's clean and was approved, but we're consolidating #2381 on the unified version in #2483, which builds on this work and additionally collapses No action needed here. I'll close this once #2483 merges (it carries your initial commit forward). |
|
Made obsolete by #2483 |
Implements the
semantic_similarityclassifier — the first model-backed classifier in the generic routing engine — against the existingClassifierinterface. It scores an input by max cosine similarity against a set ofreference_phrases, reported as a single score under the empty-string key and consumed via a classifier-band condition. Closes #2381.Changes
SemanticSimilarityClassifier(routing_policy.cpp): embeds the input viaClassifierServices::embed, computes cosine against each reference exemplar, and returnsmaxasScore::labels[""](read by conditions throughScore::primary()). Declares no labels.make_classifier):semantic_similaritynow constructs the real classifier instead of throwing "not implemented". Requiresmodel+ non-emptyreference_phrases; rejectslabels/default_label.Score::ok = falseso the owning band applies itson_errorpolicy rather than letting an exception escape.FakeClassifierServiceswith per-(model, text)embeddings and embed call counters; addedtest_routing_policy_semantic.cppcovering max-cosine selection, reference-phrase caching (embed-once), inclusive band boundaries incl. the defaultmin_score: 0.5, andon_error; updated the registry test for the now-accepted type.Notes
[0,1]to satisfy the band contract (guards against floating-point overshoot past 1.0 for near-identical vectors).embed()↔ Router wiring ([Router] ClassifierServices to Router wiring (M-svc) #2384) and the other classifier types (classifier/llm). No schema change — the existing route_policy.schema.json already describesreference_phrases.Testing
ctest -R RoutingPolicy— all four suites (Contract,Evaluator,Registry,Semantic) pass.