Embedding Similarity vs Decision Models: Retrieve With Cosine Scores, Decide With Rules or Thresholds
A cosine similarity score measures how alike two texts are, not whether an action is correct. Use embeddings to find candidates, then decide with rules, a calibrated classifier or an option scorer.
Embedding similarity measures how alike two pieces of text are, and a decision model chooses an outcome or an action. A cosine similarity score from Sentence Transformers is not a calibrated probability that a request is correct, eligible or safe to act on. Use embeddings to retrieve relevant policies, examples or options. Then make the decision with explicit rules, a classifier whose threshold is tuned against the cost of each error, or a model that scores a fixed list of allowed actions.
The two ideas come from two different bodies of documentation. The Sentence Transformers guide to semantic textual similarity covers cosine scores between embeddings. The scikit-learn guide to tuning the decision threshold covers how a predicted probability becomes an action. Most systems that route requests need both, in separate stages.
Similarity, classification, ranking, probability and policy answer five different questions
The following table separates the methods that are often grouped under "embedding similarity vs decision models".
| Method | Question it answers | Typical output | What the output does not mean |
|---|---|---|---|
| Cosine similarity of embeddings | How alike are these two texts? | One score per pair | Correctness or eligibility |
| Semantic retrieval | Which stored items are closest to this query? | A ranked list of items with scores | That the top item is the right action |
| Classification | Which label from a fixed set applies? | A label, from a probability and a threshold | A cost-aware choice, unless the threshold was tuned |
| Option ranking | Which of these allowed actions fits best? | One probability per supplied option | That any option is safe to execute |
| Policy-based action selection | Is this action permitted for this case? | Allow or block, with a reason | How similar the case is to others |
The Sentence Transformers guide describes the score in comparative terms. It says that "the text pairs with the highest similarity score are most semantically similar," and it gives no value range or threshold that turns a score into a yes or no. Its own example uses sentence-transformers/all-MiniLM-L6-v2 and prints cosine scores from -0.0502 to 0.8939. The highest score belongs to "The new movie is awesome" and "The new movie is so great." That pair is a paraphrase. Nothing in the score marks whether a decision based on it would be right.
The scale also depends on the function that the model uses. The guide lists cosine as the default and also offers dot product and negative Euclidean and Manhattan distances, which print values such as -12.6269. A threshold of 0.8 on one function has no meaning on another. Research has questioned the score itself as well. Harald Steck, Chaitanya Ekanadham and Nathan Kallus showed in March 2024 that for some regularized linear models, cosine similarity "can yield arbitrary and therefore meaningless" results.
A probability is a different kind of number. The scikit-learn calibration guide says that a well calibrated classifier's output "can be directly interpreted as a confidence level." Among cases given a probability near 0.8, about 80% should be positive. A cosine score carries no such promise, because it was never fitted to outcomes.
A 29-day and a 31-day refund request look almost identical but need opposite answers
The clearest way to see the boundary is a pair of inputs that differ in one fact. Consider an illustrative policy, invented for this guide: refunds are allowed within 30 days of purchase.
- "I bought these headphones 29 days ago and would like a refund."
- "I bought these headphones 31 days ago and would like a refund."
The two sentences share every word except one number. They describe the same product, the same request and the same kind of customer, which is exactly what a resemblance score is designed to capture. Under the policy, the first request is eligible and the second is not. The deciding feature is one integer, and nothing in a similarity score compares an integer against a limit. The cosine score for this pair has not been published, and it can be checked with the example code in the Sentence Transformers guide.
A rule solves this case completely, and it needs no model at all. The rule needs one structured input, the number of days since purchase, which should come from the order record rather than from the customer's sentence.
# Illustrative 30-day refund policy (not a real company's policy).
REFUND_WINDOW_DAYS = 30
def refund_allowed(days_since_purchase: int) -> bool:
return days_since_purchase <= REFUND_WINDOW_DAYS
assert refund_allowed(29) is True
assert refund_allowed(31) is False
Retrieval still has a job here. When a support system holds hundreds of policies, embeddings can find the refund policy for a message about headphones. That is a resemblance question, and it is the question that embeddings answer well. The mistake is to let the retrieval score also decide eligibility.
Routing shows the same split in a softer form. A message such as "my card was charged twice" is close to stored examples about billing and to stored examples about fraud. Similarity can rank both queues as candidates. Choosing between them depends on facts such as whether the customer recognises the merchant, and on the cost of sending a fraud case to the billing queue.
A routing system works best as four separate stages
The design that follows keeps each kind of score in the stage where it has a meaning. Each stage passes a smaller and better-defined problem to the next one.
- Retrieval of candidates uses embeddings to find the policies, examples or actions that are relevant to the request. The output is a short list, not a decision.
- Scoring of the options takes the state of the case, the question and the candidate actions, and produces a score or probability for each action.
- Calibrated deferral compares the top probability against a threshold, and it sends the case to a person or a larger model when the probability is too low.
- Policy checks at execution test the chosen action against explicit rules before anything happens, and they block actions that the rules forbid.
Two responsibilities stay outside the option scorer. Argument resolution, such as reading the purchase date from the order system, belongs to ordinary code that can be tested. Execution authority, such as the right to issue a refund, belongs to the policy check and to the system that performs the action. A scorer that picks "issue refund" has made a recommendation, and the rule decides whether the refund happens.
Retrieval misses limit everything after them. If the correct action is not in the retrieved list, no scorer can choose it. End-to-end success therefore cannot be higher than the share of cases in which the right candidate was retrieved. Measure that share, often called recall at k, before tuning anything downstream.
The retrieval stage in Sentence Transformers is a few lines. The library's util.semantic_search function returns, for each query, a list of dictionaries with a corpus_id and a score, sorted from the highest score down. Its top_k parameter defaults to 10, and its default score function is cosine similarity. The semantic search guide recommends encode_query and encode_document for asymmetric search, where a short query is matched to longer passages.
# pip install sentence-transformers==6.3.0
from sentence_transformers import SentenceTransformer, util
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
policies = [
"Refunds are allowed within 30 days of purchase.",
"Duplicate card charges are reversed by the billing team.",
"Report unrecognised charges to the fraud team.",
]
policy_emb = model.encode_document(policies)
query_emb = model.encode_query(["I was charged twice for one order"])
hits = util.semantic_search(query_emb, policy_emb, top_k=2)[0]
candidates = [policies[h["corpus_id"]] for h in hits]
The model card for all-MiniLM-L6-v2 says that it maps text to 384-dimensional vectors and truncates input longer than 256 word pieces. Long policy documents should be split into passages before they are embedded.
A threshold should be chosen from the cost of each kind of error
Every decision that uses a score ends in a threshold, even when nobody wrote one down. The scikit-learn guide explains that its binary classifiers predict the positive class when the probability is greater than 0.5. It says that this default is "most certainly not ideal for most use cases." The right threshold depends on what a false positive costs compared with a false negative.
The arithmetic is short when the probabilities are calibrated. Suppose that acting wrongly costs C_FP and failing to act costs C_FN. For a calibrated probability p, acting is cheaper on average when p is greater than C_FP divided by the sum of C_FP and C_FN. With a false-positive cost of 1 and a false-negative cost of 5, the threshold is 1/6, or about 0.17.
The scikit-learn cost-sensitive example uses exactly that 5-to-1 ratio for credit decisions. It builds a scorer with make_scorer and passes it to TunedThresholdClassifierCV, which searches for the threshold that maximises the gain. The tuned threshold in that example is 0.03, far below 0.5. On its test set the business gain improved from -209 to -143. The example also notes that a calibrated model on a large, representative dataset could take the threshold straight from the cost ratio.
A similarity threshold follows the same logic. If a team decides that two support tickets are duplicates when their cosine score is above some cut-off, that cut-off is a decision rule. It should be chosen on labeled pairs, using the cost of merging two different tickets and the cost of missing a true duplicate.
Training, calibration and test data must be kept separate
The scikit-learn guide warns directly about one risk. "You should never use the same data for training the classifier and tuning the decision threshold due to the risk of overfitting," it says. The calibration guide gives the same advice for the calibrator, which should be fitted on data that the classifier did not see.
A sound evaluation for a routing workload therefore uses three splits.
- The training split fits the classifier, or the small model on top of the embeddings.
- The calibration split is divided in two, so that one half fits the calibrator and the other half tunes the threshold.
- The test split stays untouched until the end, and every reported number comes from it.
The following baseline embeds each request, trains a logistic regression on the embeddings, calibrates it on the second split and tunes a cost-aware threshold. It is written for one binary decision, such as "escalate to fraud team or not."
# pip install scikit-learn==1.9.1 sentence-transformers==6.3.0
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.calibration import CalibratedClassifierCV
from sklearn.frozen import FrozenEstimator
from sklearn.metrics import confusion_matrix, make_scorer
from sklearn.model_selection import TunedThresholdClassifierCV
def gain(y, y_pred, c_fp=1, c_fn=5):
tn, fp, fn, tp = confusion_matrix(y, y_pred, labels=[0, 1]).ravel()
return -(c_fp * fp + c_fn * fn)
# train_text, cal_text, thr_text, test_text and their labels are separate labeled splits:
# cal_text fits the calibrator and thr_text tunes the threshold.
X_train, X_cal, X_thr, X_test = (
model.encode(t) for t in (train_text, cal_text, thr_text, test_text)
)
clf = LogisticRegression(max_iter=1000).fit(X_train, y_train)
calibrated = CalibratedClassifierCV(FrozenEstimator(clf), method="sigmoid")
calibrated.fit(X_cal, y_cal)
tuned = TunedThresholdClassifierCV(
FrozenEstimator(calibrated), scoring=make_scorer(gain), cv="prefit", refit=False
)
tuned.fit(X_thr, y_thr)
print(tuned.best_threshold_)
The calibration guide recommends the sigmoid method for small samples. It says that the isotonic method is more prone to overfitting and performs as well or better only with more than about 1,000 samples. Check calibration on the test split with calibration_curve. The guide warns that a lower Brier score alone "does not necessarily mean a better calibrated model."
The report for each baseline should include the same measures, computed only on the test split:
- precision and recall for each action, with the cost of each error type;
- a calibration curve for the probabilities that drive deferral;
- selective coverage, which is the share of cases handled automatically at the chosen deferral threshold, with the accuracy on those cases;
- latency and total cost, with the hardware and traffic stated.
Results from different architectures should be reported side by side, not averaged into one figure. No published evaluation has compared embeddings with a threshold, a supervised classifier, explicit rules and a ready-made option scorer on the same routing workload with these splits. Those numbers have not been measured. A team that runs this comparison should report the cases where the rule or the frozen model wins, because those cases decide whether training is worth it.
A ready-made option scorer fits when the allowed actions change from case to case
A classifier needs a fixed set of labels. Some routing tasks offer a different list of allowed actions for each case, such as the tools that a support agent may call for one customer. A model that scores whatever options it is given fits that shape better.
Parsec's TOD is one such release. Parsec calls it a "universal decision model" that reads policy and task state and ranks the next action from a list of allowed actions, without generating free text. The repository's predict(state, options, question, images) returns one probability per supplied option, summing to 1. That sum makes the scores comparable across options, but it is not the same as calibration against outcomes on a given workload. According to Parsec's TOD page, its September 29, 2026 v1 release evaluation scored 84.4% on the public JevBench set against 86.2% for the untrained base model. The page says that recovering those decisions is planned for the next release, and the figures are Parsec's own rather than independent. The release consists of LoRA adapters on google/gemma-4-12B-it. It requires users to accept the Gemma 4 licence, because the base weights are not included. TOD has not been evaluated on the refund and routing workload in this guide.
Rules, embeddings or an unmodified model are often enough before custom training
The decision about what to build follows from the kind of feature that settles each case. The following order puts the cheapest sufficient option first.
- Use explicit rules when the deciding fact is a structured field and the policy is written down, as with a 30-day refund window. Rules are exact on these cases, and they are easy to audit.
- Use embeddings with a validated threshold when the task really is resemblance, such as finding duplicate tickets or matching a question to a stored answer. Choose the threshold on labeled pairs from the cost of each error.
- Use a supervised classifier with a tuned threshold when the label set is fixed and labeled outcomes exist. Calibrate it on a separate split and set the threshold from error costs.
- Use an unmodified option scorer when the allowed actions vary per case and labeled data is scarce. Keep the policy check after it, and defer when its top probability is low.
- Consider custom training only when these baselines fail on the held-out test split, and when the failures are cases that more labeled data could fix.
Sources
- Sentence Transformers, Semantic Textual Similarity: https://www.sbert.net/docs/sentence_transformer/usage/semantic_textual_similarity.html
- Sentence Transformers, Semantic Search: https://www.sbert.net/examples/sentence_transformer/applications/semantic-search/README.html
- Sentence Transformers, retrieval utilities: https://www.sbert.net/docs/package_reference/util/retrieval.html
- Hugging Face, sentence-transformers/all-MiniLM-L6-v2: https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2
- Sentence Transformers, GitHub releases: https://github.com/huggingface/sentence-transformers/releases
- scikit-learn 1.9.1, Tuning the decision threshold for class prediction: https://scikit-learn.org/stable/modules/classification_threshold.html
- scikit-learn 1.9.1, TunedThresholdClassifierCV: https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TunedThresholdClassifierCV.html
- scikit-learn 1.9.1, Post-tuning the decision threshold for cost-sensitive learning: https://scikit-learn.org/stable/auto_examples/model_selection/plot_cost_sensitive_learning.html
- scikit-learn 1.9.1, Probability calibration: https://scikit-learn.org/stable/modules/calibration.html
- Steck, Ekanadham and Kallus, Is Cosine-Similarity of Embeddings Really About Similarity?: https://arxiv.org/abs/2403.05440
- Parsec, TOD: https://parseclab.ai/tod/
- Parsec, TOD model card: https://huggingface.co/parsecai/tod
- Parsec, TOD repository: https://github.com/daseinlabs/tod