> ## 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**: <Tooltip tip="Continuously evaluate your models and datasets as you iterate on their versions.">development</Tooltip>
  and <Tooltip tip="Monitor a model in production, measure its health, check for drifts and set up alerts.">monitoring</Tooltip>.

## 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

## Test configuration examples

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

<CodeGroup>
  ```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",
          "insightParameters": null,
          "measurement": "meanEditDistance",
          "operator": "<",
          "value": 10
        }
      ],
      "subpopulationFilters": null,
      "mode": "development",
      "usesValidationDataset": true,
      "usesTrainingDataset": false,
      "usesMlModel": false,
      "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",
          "insightParameters": null,
          "measurement": "meanEditDistance",
          "operator": "<",
          "value": 10
        }
      ],
      "subpopulationFilters": null,
      "mode": "monitoring",
      "usesProductionData": true,
      "evaluationWindow": 3600,
      "delayWindow": 0,
      "syncId": "b4dee7dc-4f15-48ca-a282-63e2c04e0689"
    }
  ]
  ```
</CodeGroup>

## Related

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