Skip to content

Add Retrieval-Conditioned Confidence Metric (RCCS) for RAG evaluation#782

Open
AIMindCrafter wants to merge 1 commit into
huggingface:mainfrom
AIMindCrafter:add-rccs-metric
Open

Add Retrieval-Conditioned Confidence Metric (RCCS) for RAG evaluation#782
AIMindCrafter wants to merge 1 commit into
huggingface:mainfrom
AIMindCrafter:add-rccs-metric

Conversation

@AIMindCrafter

Copy link
Copy Markdown

Description

This pull request implements the Retrieval-Conditioned Confidence Score (RCCS) metric under metrics/rccs/ as proposed in issue #736.

RCCS provides a lightweight, model-agnostic calibration diagnostic for Retrieval-Augmented Generation (RAG) pipelines. By evaluating the joint alignment between retrieval relevance ($R$), model confidence ($C$), and ground-truth correctness ($A$), this metric helps detect instances of "confident hallucinations" (i.e., high confidence in the output despite poor or missing retrieved context).

Key Components Implemented:

  1. Inputs Accepted:

    • retrieval_score: The relevance/quality score ($R$) of retrieved documents.
    • confidence_score: The model's generation confidence ($C$).
    • correctness: Binary ground-truth correctness ($A$, $0$ or $1$).
  2. Metrics Returned:

    • rccs_correlation: Pearson correlation between $(R \times C)$ and $A$.
    • confidence_calibration_error: Mean absolute error mean(|R * C - A|).
    • mean_rc: Average of $(R \times C)$.
    • n: Total sample count.

Files Added

  • metrics/rccs/rccs.py: Core metric implementation inheriting from evaluate.Metric.
  • metrics/rccs/README.md: Comprehensive metric card documentation, installation instructions, and examples.
  • metrics/rccs/requirements.txt: Dependencies list (scipy, numpy).
  • metrics/rccs/app.py: Gradio app launcher script for the metric widget.

Verification and Tests

  1. Doctests:
    Successfully passed using pytest on the local module test suite:

    pytest tests/test_metric_common.py -k rccs

    Output:

    tests/test_metric_common.py .
    tests/test_metric_common.py .s
    =========== 1 passed, 1 skipped, 133 deselected, 2 warnings in 7.15s ===========
    
  2. Manual verification:

    import evaluate
    rccs = evaluate.load("metrics/rccs")
    results = rccs.compute(
        retrieval_score=[0.8, 0.3, 0.5],
        confidence_score=[0.9, 0.2, 0.7],
        correctness=[1, 0, 1]
    )
    print(results)

    Output:

    {
        'rccs_correlation': 0.8290069500014531,
        'confidence_calibration_error': 0.33000001311302185,
        'mean_rc': 0.3766666650772095,
        'n': 3
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant