99from numpy .typing import NDArray
1010from pydantic import BaseModel , Field
1111
12- from ragas .metrics ._faithfulness import NLIStatementInput , NLIStatementPrompt
12+ from ragas .metrics ._faithfulness import (
13+ HasSegmentMethod ,
14+ NLIStatementInput ,
15+ NLIStatementPrompt ,
16+ )
1317from ragas .metrics .base import (
1418 MetricType ,
1519 MetricWithLLM ,
@@ -212,6 +216,8 @@ class FactualCorrectness(MetricWithLLM, SingleTurnMetric):
212216 coverage : t .Literal ["low" , "high" ] = "low"
213217 claim_decomposition_prompt : PydanticPrompt = ClaimDecompositionPrompt ()
214218 nli_prompt : PydanticPrompt = NLIStatementPrompt ()
219+ sentence_segmenter : t .Optional [HasSegmentMethod ] = None
220+ language : str = "english"
215221
216222 def __post_init__ (self ):
217223 value = f"{ self .atomicity } _atomicity_{ self .coverage } _coverage"
@@ -224,7 +230,8 @@ def __post_init__(self):
224230 logger .warning (
225231 f"No examples found for the atomicity and coverage level: { value } "
226232 )
227- self .segmenter = get_segmenter (language = "english" )
233+ if not self .sentence_segmenter :
234+ self .sentence_segmenter = get_segmenter (language = self .language , clean = False )
228235
229236 if type (self .beta ) is not float :
230237 raise ValueError (
@@ -235,7 +242,11 @@ async def decompose_claims(
235242 self , response : str , callbacks : Callbacks
236243 ) -> t .List [str ]:
237244 assert self .llm is not None , "LLM must be set"
238- sentences = self .segmenter .segment (response )
245+ assert (
246+ self .sentence_segmenter is not None
247+ ), "Sentence segmenter is not initialized"
248+
249+ sentences = self .sentence_segmenter .segment (response )
239250 assert isinstance (sentences , list ), "Segmenter must return a list of sentences"
240251 prompt_input = ClaimDecompositionInput (response = response , sentences = sentences )
241252 result = await self .claim_decomposition_prompt .generate (
0 commit comments