RAGASragas 0.4.3 · Python 3.9+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
20 small wins to finish your pathNext lesson

SingleTurnSample: one interaction to score

Everything RAGAS scores is one interaction: a question went in, documents came back, an answer came out. That is a sample, and it is the only data structure you need for a while.

Example
from ragas import SingleTurnSample

sample = SingleTurnSample(
    user_input="Where is order A17?",
    retrieved_contexts=["Order A17 shipped on 3 March by courier."],
    response="Order A17 shipped on 3 March.",
    reference="Order A17 shipped on 3 March by courier.",
)
print(sample.user_input)
print(sample.retrieved_contexts)
print(sample.response)
print(sample.reference)

user_input is the question the user asked.

retrieved_contexts is what the search returned, as a list. This is the field that makes RAG evaluation different from evaluating a plain model.

response is what your bot answered.

reference is the answer you would like, sometimes called the ground truth. Some metrics need it and some do not, which is what decides whether you can run them in production.

Fields you leave out

Example
thin = SingleTurnSample(user_input="Where is order A17?", response="It shipped.")
print(thin.retrieved_contexts, thin.reference)

Nothing is required except the question. Each metric reads the fields it needs, and fails with a clear message when one is missing, so a sample carries whatever the metrics you chose require.

The other kind of sample
There is also a MultiTurnSample, for whole conversations with a chatbot. This course stays with single turns, and lesson 19 names what the multi-turn metrics cover.
Try it yourself
  • Print sample on its own and read every field it can hold.
  • Add a second document to retrieved_contexts and print the list again.

Little by little, you're building something great.