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

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.

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

Parameters

NameTypeDescription
prediction*str

The predicted string to compare.

reference*str

The reference string to compare against.

configOptional[EditDistanceConfig]
Default:None

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.

View source on GitHub