ContextCoverageMetric<T>

Models & Types · AiDotNet.RetrievalAugmentedGeneration.Evaluation

Evaluates how well the retrieved documents cover the information needed to answer the query.

Inheritance: RAGMetricBase<T> → ContextCoverageMetric<T>

For Beginners

This checks if the retrieved documents have enough info to answer the question.

Think of it like checking if you brought the right textbooks to class:

  • Question: “What is photosynthesis?”
  • Retrieved docs about plants, sunlight, energy ✓ (good coverage)
  • Retrieved docs about animals, water, soil ✗ (poor coverage)

How it works:

With Ground Truth (you know the correct answer):

  • Checks if the retrieved documents contain words from the correct answer
  • High score: Sources have all the key information
  • Low score: Sources are missing important facts

Without Ground Truth (no reference answer):

  • Uses relevance scores from retrieval
  • Checks document diversity (not all the same topic)
  • Estimates if sources are comprehensive enough

For example:

  • Query: “What are the products of photosynthesis?”
  • Ground truth: “Glucose and oxygen”
  • Retrieved docs mention “glucose” and “oxygen” ✓ (score: 1.0)
  • Retrieved docs only mention “glucose” ✗ (score: 0.5)

Why this matters:

  • Bad retrieval = bad answers (garbage in, garbage out)
  • Identifies when you need better retrieval or more documents
  • Helps tune retrieval parameters (topK, similarity threshold)

How It Works

Context coverage measures whether the retrieved documents contain the information needed to answer the query. When ground truth is provided, it checks if the sources contain the key information from the correct answer. Without ground truth, it estimates coverage by analyzing document relevance scores and diversity.

Constructors

Constructor Summary
ContextCoverageMetric()

Properties

Property Summary
string Description { get; } Gets the description of what this metric measures.
string Name { get; } Gets the name of this metric.