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.
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
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.
MultiTurnSample, for whole conversations with a chatbot. This course stays with single turns, and lesson 19 names what the multi-turn metrics cover.- Print
sampleon its own and read every field it can hold. - Add a second document to
retrieved_contextsand print the list again.
Little by little, you're building something great.