AI engineering paper · 2024

Ragas

Es, James, Espinosa-Anke and Schockaert · EACL 2024

How to score an AI that answers from retrieved documents with no answer key: three checks, tested on 50 examples, and what has changed since.

Ragas gives three scores from the question, the retrieved context and the answer. On 50 test examples with a human choice between two versions, the scores chose the same version as the people 95% of the time (faithfulness), 78% (answer relevance) and 70% (context relevance).

You’ll learn to

  • Work out the paper’s three scores by hand on small examples, each a simple ratio or average.
  • Explain why 50 human-judged test examples support one of the scores well and leave another unsettled.
  • Name what the scores cannot see, such as a missing fact or a wrong but well-supported answer.
  • Describe how the Ragas software library has changed since the paper, and how to check any score computed by a language model against human judgments before trusting it.

Read first: RAG

The idea in short

A retrieval-augmented generation (RAG) system answers a question by first looking up passages in your documents, then asking a language model to write an answer from them. The passages it finds are called the context. To test such a system you normally need a correct answer for every test question, and writing those by hand is slow. In 2023 Es, James, Espinosa-Anke and Schockaert proposed Ragas, both a method and a software library: three scores that need no answer key, each worked out by asking a language model simple questions about the question, the context and the answer.

Faithfulness is the share of claims in the answer that the context supports, a claim being one short statement that can be true or false. Answer relevance asks a model to guess the questions the answer replies to and checks that they match the real one. Context relevance is the share of the context’s sentences that were needed to answer. The authors tested the scores on 50 examples, each holding two versions of an answer or context plus a human choice of the better one. The scores chose the same version as the people 95% of the time for faithfulness, 78% for answer relevance and 70% for context relevance. Fifty examples is few, and the library has since changed some of the scores.

The problem

A () system answers a question in two stages. A searches your documents and returns a ranked list of passages, best first. A then reads the top passages together with the question and writes an answer. This guide calls the retrieved passages the context.

Such a system has many settings that change its answers: the retriever, the documents, the model and the wording of the , the instructions sent to the model. Anyone building one has to try changes and see whether the answers get better. That means testing, which engineers call an : a repeatable set of test questions, each with a score for the answer.

The usual way to score an answer is to compare it with a known correct one, called a . In 2023 Shahul Es, Jithin James, Luis Espinosa-Anke and Steven Schockaert posted “Ragas: Automated Evaluation of Retrieval Augmented Generation”. Their starting point is that, while you are building a system, you often have no reference answers yet. They call a method that needs none . Ragas names both their method and the open-source library that implements it.

The authors say two common alternatives fall short. Perplexity, which measures how surprised a language model is by a sample of text, does not always predict how well a system answers, and it needs word probabilities that some models offered through an API (a web service you call over the network) do not expose. Question-answering datasets with short answers do not look like real use, where answers are long.

Their setting is simple: a question, a retrieved context and an answer written from it. They pick three qualities of this triple that they argue matter most, and build a score for each. Asking a model for one overall grade is known to be sensitive to the wording of the request. Ragas instead breaks each judgment into small questions that a model answers with yes or no, or by counting.

The design choices

The three qualities are:

Our biggest sale ever · Black Friday

Flat 50% Off

Pro

Continue reading

Unlock every course, now and later

  • System Design, live
  • AI Engineering, live
  • Data Engineering, live
  • Machine Learning Engineering, live
  • Inference Engineering, coming soon
  • AI Research, coming soon
  • Performance Engineering, coming soon
  • Agent & Harness Engineering, coming soon
  • LLM Fine-tuning, coming soon
  • LLM Pre-training & Post-training, coming soon
  • Reinforcement Learning, coming soon
  • AI Infrastructure & Platform Engineering, coming soon
  • AI Evaluation & Safety, coming soon
  • Forward Deployed Engineering, coming soon
  • Cloud Computing, coming soon
  • DevOps, coming soon

50% off · Annual and Lifetime

BLACKFRIDAY50Applied at checkout

Choose a plan

About the paper

Ragas: Automated Evaluation of Retrieval Augmented Generation by Es, James, Espinosa-Anke and Schockaert, EACL 2024.

Read the original paper

More AI engineering papers

All papers