Home / Function/ _manhattan_distance() — langchain Function Reference

_manhattan_distance() — langchain Function Reference

Architecture documentation for the _manhattan_distance() function in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  cc8c74ee_5ac7_6e8f_afaf_c9ff702bf10c["_manhattan_distance()"]
  dc2d52f5_736c_0ec2_ad57_0e2fdaa94e04["_EmbeddingDistanceChainMixin"]
  cc8c74ee_5ac7_6e8f_afaf_c9ff702bf10c -->|defined in| dc2d52f5_736c_0ec2_ad57_0e2fdaa94e04
  91b8ba41_75bf_8afd_e893_d85d055226da["_check_numpy()"]
  cc8c74ee_5ac7_6e8f_afaf_c9ff702bf10c -->|calls| 91b8ba41_75bf_8afd_e893_d85d055226da
  caa53c2b_01ef_7204_a5e6_ad683c86dbd2["_import_numpy()"]
  cc8c74ee_5ac7_6e8f_afaf_c9ff702bf10c -->|calls| caa53c2b_01ef_7204_a5e6_ad683c86dbd2
  style cc8c74ee_5ac7_6e8f_afaf_c9ff702bf10c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/evaluation/embedding_distance/base.py lines 264–283

    def _manhattan_distance(a: Any, b: Any) -> Any:
        """Compute the Manhattan distance between two vectors.

        Args:
            a (np.ndarray): The first vector.
            b (np.ndarray): The second vector.

        Returns:
            np.floating: The Manhattan distance.
        """
        try:
            from scipy.spatial.distance import cityblock

            return cityblock(a.flatten(), b.flatten())
        except ImportError:
            if _check_numpy():
                np = _import_numpy()
                return np.sum(np.abs(a - b))

            return sum(abs(x - y) for x, y in zip(a, b, strict=False))

Domain

Subdomains

Frequently Asked Questions

What does _manhattan_distance() do?
_manhattan_distance() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/evaluation/embedding_distance/base.py.
Where is _manhattan_distance() defined?
_manhattan_distance() is defined in libs/langchain/langchain_classic/evaluation/embedding_distance/base.py at line 264.
What does _manhattan_distance() call?
_manhattan_distance() calls 2 function(s): _check_numpy, _import_numpy.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free