RAGASragas 0.4.3 · Python 3.10+
Dashboard
0%
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

python
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 response

The reference for g005

The price golden has one exact fact. Take the price itself as the reference.

python
reference = "$899"

Two answers to score

python
answers = ["$899", "The PixelPhone 15 is priced at $899."]

Scoring two price answers

Example
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)

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

ExactMatchStringPresence
Passes whenThe strings are identicalThe reference is inside the response
Good forIds, codes, one-word answersA price, an order number, a required phrase
Fails onAny extra wordA 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.
Try it yourself
  • Score the answer "899 dollars" with both metrics and explain both results.
  • Swap response and reference in the string presence call for the full sentence and read the new score.

Little by little, you're building something great.