How RAG evaluation with Ragas metrics works in self-hosted Langfuse
A team that runs a retrieval-augmented generation (RAG) application needs one answer before and after every change: are the answers getting better or worse? Ragas metrics address this by scoring each answer against the retrieved context and the question, and in self-hosted Langfuse those metrics are run as evaluators that write their results back as scores. Two surfaces carry them. The first is experiments run from code, where a dataset of questions and reference answers is replayed through the application and each run is scored, so two runs of a retriever or prompt can be compared side by side. The second is production trace evaluation, where evaluators score a sample of live traces as they arrive, which shows drift that a fixed dataset will not catch. The same score names can appear on both, which makes an offline result and a live result directly comparable.
Before building anything, confirm three things against the sources rather than from memory. First, the Ragas version you will install and the exact metric names and input fields it expects for each metric, since these have changed across releases and the Ragas documentation is the authority for them. Second, how custom evaluators are registered and triggered on your Langfuse version, which the Langfuse evaluator documentation describes and which can differ between a self-hosted instance and Langfuse Cloud. Third, which fields your traces actually carry, such as the user question, the retrieved chunks and the generated answer, because a Ragas metric can only score what the trace records. Missing retrieval spans are the most common reason a faithfulness or context score comes back empty, so check this with a few real traces before you write any evaluator logic.
Plan for the model cost of these metrics early. Many Ragas metrics call a language model to judge each answer, so every scored item adds model calls on top of the application's own calls, and production sampling directly controls that spend. Ask your team to confirm which judge model the metrics will use, how it is connected to your self-hosted instance, and what sampling rate and filters limit volume on live traffic. Use the same judge model across the runs you compare, because switching it changes the scores and makes the comparison meaningless.
What you need before wrapping Ragas metrics
Ragas metrics only produce useful scores when the Langfuse version, trace data, judge model access and runtime are ready. The cards below cover the prerequisites that connect a self-hosted Langfuse instance to a repeatable RAG evaluation.
Langfuse version and SDK pairing
Python SDK v5 and JS/TS SDK v6 need Langfuse v4.59.0 or later. Check your self-hosted version before writing evaluator code, because an older server will reject the newer SDK calls that experiments depend on. Pin both the server and SDK versions in your deployment notes, and confirm the current release on the Langfuse releases page before you upgrade. A mismatch usually shows up as failed experiment runs rather than a clear error, so test one trace end to end first.
Langfuse releasesWorking trace pipeline for RAG
Each RAG request should produce a trace that records the user question, the retrieved chunks and the generated answer as separate, identifiable inputs and outputs. Ragas metrics such as faithfulness read the retrieved context, so a trace that logs only the final answer cannot be scored. Decide how retrieval spans are named and how chunk identifiers are stored, then confirm one sample trace shows all three fields in the Langfuse UI.
LLM connection for the judge
Model-based Ragas metrics call a judge model to score each sample, so Langfuse needs a configured LLM connection that the evaluator can use. Confirm which provider or OpenAI-compatible endpoint will act as judge, which model name it exposes and who owns the API key. Keep the judge model separate from the generator model where possible, so a model does not grade its own answers. Record the connection scope (organization or project) before the first run.
Reference answers in a dataset
Metrics such as context recall and answer correctness compare output against reference answers, which must live in a Langfuse dataset with stable item identifiers. Each item should hold the question, the expected answer and, where you test retrieval, the source passages it should draw on. Version the dataset before a comparison, and keep personal or confidential content out of reference data unless your controls allow it. Ask the domain owner who signs off on reference answers.
Network path to the judge endpoint
The evaluator process must reach the judge model endpoint over the network, and in a self-hosted setup this often crosses egress controls, proxies or private gateways. Confirm the route from wherever the Ragas evaluator runs, including DNS, TLS trust and any allow-listed domains or IP ranges. Test with a single judge call before a batch run, because a blocked endpoint can look like a slow or failing metric.
Python or Node runtime for Ragas
Ragas is a Python library, so the evaluator needs a supported Python environment with the Ragas and Langfuse SDK packages installed at versions that match your server. Teams working in JS/TS should confirm which evaluation tooling they will use, since the Python route is the one described here. Pin dependency versions in a lock file, run the evaluator from the same container image as CI, and check that the runtime can read the judge credentials from your secret store rather than from source files.
How Ragas scores flow from experiments and traces into Langfuse
The diagram has two starting points: a dataset run through the RAG application inside the SDK experiment runner, and live traces from the production RAG service. Both paths call a Ragas evaluator, which sends the retrieved context, question and answer to a judge model and writes the returned scores back to Langfuse. The self-hosted Langfuse web container receives those writes and the worker container processes them asynchronously before storage. Check that both paths land in the same project and that the judge model call is billed to your own account.
Experiment and production paths both write Ragas scores into self-hosted Langfuse.
Experiment evaluators versus production trace evaluators for Ragas
Use experiment evaluators when you test a change against a fixed dataset before release. Each dataset item can carry a reference answer, and sometimes a reference context set, written or approved by your team. That reference data is what lets you score retrieval quality against a known target. Metrics that compare retrieved context with a reference, such as context recall style metrics, need these fields, so they only run where your dataset provides them. Run the same dataset against the old and new pipeline so the comparison is like for like.
- Reference-dependent metrics: Context recall and similar metrics compare retrieved chunks with the expected evidence, so every dataset item needs that field populated.
- Reference-free metrics on the same run: Faithfulness and answer relevance style metrics can still run on the question, context and answer, which adds a second view of the same outputs.
- Repeatable comparisons: Fixed datasets let you compare run scores across prompt, chunking or model changes.
- Dataset curation cost: Writing and reviewing reference answers is recurring work for your domain experts, and it grows with the dataset.
- Model-based metric cost: Each metric that calls a judge model adds token cost to every item in every run.
Confirm each metric's required inputs and the exact field names in the Ragas documentation before you map dataset keys to evaluator inputs.
Use production trace evaluators when you score live answers from real users. Live traffic normally has no reference answer, so you can only run metrics that work from the question, the retrieved context and the generated answer. Scoring every request is usually too expensive when metrics call a judge model, so most teams sample traffic and apply filters, such as a route, user segment or retrieval result count. The evaluator runs against observations or traces that Langfuse already records, so you do not need a separate pipeline to collect inputs.
- Reference-free metrics only: Metrics that need a ground truth answer cannot run on live traces unless you add one through human review or a later labeling step.
- Sampling rate and filters: Set the sample rate and filters to control judge model spend.
- Trace field mapping: Confirm that the retrieval span stores the retrieved context in the field your evaluator reads.
- Sensitive data: Live prompts and contexts can contain personal data, so review masking and retention settings before judge models read them.
- Delayed results: Scores appear after evaluation runs asynchronously, so dashboards lag behind traffic.
Confirm with your Langfuse operator that the evaluator can read the retrieval fields from your traces before you rely on the scores.
Choosing a metric depends on which inputs it needs, so check each metric against the two settings before you wire it up. Metrics that need reference data are the ones you can only run on experiments, unless you later build reference answers for sampled live traces. Metrics that use only the question, context and answer can run in both settings, which makes them the basis for comparing offline and production scores. Keep the mapping in one document so that the same metric name means the same inputs in both places.
- Experiment only: Metrics requiring reference answers or reference contexts, such as context recall style metrics.
- Both settings: Metrics that use the question, retrieved context and answer, such as faithfulness style metrics.
- Input mapping table: Record which dataset key or trace field feeds each metric input.
- Version pinning: Record the Ragas version, since metric names and inputs change between releases.
- Shared thresholds: Use the same score definitions in both settings so trends can be compared.
Confirm each metric's inputs in the Ragas documentation for the version you pin, because the requirements decide which setting a metric can support.
Wrapping a Ragas metric as a Langfuse evaluator
This sequence turns a Ragas RAG metric into a Langfuse evaluator that writes a named numeric score to traces or experiment runs. Each step ends with a check so the team knows the wiring is correct before judge model spend scales up.
Install and pin Ragas and the Langfuse SDK
An engineer on the evaluation team installs the Ragas package and the Langfuse Python SDK into a dedicated evaluation environment and pins both versions in the lock file, so metric definitions and SDK behavior do not shift between runs. Pin the Langfuse SDK to a version that matches your self-hosted server, since current SDK majors require a minimum Langfuse server release, which you should confirm in the Langfuse release notes before installing. The check is that a clean environment can import both packages and that the Langfuse client reports a successful connection to your self-hosted host.
Map retrieval fields from traces and dataset items
Decide where each Ragas input comes from: the user question, the retrieved context chunks, the generated answer and, for metrics that need it, a reference answer. In a production trace, these usually sit in observation inputs and outputs produced by your retriever and generator spans, so the mapping must name the exact span and key. For experiments, map them from dataset item fields. Write the mapping as a small function with explicit keys and fail loudly when a key is missing. The check is that running the mapping on one real trace and one dataset item returns all required fields as non-empty strings or lists.
Configure the judge model for the metric
Ragas model-based metrics call a language model to judge answers, so the platform team sets the judge model, its endpoint and its credentials in the evaluation environment rather than in application code. Record the judge model name in the score comment or metadata so results remain interpretable after the model changes. Confirm with your model provider or internal gateway which model versions are available and how they are billed. The check is a single direct metric call on one sample that returns a number and logs the judge model used.
Call the metric and return a named score
Write the evaluator function that calls the chosen Ragas metric with the mapped fields, takes the numeric result, and returns it to Langfuse with a stable score name such as the metric name, plus a comment that identifies the judge model and metric version. Keep the score name fixed across runs so charts and experiment comparisons line up. Handle a failed or empty judge response by returning no score and logging the error, not a zero. The check is one dataset item producing one score in the Langfuse UI, attached to the correct trace or run item with the expected name.
Attach the evaluator to production traces
For production traces, the team configures the evaluator to run on a sample of incoming traces that carry the retrieval and generation spans, using the Langfuse evaluator setup for observation-level evaluators. Set the sampling rate and filters deliberately, because each sampled trace triggers one or more judge model calls that are billed. Confirm that the evaluator reads the mapped span names in your environment. The check is that a set of new production traces each receives the expected score, and that traces outside the filter receive none.
Run a full experiment and compare with manual calculation
The evaluation engineer runs the wrapped metric through a Langfuse experiment across the dataset, then selects a small sample of items, typically a handful chosen to cover high and low scores, and computes the same metric by hand from the same inputs with the same judge settings. Compare the Langfuse scores with the manual results item by item. Differences usually come from mismatched field mapping, a changed judge model, or a metric version change, so resolve those before trusting trends. The check is that scores agree on the sample, and that the run is recorded so later experiments can compare against it.
What model-based Ragas metrics cost to run
Model-based Ragas metrics cost money on every scored sample, and the judge model is usually the largest line item. Several Ragas metrics, such as those that check whether retrieved context supports an answer or whether an answer is faithful to its sources, make more than one model call per sample, and each call sends the question, the retrieved passages and the answer as input tokens while the judge returns output tokens. Total spend therefore depends on how many metric calls each sample triggers, how long the retrieved context is, and which provider and model price those tokens. Ask the team to count the calls per metric from the Ragas version it plans to pin, and to measure average token counts on a sample of real retrievals before estimating anything.
Cost splits into one-time setup and recurring run cost. Setup covers wiring metrics as evaluators, building and reviewing the dataset, calibrating the judge against a small set of human labels, and configuring the LLM connection in Langfuse. Recurring cost comes from the number of samples per experiment, the number of metrics, the sampling rate on production traces, and the judge model chosen. Each of these scales the bill directly, so a large dataset run against several metrics on a premium model costs far more than a sampled production check on a smaller model. Retries after rate-limit responses add tokens and wall-clock time, and a judge endpoint with tight limits can make a run slower and more expensive at the same time. Self-hosted infrastructure also recurs: the PostgreSQL, ClickHouse and blob storage that hold scores and traces are sized by score volume, which the team should confirm against its own Langfuse scaling guide.
When requesting a quote, ask the partner or internal team to state the metric list, the sample counts for experiments and for sampled production traces, the judge model and provider with its current list price, the expected calls per sample for each metric, and the assumed retry policy. Ask who pays the model provider, since that cost usually sits with the client's account, and whether the work includes measuring token use on real data or only estimating it. Ask for the one-time and recurring components separately, and for the infrastructure assumptions behind any storage or compute line. A quote that cannot name these inputs cannot be checked against the bill that arrives later.
Mapping RAG fields to Langfuse traces, dataset items and scores
This table shows where each Ragas input and output lives in Langfuse, from the trace and retrieval observation to the dataset item and score. Read it before writing the evaluator, so that every metric reads the same fields in every experiment and production run. The main takeaway is that run metadata and score config names are what make runs comparable months later.
| Ragas input or output | Where it lives in Langfuse | Notes for consistent evaluation |
|---|---|---|
| User question | Trace input, and dataset item input for experiments | Store the exact string the user sent, not a rewritten query, so faithfulness and relevance judge the same question. |
| Retrieved contexts | Output of the retrieval observation, as a list of chunk texts | Keep chunk IDs and source references alongside the text so context precision can be traced back to documents. |
| Generated answer | Trace output, and output of the generation observation | Evaluate the final answer at trace level and the generation separately when debugging retrieval versus generation. |
| Reference answer | Dataset item expected output | Only set this for datasets with curated ground truth; leave it empty for reference-free metrics. |
| Metadata: retriever, embedding model, chunk size | Trace metadata and dataset item metadata, with the same keys in every run | Use fixed key names such as embedding_model and chunk_size so you can filter and compare experiment runs later. |
| Metric result | Score with a name, numeric data type and optional comment from the metric's reasoning | Define a score config per metric so names and value ranges stay identical across evaluators and team members. |
| Judge model and cost | Score metadata or a comment recording the judge model used | Record which model judged each score, since changing the judge changes the numbers you compare. |
Security and data handling for RAG evaluation
Retrieved contexts are often the most sensitive part of a RAG evaluation, because they carry source documents into the judge model's prompt. The cards below cover where that data goes, how judge credentials are stored, which Langfuse access and masking controls need an Enterprise license key, and what belongs in evaluation datasets.
Choose the judge model endpoint
Every Ragas metric that calls a model sends the question, the retrieved contexts and the answer to that model. Decide before the first run whether the judge sits inside your controls, such as a private endpoint in your cloud account or an internal OpenAI-compatible gateway, or whether a hosted provider is acceptable for your data classification. Ask the provider where prompts are processed and how long they are retained, and record the answer in your evaluation design.
Store judge credentials encrypted
Judge model keys should be entered as LLM connections in Langfuse, not hard-coded in evaluator functions, notebooks or CI scripts. Keep the provider keys out of repositories and build logs, and rotate them on the schedule your security team sets. Confirm how connections are encrypted in your self-hosted instance and who in your organization can view or edit them.
Langfuse access docsReview retrieved context exposure
Retrieved chunks can contain customer records, contracts or internal policy text that were never meant for a second system. Before scoring production traces, decide which fields reach the judge, whether chunks need redaction, and which traces may be sampled at all. Note that a judge score stored as a Langfuse score is also data, so the same classification rules apply to the results.
Check Enterprise-only access controls
Project-level RBAC roles, protected prompt labels, data retention policies, audit logs and server-side data masking need an Enterprise license key on self-hosted Langfuse. If your evaluation team shares a project with production engineers, or must show who viewed traces containing source documents, confirm whether the MIT version meets that need or whether the Enterprise license is required. Ask for the current license terms in writing before you plan around them.
License key docsKeep sensitive data out of datasets
Evaluation datasets are copied, versioned and shared across experiments, so a single production trace added as a dataset item can spread personal data into every run and CI log. Require a review step before any trace with retrieved source text becomes a dataset item. Replace names and identifiers with synthetic values where the answer quality does not depend on them, and set a deletion owner for each dataset.
Limit who can read scores
Ragas scores, reasons and the judge's written justifications often quote the context or answer they assessed. Treat those fields as sensitive, restrict project access to the people who need them, and confirm that masking settings cover the trace fields that feed evaluators. Test masking with a sample trace that contains a known test identifier before you rely on it for production scoring.
Comparing RAG runs without fooling yourself
A score difference between two RAG experiment runs is only meaningful if everything except the change under test was held constant. Before comparing a new retriever, chunking strategy, embedding model or prompt against a baseline, confirm that both runs used the same dataset version and the same evaluator version, including the Ragas metric implementations, their prompts and the judge model. In self-hosted Langfuse, a dataset can change after a run starts if items are added or edited, so record the dataset version each run was executed against. Likewise, changing a metric's wording or the judge model silently moves every score, so pin the evaluator definition and treat any change to it as a new baseline.
Small datasets make RAG comparisons unreliable. With a few dozen questions, one or two items flipping from faithful to unfaithful can produce a gap that looks like an improvement but is within noise. Model-based Ragas metrics add a second source of variance: the judge model can return different scores for the same answer across repeated calls, and a different judge model or temperature will shift the whole distribution. Run the baseline more than once to see how much a score moves with no change at all, and be cautious about reading a difference smaller than that spread. Ask your team to decide what sample size and judge settings are acceptable before the first comparison, not after the results arrive.
Each run needs configuration metadata attached so that a comparison can be explained later. At minimum, record the retriever settings, chunk size and overlap, embedding model identifier, prompt version, generator model, top-k value and judge model, and store them with the run rather than in a wiki page. For a CI regression gate, agree on thresholds with the owners of the application before the gate is switched on, and specify whether the gate compares a single metric or several, and how many items must be scored for the result to count. Finally, confirm in your own instance how your Langfuse version presents run comparisons, including which metadata fields are shown side by side and whether per-item scores can be inspected, since the interface you rely on may differ between versions.
Failure points that skew Ragas scores
This table lists the failure points that most often distort Ragas scores in Langfuse, with the cause and fix for each. Read it before the first experiment run or before turning on production scoring, since several of these problems produce scores that look valid but compare the wrong things. Check your own score mapping and judge settings against each row before trusting a trend line.
| Failure point | Typical cause | Fix |
|---|---|---|
| Scores missing or attached to the wrong observation | The question, retrieved contexts or answer field is empty, or is mapped to a different span than the retriever or generator span | Map each Ragas input to a named observation in the trace, log a sample trace, and confirm the score appears on the intended observation before scaling up |
| Scores drift between runs | The judge model, its version or temperature changed between experiments, so the same outputs receive different metric values | Pin the judge model and temperature in the evaluator configuration, record them with each run, and rerun a baseline before comparing changes |
| Evaluator timeouts or rate limits | The judge endpoint throttles requests, or each Ragas metric makes several judge calls per item, so large batches stall or fail | Lower concurrency, add retries with backoff, and confirm the judge endpoint's rate limits and timeout settings with the provider or your gateway |
| Scores never arrive for production traces | The Langfuse worker is backlogged or under-scaled, so traces are ingested but evaluation jobs wait in the queue | Check worker load and queue depth, scale worker containers on CPU use as the Langfuse scaling guide recommends, and compare trace timestamps with score timestamps |
| Reference-based metrics run without references | Metrics such as context recall or answer correctness need a ground-truth answer, but production traces do not carry one | Limit reference-based metrics to dataset experiments, or attach reviewed reference answers to dataset items before running them on production traffic |
| Faithfulness scores on unclear claims | Answers are long or contain statements that the judge cannot split into verifiable claims, so the metric reflects formatting more than grounding | Review a sample of low scores by hand, shorten the answer format for evaluation, and compare judge results with human labels before relying on the metric |
Questions teams ask before running Ragas in Langfuse
How much effort does wrapping Ragas metrics as Langfuse evaluators take?
Wrapping a Ragas metric is usually the smaller part of the work. Each metric needs a Python function that maps Langfuse dataset fields (question, retrieved contexts, generated answer, reference answer) onto the inputs the metric expects, then returns a score that Langfuse can record. Effort grows with the number of metrics, how many RAG pipelines feed the same evaluator, and how much your data needs cleaning before it maps cleanly. Expect the most time to go into agreeing what a good answer means for your domain and checking that the scores match what reviewers would decide. Ask any partner to state which metrics, which pipelines and which datasets are in scope before quoting.
What drives the cost of the judge model behind Ragas metrics?
Most Ragas metrics that judge answers call a language model, so every evaluated trace or dataset item adds model calls. The main drivers are the number of metrics per item, the length of the retrieved contexts sent with each call, the number of items in each experiment run, how often you rerun experiments, and whether production traces are scored at all or only sampled. Model pricing is set by your provider or internal endpoint, so the figure to request is your own per-call cost multiplied by your planned volume. Ask for a quote that lists the judge model, the metrics, the sample size and the rerun frequency so the cost can be checked.
Can our internal engineers set up Ragas evaluation in Langfuse without a partner?
Yes, a team with Python experience, access to a self-hosted Langfuse instance and a working RAG pipeline can wrap Ragas metrics and run experiments on its own. The skills that usually take longer to build are dataset design, evaluation judgment and operating the judge model connection. Teams often find it hard to decide which metrics matter for their use case, to keep test data free of sensitive content, and to keep scores stable across Ragas and Langfuse version changes. A partner is useful when you want a fixed scope, a second review of metric choices or help standing up the platform first. Your engineers should confirm the Ragas version they will pin before starting.
What does the work need from data and infrastructure owners?
Data owners need to confirm which documents, questions and answers may be used as test data, and to approve how any personal data is removed or masked before it reaches Langfuse or a judge model. Infrastructure owners need to confirm that the Langfuse instance, its PostgreSQL, ClickHouse and blob storage, and the judge model endpoint are reachable from the evaluation runner, and that outbound model calls follow your network and data residency rules. Security teams should review which provider or internal endpoint receives retrieved context, since that text can contain confidential material. Agree these approvals before dataset building starts, because they often decide which metrics and models can be used.
How long does a Ragas evaluation setup take, in phases?
The work usually runs in phases rather than against a fixed duration. The first phase confirms the RAG pipeline, the metrics in scope and the judge model connection. The second builds a representative dataset with reviewed reference answers and removes sensitive content. The third wraps the metrics as evaluators and checks them against human judgments on a small sample. The fourth runs baseline experiments, compares runs and adds production trace scoring if it is needed. Each phase can be extended by approvals, data quality issues or the number of pipelines. Ask for a written plan that names the exit criteria for each phase instead of a single end date.
Does Langfuse have a built-in Ragas integration?
Confirm this before planning, because the answer depends on the Langfuse version you run and the current documentation. The Langfuse documentation and self-hosting guides describe evaluators, experiments and custom scores, and a team can attach Ragas metrics through those general mechanisms by calling Ragas in code and recording the results. Check the Langfuse evaluation documentation for your pinned version to see whether a prebuilt Ragas option exists, and check the release notes for changes. Until you confirm that, treat Ragas as a metric library your code calls, not as a feature that Langfuse ships.
How do Ragas scores stay comparable across experiment runs?
Scores stay comparable when the dataset version, the judge model, the metric version, the prompt templates inside the metrics and the sampling settings are pinned for each run. If any of these changes between runs, a score difference may reflect the change in setup rather than in your RAG pipeline. Record the Ragas version and judge model name as run metadata, keep a fixed baseline run, and review a sample of scores by hand after each judge change. Your engineers should agree this rule before the first comparison, because it is much harder to add later.
How DeployOpen works on this
DeployOpen plans and builds RAG evaluation with Ragas metrics inside a self-hosted Langfuse that runs in your infrastructure. We start from the questions your team needs answered about retrieval and generation quality, then wire the metrics into experiments and production traces with documented ownership and handover.
How we scope
- Written scope listing which Ragas metrics apply to your retrieval and generation pipeline and why
- Inventory of the RAG traces, datasets and judge models that the evaluators will read and call
- Decisions on which metrics run on experiments, which sample production traces, and the model-based cost each implies
- Fixed-scope agreement covering deliverables and timelines before any build work starts
How we build
- Wrapping selected Ragas metrics as Langfuse evaluators with tested inputs for question, context and answer fields
- Connecting the evaluators to experiment runs and to sampled production traces in your self-hosted instance
- Testing scores against a reviewed sample of answers so the team can see where metrics agree or disagree with reviewers
- Configuring model connections, sampling rules and filters so judge calls stay within the budget agreed in scope
How we hand over
- Runbook covering evaluator configuration, dataset conventions, metric definitions and how to compare runs
- Documentation of model-based metric costs, including which calls recur on every trace and what to ask a provider for
- Walkthrough with your engineers and evaluation owners so they can add or retire metrics without a partner
- Written record of the test results and the configuration state at handover
How we support
- Ongoing support and upgrades for the Ragas and Langfuse versions in use, available as a retainer
- Periodic re-testing of evaluators after Langfuse upgrades, SDK changes or model provider changes
- Review of metric drift and cost trends when your retrieval pipeline or document corpus changes
- Option to add continuous security and quality testing of the RAG application under the same retainer

