__init__() — langchain Function Reference
Architecture documentation for the __init__() function in json_distance.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD d0762f64_a7cc_0f12_772c_aac695ded0ec["__init__()"] 481593b0_ea9f_1093_bbdc_d3bd06c33d40["JsonEditDistanceEvaluator"] d0762f64_a7cc_0f12_772c_aac695ded0ec -->|defined in| 481593b0_ea9f_1093_bbdc_d3bd06c33d40 style d0762f64_a7cc_0f12_772c_aac695ded0ec fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/evaluation/parsing/json_distance.py lines 34–77
def __init__(
self,
string_distance: Callable[[str, str], float] | None = None,
canonicalize: Callable[[Any], Any] | None = None,
**_: Any,
) -> None:
"""Initialize the JsonEditDistanceEvaluator.
Args:
string_distance: A callable that computes the distance between two strings.
If not provided, a Damerau-Levenshtein distance from the `rapidfuzz`
package will be used.
canonicalize: A callable that converts a parsed JSON object into its
canonical string form.
If not provided, the default behavior is to serialize the JSON with
sorted keys and no extra whitespace.
Raises:
ImportError: If the `rapidfuzz` package is not installed and no
`string_distance` function is provided.
"""
super().__init__()
if string_distance is not None:
self._string_distance = string_distance
else:
try:
from rapidfuzz import distance as rfd
except ImportError as e:
msg = (
"The default string_distance operator for the "
" JsonEditDistanceEvaluator requires installation of "
"the rapidfuzz package. "
"Please install it with `pip install rapidfuzz`."
)
raise ImportError(msg) from e
self._string_distance = rfd.DamerauLevenshtein.normalized_distance
if canonicalize is not None:
self._canonicalize = canonicalize
else:
self._canonicalize = lambda x: json.dumps(
x,
separators=(",", ":"),
sort_keys=True, # eliminate whitespace
)
Domain
Subdomains
Source
Frequently Asked Questions
What does __init__() do?
__init__() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/evaluation/parsing/json_distance.py.
Where is __init__() defined?
__init__() is defined in libs/langchain/langchain_classic/evaluation/parsing/json_distance.py at line 34.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free