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

What you are going to build

RAGAS scores a RAG application: whether the answer stuck to the documents, and whether the search found the right documents in the first place. This course builds an evaluation suite for one support bot, and every lesson runs on your machine with no API key.

A RAG bot answers in two steps. It searches for documents, then writes an answer from them. When the answer is wrong, either the search missed or the writing drifted, and a single score cannot tell you which. RAGAS has separate metrics for each half, which is the whole point of it.

A metric, working

Example
from pretend_ragas import PretendJudge
from ragas.metrics.collections import Faithfulness

faithfulness = Faithfulness(llm=PretendJudge())
context = ["Order A17 shipped on 3 March by courier."]

for answer in ["Order A17 shipped on 3 March by courier.", "Order A17 was cancelled."]:
    result = faithfulness.score(user_input="Where is order A17?", response=answer,
                                retrieved_contexts=context)
    print(result.value, answer)

One metric, two answers, two scores. The first answer only says what the document says, so faithfulness is 1. The second contradicts it and scores 0.

PretendJudge is a stand-in model you write in lesson 4. Almost every RAGAS metric asks a model to judge, and by default that is an OpenAI model with a key; the stand-in decides by comparing words instead, so the whole course runs offline.

What you will have built

PieceWhat it doesLesson
SamplesOne question, the answer, the documents, and the right answer1
Metrics with no modelScores that are pure Python: exact match, ids2 and 3
A stand-in judgeAnswers every question a metric asks, with no key4
The RAG fourFaithfulness, context recall, context precision, factual correctness5 to 8
Answer relevancyThe judge plus a stand-in embedding model9
Your own metricsCriteria in plain words, and plain Python functions10 and 11
Datasets and experimentsQuestions in a file, runs that write results next to it12 to 14
evaluate()The older API every other tutorial uses15 and 16
A suite in CIA score falling turns the build red18 and 19

What you need

bash
pip install "ragas==0.4.3" "langchain-community<0.4"

The pin matters. RAGAS 0.4.3 imports a class that langchain-community removed in its 0.4 release, so the newest of both together will not import at all. Lesson 16 says more about the version churn in this library.

Needed for this course?When you do need it
Python 3.9 or laterYesNow
An OpenAI API keyNoLesson 17, when you swap in a real judge
A vector databaseNoNever here. The bot's search is six lines of Python
Try it yourself
  • Install the two packages now, with the pin.
  • Download pretend_ragas.py into the folder you will work in.
  • Change the second answer so it agrees with the document, and predict its score.
Back toAll frameworks

Every expert started right here.