datarobot_genai.eval.benchmarks.response_similarity
response_similarity
Response Similarity: lexical or embedding similarity to example answers (judge-free).
The fuzzy sibling of answer_correctness. Where answer_correctness asks "did the agent say exactly this?", this asks "how close did the agent get to one of these?". Each case lists one or more acceptable responses, and the score is the response's similarity to the closest one.
Lexical metrics compare words, not meaning, so a paraphrase with no shared words
("30 days" vs "a month") scores low. embedding_cosine tolerates rewording but
measures topic, not facts. Use response_acceptability (the judge-based twin,
same dataset shape) when correctness matters.
Lexical metrics, all in [0, 1], computed on lowercased words with punctuation and common stopwords removed: token_recall fraction of the example's words that appear in the response (the default; tolerant of verbose agents) token_f1 balances covering the example against adding extra words (SQuAD-style); penalizes long responses to short examples rouge_l longest run of words the two share in the same order (ROUGE-L F-measure); rewards matching word order
Embedding metric, in [0, 1] (negative cosines are clamped to 0):
embedding_cosine cosine similarity of the two texts' embeddings, from a
local fastembed model (benchmark.params.embedding_model,
default BAAI/bge-small-en-v1.5, ~70MB downloaded on first
use to FASTEMBED_CACHE_PATH). With the default model,
unrelated text scores about 0.4 and a near-miss wrong
answer ("90 degrees" vs "100 degrees") can score as high as
a correct paraphrase, so raise run.pass_threshold well
above 0.5 and read it as "on topic", not "correct".
Scoring (judge-free): the score is the raw similarity to the closest acceptable
example, not a pass/fail. passed compares it against the pipeline's
run.pass_threshold (default 0.5), which users tune to their data. The
reason says in plain words what the number means and which example matched.
unacceptable_responses do not change the score. When given, the reason also
reports the closest unacceptable example and flags the case when the response is
at least as close to it as to any acceptable one.
Pick the default metric in the pipeline YAML; a case can override it: benchmark: params: metric: token_recall embedding_model: BAAI/bge-small-en-v1.5 # embedding_cosine only
Dataset fields
input (required) the prompt sent to the agent acceptable_responses (required) str | list[str] example good answers unacceptable_responses (optional) str | list[str] example bad answers metric (optional) per-case override of the pipeline metric
A case with no acceptable_responses is scored inconclusive, not failed.
evaluate_response
evaluate_response(response: str, metadata: dict[str, Any], params: dict[str, Any] | None = None) -> dict[str, Any]
Pure scoring logic, importable for unit tests, no judge, no I/O.