Working through this module?0 of 19 done
Module 14 · Page 15 of 20 · 10 sections

Evaluation and Testing

How to measure an AI system: evaluation types, LLM and RAG metrics, an evaluation workflow, testing types and example test cases.

14.1

1. Introduction

  • Evaluation and testing are essential to ensure that AI systems provide accurate, reliable, fair and safe responses.
  • For LLM and RAG systems, we need to evaluate both the model's capability and the overall application performance.
  • Proper evaluation helps in improving the system, reducing errors and building trust with users.
14.2

2. Why Evaluation is Important?

  1. 1Measure how good the model / system is.
  2. 2Identify strengths and weaknesses.
  3. 3Compare different models and approaches.
  4. 4Ensure reliability and consistency.
  5. 5Improve prompts, retrieval and generation.
  6. 6Detect bias, hallucination and harmful content.
  7. 7Validate performance in real-world scenarios.
  8. 8Essential for production readiness.
14.3

3. Types of Evaluation

Evaluation
Automatic Evaluation
  • ROUGE
  • BLEU
  • BERTScore
  • Cosine similarity
  • Semantic similarity
Human Evaluation
  • Relevance
  • Correctness
  • Helpfulness
  • Coherence
  • Safety
  • User satisfaction
Task-specific Evaluation
  • RAG evaluation
  • Chatbot evaluation
  • Summarization
  • Question answering
  • Translation
  • Classification
System Evaluation
  • Latency
  • Throughput
  • Error rate
  • Scalability
  • Cost
  • Availability
14.4

4. Evaluation Metrics for LLMs

1
Perplexity
Measures how well the model predicts text.
2
BLEU
Commonly used for machine translation.
3
ROUGE
Used for text summarization.
4
BERTScore
Measures semantic similarity.
5
Accuracy
Correctness of the answer.
6
Relevance
How relevant the response is to the query.
7
Faithfulness
Whether the answer is grounded in the source.
8
Coherence
Logical flow and readability of the response.
14.5

5. Metrics for RAG Systems

1
Context Precision
How much retrieved context is relevant.
2
Context Recall
How much relevant context is retrieved.
3
Answer Relevance
Is the answer relevant to the question?
4
Faithfulness
Is the answer supported by retrieved context?
5
Hallucination Rate
Percentage of unsupported statements.
6
Source Attribution
Correct citation of source documents.
7
Response Quality
Helpfulness, completeness, clarity.
8
End-to-end Latency
Total time (retrieval + generation).
14.6

6. Evaluation Workflow (RAG Example)

Test QueriesQuestion set
RAG SystemRetrieval + generation
EvaluationRelevance, faithfulness, correctness, context precision, human review
ResultsMetrics, analysis, improvement areas
14.7

7. Example Evaluation Techniques

1
LLM-as-a-Judge
Use another LLM to evaluate responses.
2
Reference-based Evaluation
Compare with ground truth answers.
3
Semantic Similarity
Use embeddings to compare meaning.
4
Pairwise Comparison
Compare responses from two models.
5
Human Evaluation
Manual review by domain experts.
6
RAGAS
Popular framework for RAG evaluation.
7
LangSmith
Track and evaluate LLM applications.
8
Custom Scoring
Task-specific evaluation criteria.
14.8

8. Testing Types for AI Systems

1
Unit Testing
Test individual components (e.g. prompts, functions).
2
Integration Testing
Test retrieval + generation together.
3
Functional Testing
Verify expected behavior.
4
Regression Testing
Ensure new changes don't break existing flow.
5
A/B Testing
Compare two models or prompts.
6
Load Testing
Test the system under high traffic.
7
Adversarial Testing
Test with tricky or malicious inputs.
8
Safety Testing
Check for harmful, biased or inappropriate content.
14.9

9. Example Test Cases (RAG)

Test caseExample inputExpected output
Relevant queryWhat is Spring Boot?Correct and relevant answer with source citation
Irrelevant queryWho won the 2022 World Cup?Response: not in context, or an appropriate message
Ambiguous queryExplain thisAsk for clarification or give the best possible answer
Incorrect context(wrong document)Detect and avoid hallucination
Multi-turn queryTell me about Kafka. What are its use cases?Maintain context and give an accurate answer
14.10

10. Best Practices

  1. 1Use a diverse and representative test dataset.
  2. 2Evaluate with both automatic metrics and human feedback.
  3. 3Continuously monitor model performance in production.
  4. 4Track and analyze failure cases.
  5. 5Set clear evaluation criteria for your use case.
  6. 6Use tools like RAGAS, LangSmith and OpenAI Evals.
  7. 7Test for bias, safety and adversarial inputs.
  8. 8Keep improving prompts, retrieval and system design based on evaluation results.