Ragas
Ragas evaluates your model’s answers with metrics, and a metric’s judge is a model call. This page traces those calls and sends each metric result to cetra as a score on the trace. It is setup only: the sample was not run.
Install
Section titled “Install”pip install "cetra-sdk[openai]" ragasSet up
Section titled “Set up”You give each metric an LLM built by llm_factory around an OpenAI client. Turn on cetra’s OpenAI instrumentation, and the judge’s calls become llm spans, as on the OpenAI page. Score inside a span, so the score has a trace to attach to:
import asyncio
import cetrafrom openai import AsyncOpenAIfrom ragas.llms import llm_factoryfrom ragas.metrics import DiscreteMetric
cetra.init(instrument=["openai"])
metric = DiscreteMetric( name="correctness", prompt="Is {response} right for {question}?", allowed_values=["pass", "fail"],)
async def main() -> None: question = "What is the capital of France?" response = "Paris." async with cetra.span("ragas", input={"question": question, "response": response}): result = await metric.ascore( llm=llm_factory("gpt-4o-mini", client=AsyncOpenAI()), question=question, response=response, ) cetra.score( trace_id=cetra.current_trace_id(), name=metric.name, value=result.value, reason=result.reason, )
asyncio.run(main())cetra.flush()Set CETRA_API_KEY to your sk-cetra-… key first, and RAGAS_DO_NOT_TRACK=true to turn Ragas’s own usage analytics off.
What you get
Section titled “What you get”- The judge’s model call as an
llmspan under theragasspan, with the model, the token counts and the cost, as on the OpenAI page. - One categorical score named
correctness, the metric’s name, with the judge’s value (passorfail) as its label and the judge’s reasoning as the score’s reason, on the trace of theragasspan.
Limits
Section titled “Limits”- Setup only: the sample on this page was not run. The spike ran the metric call with a mocked model and read its
llmspan; thecetra.scorewiring was not run. - Ragas writes no spans of its own. The trace holds your
ragasspan and the model spans of the OpenAI instrumentation. - A
DiscreteMetricreturns one of itsallowed_values, so the score is categorical. A numeric Ragas metric gives a numeric score the same way. evaluate, which runs metrics over a whole dataset, was not run. This page scores one call of one metric withascore.