Notebooks
N
NVIDIA
03 Eval Ragas

03 Eval Ragas

gpu-accelerationretrieval-augmented-generationllm-inferencetensorrtnvidia-generative-ai-examplestoolslarge-language-modelsmicroservicetriton-inference-serverevaluationLLMnotebooksragnemo

Evaluation with Ragas

Leveraging a strong LLM for reference-free evaluation is an upcoming solution that has shown a lot of promise. They correlate better with human judgment than traditional metrics and also require less human annotation. Papers like G-Eval have experimented with this and given promising results but there are certain shortcomings too.

LLM prefers their own outputs and when asked to compare between different outputs the relative position of those outputs matters more. LLMs can also have a bias toward a value when asked to score given a range and they also prefer longer responses.

Ragas aims to work around these limitations of using LLMs to evaluate your QA pipelines while also providing actionable metrics using as little annotated data as possible, cheaper, and faster.

This notebook uses the Llama 3 70B Instruct LLM from the NVIDIA API Catalog as a judge and eval model.

Step 1: Set Your NVIDIA API Key

[ ]
[ ]
[ ]

Bring your own LLMs

Ragas uses LangChain for connecting to LLMs for metrics that require them. This means you can swap out the default LLM, GPT-3.5, with Llama 3 70B Instruct from the API catalog.

[ ]

Step 2: Import Eval Data and Reformat It

[ ]
[ ]
[ ]
[ ]
[ ]

Step 3: View and Interpret Results

A Ragas score is comprised of the following: ragas

Metrics explained

  1. Faithfulness: measures the factual accuracy of the generated answer with the context provided. This is done in 2 steps. First, given a question and generated answer, Ragas uses an LLM to figure out the statements that the generated answer makes. This gives a list of statements whose validity we have we have to check. In step 2, given the list of statements and the context returned, Ragas uses an LLM to check if the statements provided are supported by the context. The number of correct statements is summed up and divided by the total number of statements in the generated answer to obtain the score for a given example.

  2. Answer Relevancy: measures how relevant and to the point the answer is to the question. For a given generated answer Ragas uses an LLM to find out the probable questions that the generated answer would be an answer to and computes similarity to the actual question asked.

  3. Context Precision: measures the precision of the retrieved context in providing relevant information for generating answer. Given a question, answer and retrieved context, Ragas calls LLM to check sentences from the ground truth answer against a retrieved context. It is the ratio between the relevant sentences from retrieved context and the total sentence from ground truth answer.

  4. Context Recall: measures the ability of the retriever to retrieve all the necessary information needed to answer the question. Ragas calculates this by using the provided ground_truth answer and using an LLM to check if each statement from it can be found in the retrieved context. If it is not found that means the retriever was not able to retrieve the information needed to support that statement.