Skip to main content

Required Arguments

Each test case must be a ModelTestCase instance with the following fields:
  • input: The user’s query.
  • actual_output: The generated response (used for formatting or logging; not used in score computation).
  • retrieval_context: A list of strings representing the context chunks retrieved from your knowledge base.

Optional Arguments

Usage Example

How It Works

  • Extract statements from the retrieval_context using the selected LLM.
  • Classify each statement as either relevant or not relevant to the input.
  • Compute the Contextual Relevancy score as:
Contextual Relevancy=Number of Relevant Statements/Total Statements in ContextContextual Relevancy=Number of Relevant Statements / Total Statements in Context ​ This focuses on precision of retrieval, rewarding concise and input-aligned context chunks.

Use Cases

Use ContextualRelevancyMetric when you want to:
  • Optimize retriever precision by penalizing irrelevant or off-topic context.
  • Measure retrieval drift when irrelevant content is included in context.
  • Improve user satisfaction by keeping retrieved context short and focused.