Skip to content

Commit 1c3c1c2

Browse files
committed
update: input validation
1 parent da87e80 commit 1c3c1c2

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/ragas/metrics/collections/_context_recall.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,14 @@ def __init__(
7676
name: str = "context_recall",
7777
**kwargs,
7878
):
79-
"""Initialize ContextRecall metric with required components."""
79+
"""
80+
Initialize ContextRecall metric with required components.
81+
82+
Args:
83+
llm: Modern instructor-based LLM for classification
84+
name: The metric name (default: "context_recall")
85+
**kwargs: Additional arguments passed to BaseMetric
86+
"""
8087
# Set attributes explicitly before calling super()
8188
self.llm = llm
8289

@@ -102,6 +109,14 @@ async def ascore(
102109
Returns:
103110
MetricResult with recall score (0.0-1.0)
104111
"""
112+
# Input validation
113+
if not user_input:
114+
raise ValueError("user_input cannot be empty")
115+
if not reference:
116+
raise ValueError("reference cannot be empty")
117+
if not retrieved_contexts:
118+
raise ValueError("retrieved_contexts cannot be empty")
119+
105120
# Combine contexts into a single string
106121
context = "\n".join(retrieved_contexts) if retrieved_contexts else ""
107122

0 commit comments

Comments
 (0)