-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement
RAGEvaluationHarness
and related classes
- Loading branch information
Showing
11 changed files
with
1,155 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from .harness import RAGEvaluationHarness | ||
from .parameters import ( | ||
RAGEvaluationInput, | ||
RAGEvaluationMetric, | ||
RAGEvaluationOutput, | ||
RAGEvaluationOverrides, | ||
RAGExpectedComponent, | ||
RAGExpectedComponentMetadata, | ||
) | ||
|
||
_all_ = [ | ||
"RAGEvaluationHarness", | ||
"RAGExpectedComponent", | ||
"RAGExpectedComponentMetadata", | ||
"RAGEvaluationMetric", | ||
"RAGEvaluationOutput", | ||
"RAGEvaluationOverrides", | ||
"RAGEvaluationInput", | ||
] |
49 changes: 49 additions & 0 deletions
49
haystack_experimental/evaluation/harness/rag/evaluation_pipeline.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from functools import partial | ||
from typing import Set | ||
|
||
from haystack import Pipeline | ||
from haystack.components.evaluators import ( | ||
DocumentMAPEvaluator, | ||
DocumentMRREvaluator, | ||
DocumentRecallEvaluator, | ||
FaithfulnessEvaluator, | ||
SASEvaluator, | ||
) | ||
from haystack.components.evaluators.document_recall import RecallMode | ||
|
||
from .parameters import RAGEvaluationMetric | ||
|
||
|
||
def default_rag_evaluation_pipeline( | ||
metrics: Set[RAGEvaluationMetric], | ||
) -> Pipeline: | ||
""" | ||
Builds the default evaluation pipeline for RAG. | ||
:param metrics: | ||
The set of metrics to include in the pipeline. | ||
:returns: | ||
The evaluation pipeline. | ||
""" | ||
pipeline = Pipeline() | ||
|
||
metric_ctors = { | ||
RAGEvaluationMetric.DOCUMENT_MAP: DocumentMAPEvaluator, | ||
RAGEvaluationMetric.DOCUMENT_MRR: DocumentMRREvaluator, | ||
RAGEvaluationMetric.DOCUMENT_RECALL_SINGLE_HIT: partial(DocumentRecallEvaluator, mode=RecallMode.SINGLE_HIT), | ||
RAGEvaluationMetric.DOCUMENT_RECALL_MULTI_HIT: partial(DocumentRecallEvaluator, mode=RecallMode.MULTI_HIT), | ||
RAGEvaluationMetric.SEMANTIC_ANSWER_SIMILARITY: partial( | ||
SASEvaluator, model="sentence-transformers/all-MiniLM-L6-v2" | ||
), | ||
RAGEvaluationMetric.ANSWER_FAITHFULNESS: FaithfulnessEvaluator, | ||
} | ||
|
||
for metric in metrics: | ||
ctor = metric_ctors[metric] | ||
pipeline.add_component(metric.value, ctor()) | ||
|
||
return pipeline |
Oops, something went wrong.