Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
adkakne committed Sep 26, 2024
2 parents 8f0b59b + 76790f3 commit 82ef382
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 7 additions & 5 deletions evals/metrics/ragas/ragas.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(
self.model = model
self.embeddings = embeddings
self.metrics = metrics

# self.validated_list = [
# "answer_correctness",
# "answer_relevancy",
Expand All @@ -53,11 +53,12 @@ def measure(self, test_case: Dict):
try:
from ragas import evaluate
from ragas.metrics import ALL_METRICS
self.metric_names = [metric.__class__.__name__ for metric in ALL_METRICS]
self.metric_names = [re.sub(r'(?<!^)(?=[A-Z])', '_', name).lower() for name in self.metric_names]

self.metric_names = [metric.__class__.__name__ for metric in ALL_METRICS]
self.metric_names = [re.sub(r"(?<!^)(?=[A-Z])", "_", name).lower() for name in self.metric_names]
self.metric_names = list(set(self.metric_names))
# Note - summarization score metric is not working with best open-source LLMs
# Note - which is why we are removing it from our offering at the moment.
# Note - which is why we are removing it from our offering at the moment.
self.metric_names.remove("summarization_score")
self.metric_instances = {}
for metric in self.metric_names:
Expand Down Expand Up @@ -141,14 +142,15 @@ def measure(self, test_case: Dict):
"response": "answer",
"reference": "ground_truth",
"retrieved_contexts": "contexts",
"reference_contexts": "reference_contexts"
"reference_contexts": "reference_contexts",
}
for metric in self.metrics:
if hasattr(metric, "_required_columns"):
for column in list(metric._required_columns.values())[0]:
_required_columns.add(column_map[column])
elif hasattr(metric, "evaluation_mode"):
from ragas.metrics.base import get_required_columns

for column in get_required_columns(metric.evaluation_mode):
_required_columns.add(column)
else:
Expand Down
6 changes: 2 additions & 4 deletions tests/test_ragas.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ def test_ragas(self):

embeddings = HuggingFaceBgeEmbeddings(model_name="BAAI/bge-base-en-v1.5")

metric = RagasMetric(threshold=0.5,
model=f"http://{host_ip}:{port}",
embeddings=embeddings)
metric = RagasMetric(threshold=0.5, model=f"http://{host_ip}:{port}", embeddings=embeddings)
test_case = {
"question": ["What if these shoes don't fit?"],
"answer": [actual_output],
"ground_truth": [expected_output],
"contexts": [retrieval_context],
"reference_contexts": [reference_context]
"reference_contexts": [reference_context],
}

metric.measure(test_case)
Expand Down

0 comments on commit 82ef382

Please sign in to comment.