LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Client
  • AsyncClient
  • Run Helpers
  • Run Trees
  • Evaluation
  • Schemas
  • Utilities
  • Wrappers
  • Anonymizer
  • Testing
  • Expect API
  • Middleware
  • Pytest Plugin
  • Deployment SDK
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewClientAsyncClientRun HelpersRun TreesEvaluationSchemasUtilitiesWrappersAnonymizerTestingExpect APIMiddlewarePytest PluginDeployment SDK
Language
Theme
Pythonlangsmith_expect_Expectedit_distance
Method●Since v0.1

edit_distance

Copy
edit_distance(
  self,
  prediction: str,
  reference: str,
  *,
  config: Optional[EditDistanceConfig
View source on GitHub
]
=
None
)
->
_Matcher

Parameters

NameTypeDescription
prediction*str
reference*str
configOptional[EditDistanceConfig]
Default:None

Compute the string distance between the prediction and reference.

This logs the string distance (Damerau-Levenshtein) to LangSmith and returns a _Matcher instance for making assertions on the distance value.

This depends on the rapidfuzz package for string distance computation.

The predicted string to compare.

The reference string to compare against.

Optional configuration for the string distance evaluator.

Supported options:

  • metric: The distance metric to use for comparison.

    Supported values: 'damerau_levenshtein', 'levenshtein', 'jaro', 'jaro_winkler', 'hamming', 'indel'.

  • normalize_score: Whether to normalize the score between 0 and 1.