_euclidean_distance() — langchain Function Reference
Architecture documentation for the _euclidean_distance() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 5fc9ebcf_0906_f3ae_cddd_91b2aafd49a5["_euclidean_distance()"] dc2d52f5_736c_0ec2_ad57_0e2fdaa94e04["_EmbeddingDistanceChainMixin"] 5fc9ebcf_0906_f3ae_cddd_91b2aafd49a5 -->|defined in| dc2d52f5_736c_0ec2_ad57_0e2fdaa94e04 91b8ba41_75bf_8afd_e893_d85d055226da["_check_numpy()"] 5fc9ebcf_0906_f3ae_cddd_91b2aafd49a5 -->|calls| 91b8ba41_75bf_8afd_e893_d85d055226da style 5fc9ebcf_0906_f3ae_cddd_91b2aafd49a5 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/evaluation/embedding_distance/base.py lines 241–261
def _euclidean_distance(a: Any, b: Any) -> Any:
"""Compute the Euclidean distance between two vectors.
Args:
a (np.ndarray): The first vector.
b (np.ndarray): The second vector.
Returns:
np.floating: The Euclidean distance.
"""
try:
from scipy.spatial.distance import euclidean
return euclidean(a.flatten(), b.flatten())
except ImportError:
if _check_numpy():
import numpy as np
return np.linalg.norm(a - b)
return sum((x - y) * (x - y) for x, y in zip(a, b, strict=False)) ** 0.5
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does _euclidean_distance() do?
_euclidean_distance() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/evaluation/embedding_distance/base.py.
Where is _euclidean_distance() defined?
_euclidean_distance() is defined in libs/langchain/langchain_classic/evaluation/embedding_distance/base.py at line 241.
What does _euclidean_distance() call?
_euclidean_distance() calls 1 function(s): _check_numpy.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free