Dynamiq Docs
  • Welcome to Dynamiq
  • Low-Code Builder
    • Chat
    • Basics
    • Connecting Nodes
    • Conditional Nodes and Multiple Outputs
    • Input and Output Transformers
    • Error Handling and Retries
    • LLM Nodes
    • Validator Nodes
    • RAG Nodes
      • Indexing Workflow
        • Pre-processing Nodes
        • Document Splitting
        • Document Embedders
        • Document Writers
      • Inference RAG workflow
        • Text embedders
        • Document retrievers
          • Complex retrievers
        • LLM Answer Generators
    • LLM Agents
      • Basics
      • Guide to Implementing LLM Agents: ReAct and Simple Agents
      • Guide to Agent Orchestration: Linear and Adaptive Orchestrators
      • Guide to Advanced Agent Orchestration: Graph Orchestrator
    • Audio and voice
    • Tools and External Integrations
    • Python Code in Workflows
    • Memory
    • Guardrails
  • Deployments
    • Workflows
      • Tracing Workflow Execution
    • LLMs
      • Fine-tuned Adapters
      • Supported Models
    • Vector Databases
  • Prompts
    • Prompt Playground
  • Connections
  • LLM Fine-tuning
    • Basics
    • Using Adapters
    • Preparing Data
    • Supported Models
    • Parameters Guide
  • Knowledge Bases
  • Evaluations
    • Metrics
      • LLM-as-a-Judge
      • Predefined metrics
        • Faithfulness
        • Context Precision
        • Context Recall
        • Factual Correctness
        • Answer Correctness
      • Python Code Metrics
    • Datasets
    • Evaluation Runs
    • Examples
      • Build Accurate vs. Inaccurate Workflows
  • Examples
    • Building a Search Assistant
      • Approach 1: Single Agent with a Defined Role
      • Approach 2: Adaptive Orchestrator with Multiple Agents
      • Approach 3: Custom Logic Pipeline with a Straightforward Workflow
    • Building a Code Assistant
  • Platform Settings
    • Access Keys
    • Organizations
    • Settings
    • Billing
  • On-premise Deployment
    • AWS
    • IBM
  • Support Center
Powered by GitBook
On this page
  • Context Recall Metric
  • Example Code: Context Recall Evaluation
  1. Evaluations
  2. Metrics
  3. Predefined metrics

Context Recall

PreviousContext PrecisionNextFactual Correctness

Last updated 4 months ago

Context Recall Metric

Context Recall measures the number of relevant documents or pieces of information that were successfully retrieved. It emphasizes the importance of capturing all important results. A higher recall score indicates that fewer relevant documents were overlooked.

Key Points

  • Focus: Context Recall is primarily concerned with ensuring that no significant information is missed.

  • Interpretation: Higher recall means that more relevant documents have been retrieved, while lower recall indicates that important documents were left out.

  • Comparison Reference: Calculating context recall requires a reference set of relevant documents to compare against, ensuring an accurate assessment of what has been retrieved.

In summary, context recall is crucial for applications where catching all relevant information is essential.

Example Code: Context Recall Evaluation

This example demonstrates how to compute the Context Recall metric using the ContextRecallEvaluator with the OpenAI language model.

import logging
import sys
from dotenv import find_dotenv, load_dotenv
from dynamiq.evaluations.metrics import ContextRecallEvaluator
from dynamiq.nodes.llms import OpenAI

# Load environment variables for the OpenAI API
load_dotenv(find_dotenv())

# Configure logging level
logging.basicConfig(stream=sys.stdout, level=logging.INFO)

# Initialize the OpenAI language model
llm = OpenAI(model="gpt-4o-mini")

# Sample data
questions = ["What can you tell me about Albert Einstein?"]
contexts = [
    (
        "Albert Einstein (14 March 1879 - 18 April 1955) was a German-born "
        "theoretical physicist, widely held to be one of the greatest and most "
        "influential scientists of all time. Best known for developing the "
        "theory of relativity, he also made important contributions to quantum "
        "mechanics. His mass-energy equivalence formula E = mc^2 has been called "
        "'the world's most famous equation'. He received the 1921 Nobel Prize in "
        "Physics for his services to theoretical physics."
    )
]
answers = [
    (
        "Albert Einstein, born on 14 March 1879, was a German-born theoretical "
        "physicist, widely held to be one of the greatest and most influential "
        "scientists of all time. He received the 1921 Nobel Prize in Physics for "
        "his services to theoretical physics."
    )
]

# Initialize evaluator and evaluate
evaluator = ContextRecallEvaluator(llm=llm)
recall_scores = evaluator.run(
    questions=questions, 
    contexts=contexts, 
    answers=answers, 
    verbose=True  # Set to False to disable verbose logging
)

# Print the results
for idx, score in enumerate(recall_scores):
    print(f"Question: {questions[idx]}")
    print(f"Context Recall Score: {score}")
    print("-" * 50)

print("Context Recall Scores:")
print(recall_scores)
context recall=∣GT claims that can be attributed to context∣∣Number of claims in GT∣\text{context recall} = {|\text{GT claims that can be attributed to context}| \over |\text{Number of claims in GT}|}context recall=∣Number of claims in GT∣∣GT claims that can be attributed to context∣​