Home / Function/ _get_metric() — langchain Function Reference

_get_metric() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  ce394d48_537e_9c2f_6235_1e3ee8acabb5["_get_metric()"]
  dc2d52f5_736c_0ec2_ad57_0e2fdaa94e04["_EmbeddingDistanceChainMixin"]
  ce394d48_537e_9c2f_6235_1e3ee8acabb5 -->|defined in| dc2d52f5_736c_0ec2_ad57_0e2fdaa94e04
  af8d1584_7461_17c4_1dc0_409b11712821["_compute_score()"]
  af8d1584_7461_17c4_1dc0_409b11712821 -->|calls| ce394d48_537e_9c2f_6235_1e3ee8acabb5
  style ce394d48_537e_9c2f_6235_1e3ee8acabb5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/evaluation/embedding_distance/base.py lines 171–190

    def _get_metric(self, metric: EmbeddingDistance) -> Any:
        """Get the metric function for the given metric name.

        Args:
            metric: The metric name.

        Returns:
            The metric function.
        """
        metrics = {
            EmbeddingDistance.COSINE: self._cosine_distance,
            EmbeddingDistance.EUCLIDEAN: self._euclidean_distance,
            EmbeddingDistance.MANHATTAN: self._manhattan_distance,
            EmbeddingDistance.CHEBYSHEV: self._chebyshev_distance,
            EmbeddingDistance.HAMMING: self._hamming_distance,
        }
        if metric in metrics:
            return metrics[metric]
        msg = f"Invalid metric: {metric}"
        raise ValueError(msg)

Domain

Subdomains

Called By

Frequently Asked Questions

What does _get_metric() do?
_get_metric() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/evaluation/embedding_distance/base.py.
Where is _get_metric() defined?
_get_metric() is defined in libs/langchain/langchain_classic/evaluation/embedding_distance/base.py at line 171.
What calls _get_metric()?
_get_metric() is called by 1 function(s): _compute_score.

Analyze Your Own Codebase

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

Try Supermodel Free