> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openlayer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Edit distance

> Learn how to use the edit distance test

## Definition

The edit distance test measures the minimum number of single-character insertions, deletions, or substitutions required to transform one string into another, serving as a measure of their similarity.

## Taxonomy

* **Task types**: LLM.
* **Availability**: development (Continuously evaluate your models and datasets as you iterate on their versions.)
  and monitoring (Monitor a model in production, measure its health, check for drifts and set up alerts.).

## Why it matters

* Edit distance provides a character-level measure of how different two strings are, which is useful for evaluating text generation quality.
* This metric is particularly valuable when you need to measure fine-grained differences between generated and expected text.
* Lower edit distances indicate higher similarity between the generated output and the reference text.

## Required columns

To compute this metric, your dataset must contain the following columns:

* **Outputs**: The generated text from your LLM
* **Ground truths**: The reference/expected text to compare against

> [!NOTE]
>
> Edit distance is computed on the first 2,000 characters of each output and
> ground truth, so for longer texts the score is an approximation. Keep this in
> mind when choosing thresholds for long-form outputs.

## Test configuration examples

If you are writing a `tests.json`, here are a few valid configurations for the edit distance test:

```json Development theme={null}
[
  {
    "name": "Mean edit distance below 10",
    "description": "Ensure that the mean edit distance between generated and reference text is below 10 characters",
    "type": "performance",
    "subtype": "metricThreshold",
    "thresholds": [
      {
        "insightName": "metrics",
        "measurement": "meanEditDistance",
        "operator": "<",
        "value": 10
      }
    ],
    "subpopulationFilters": null,
    "mode": "development",
    "usesValidationDataset": true,
    "usesTrainingDataset": false,
    "usesMlModel": true,
    "syncId": "b4dee7dc-4f15-48ca-a282-63e2c04e0689"
  }
]
```

```json Monitoring theme={null}
[
  {
    "name": "Mean edit distance below 10",
    "description": "Ensure that the mean edit distance between generated and reference text is below 10 characters",
    "type": "performance",
    "subtype": "metricThreshold",
    "thresholds": [
      {
        "insightName": "metrics",
        "measurement": "meanEditDistance",
        "operator": "<",
        "value": 10
      }
    ],
    "subpopulationFilters": null,
    "mode": "monitoring",
    "usesProductionData": true,
    "evaluationWindow": 3600,
    "delayWindow": 0,
    "syncId": "b4dee7dc-4f15-48ca-a282-63e2c04e0689"
  }
]
```

## Related

* [BLEU score test](https://docs.openlayer.com/tests/catalog/bleu-score.md) - Measure n-gram based text similarity.
* [Exact match test](https://docs.openlayer.com/tests/catalog/exact-match.md) - Assess identical string matches.
* [Quasi-exact match test](https://docs.openlayer.com/tests/catalog/quasi-exact-match.md) - Allow partial matches and variations.
* [Aggregate metrics](https://docs.openlayer.com/tests/performance/aggregate-metrics) - Overview of all available metrics.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.