1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
28 small wins to finish your pathNext lesson →
Exact match and string presence
Exact match and string presence are RAGAS metrics that compare the response with the reference as plain strings, with no judge model, and return 1 or 0.
Last updated: 29 Sep, 2026 · RAGAS 0.4.3
Most RAGAS metrics ask a model to judge. These two do not, so they cost nothing and give the same answer every time. They are the quickest way to see what a metric is: something that takes fields of a sample and returns a number.
The ExactMatch and StringPresence API
from ragas.metrics.collections import ExactMatch, StringPresence
ExactMatch().score(response=..., reference=...) # 1.0 only if the two strings are identical
StringPresence().score(response=..., reference=...) # 1.0 if the reference appears inside the responseThe reference for g005
The price golden has one exact fact. Take the price itself as the reference.
reference = "$899"Two answers to score
answers = ["$899", "The PixelPhone 15 is priced at $899."]Scoring two price answers
from ragas.metrics.collections import ExactMatch, StringPresence
exact = ExactMatch()
present = StringPresence()
reference = "$899"
for answer in ["$899", "The PixelPhone 15 is priced at $899."]:
print(answer)
print(" exact match ", exact.score(response=answer, reference=reference).value)
print(" string present", present.score(response=answer, reference=reference).value)Output
$899 exact match 1.0 string present 1.0 The PixelPhone 15 is priced at $899. exact match 0.0 string present 1.0
Why the full sentence fails exact match
- Exact match compares the two strings character by character. The full sentence is the better answer and still scores 0, which is why judged metrics exist.
- String presence asks whether the reference appears inside the answer. Both answers contain
$899, so both score 1. - The score sits in
.value. Every RAGAS metric returns a result object, not a bare number.
Exact match vs string presence
| ExactMatch | StringPresence | |
|---|---|---|
| Passes when | The strings are identical | The reference is inside the response |
| Good for | Ids, codes, one-word answers | A price, an order number, a required phrase |
| Fails on | Any extra word | A reworded fact, such as "899 dollars" |
When to use string metrics
- A fact with one correct form, such as a price or a SKU, that must appear in the answer.
- A required sentence, such as a warranty disclaimer, that every answer must carry.
Watch out. String presence is case-sensitive and exact about spacing: a reference of
$899 does not match an answer that says $ 899. Use it for values with one fixed spelling.Related
- Previous: SingleTurnSample
- Next: ID-based context precision and recall
- Reference: Traditional metrics
Try it yourself
- Score the answer
"899 dollars"with both metrics and explain both results. - Swap
responseandreferencein the string presence call for the full sentence and read the new score.
Little by little, you're building something great.