Skip to content

Instantly share code, notes, and snippets.

@vicpada
Created April 30, 2026 07:49
Show Gist options
  • Select an option

  • Save vicpada/64227b8b991d598132058685689b4daf to your computer and use it in GitHub Desktop.

Select an option

Save vicpada/64227b8b991d598132058685689b4daf to your computer and use it in GitHub Desktop.
RAGAS evaluation with Noise Sensitivity
from ragas import evaluate
from ragas.metrics import (
faithfulness, answer_relevancy,
context_precision, context_recall
)
from datasets import Dataset
# Standard evaluation dataset
data = {
'question': ['What is the capital of France?'],
'answer': ['Paris is the capital of France.'],
'contexts': [['France is a country in Western Europe.',
'Paris, the capital city of France, is...']],
'ground_truth': ['Paris']
}
dataset = Dataset.from_dict(data)
results = evaluate(
dataset=dataset,
metrics=[faithfulness, answer_relevancy, context_precision, context_recall],
llm=your_llm,
embeddings=your_embeddings
)
# faithfulness: 0.85, answer_relevancy: 0.92,
# context_precision: 0.78, context_recall: 0.91
# For Noise Sensitivity: add known-irrelevant documents to contexts
# and re-run evaluation. Score degradation = noise sensitivity.
# If answer_relevancy drops >0.15 with noise injection,
# invest in RAFT/DRAG robustness training.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment