Home / Class/ StringDistanceEvalChain Class — langchain Architecture

StringDistanceEvalChain Class — langchain Architecture

Architecture documentation for the StringDistanceEvalChain class in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  6ec53315_a0c1_2cad_5a74_71802365b6b8["StringDistanceEvalChain"]
  42f35457_68a1_961e_1ac4_cbaa4a2b48b3["StringEvaluator"]
  6ec53315_a0c1_2cad_5a74_71802365b6b8 -->|extends| 42f35457_68a1_961e_1ac4_cbaa4a2b48b3
  c5dd7632_1609_5447_2696_8f61ec5b865e["_RapidFuzzChainMixin"]
  6ec53315_a0c1_2cad_5a74_71802365b6b8 -->|extends| c5dd7632_1609_5447_2696_8f61ec5b865e
  02530704_9a53_33b0_b7e6_7a524bfb049e["base.py"]
  6ec53315_a0c1_2cad_5a74_71802365b6b8 -->|defined in| 02530704_9a53_33b0_b7e6_7a524bfb049e
  d00ef266_c5b6_1cc9_4544_db1478a3a0da["requires_input()"]
  6ec53315_a0c1_2cad_5a74_71802365b6b8 -->|method| d00ef266_c5b6_1cc9_4544_db1478a3a0da
  0f882050_977d_5f2e_e9b1_eceea9e00203["requires_reference()"]
  6ec53315_a0c1_2cad_5a74_71802365b6b8 -->|method| 0f882050_977d_5f2e_e9b1_eceea9e00203
  8377f1ce_14d3_5204_e76b_78f48c2ace8e["input_keys()"]
  6ec53315_a0c1_2cad_5a74_71802365b6b8 -->|method| 8377f1ce_14d3_5204_e76b_78f48c2ace8e
  e509183e_f2d1_730f_49fd_715f331ae01e["evaluation_name()"]
  6ec53315_a0c1_2cad_5a74_71802365b6b8 -->|method| e509183e_f2d1_730f_49fd_715f331ae01e
  4ad23e8f_38cc_1818_d255_53c358feaba0["_call()"]
  6ec53315_a0c1_2cad_5a74_71802365b6b8 -->|method| 4ad23e8f_38cc_1818_d255_53c358feaba0
  edde8e2e_40f0_15ef_6ae0_2d9b69f5cb02["_acall()"]
  6ec53315_a0c1_2cad_5a74_71802365b6b8 -->|method| edde8e2e_40f0_15ef_6ae0_2d9b69f5cb02
  1bf3996c_a9e3_e766_9b90_3d668a59410c["_evaluate_strings()"]
  6ec53315_a0c1_2cad_5a74_71802365b6b8 -->|method| 1bf3996c_a9e3_e766_9b90_3d668a59410c
  169ab69c_36c2_d92c_32c4_b6133c9273e4["_aevaluate_strings()"]
  6ec53315_a0c1_2cad_5a74_71802365b6b8 -->|method| 169ab69c_36c2_d92c_32c4_b6133c9273e4

Relationship Graph

Source Code

libs/langchain/langchain_classic/evaluation/string_distance/base.py lines 165–322

class StringDistanceEvalChain(StringEvaluator, _RapidFuzzChainMixin):
    """Compute string distances between the prediction and the reference.

    Examples:
    ----------
    >>> from langchain_classic.evaluation import StringDistanceEvalChain
    >>> evaluator = StringDistanceEvalChain()
    >>> evaluator.evaluate_strings(
            prediction="Mindy is the CTO",
            reference="Mindy is the CEO",
        )

    Using the `load_evaluator` function:

    >>> from langchain_classic.evaluation import load_evaluator
    >>> evaluator = load_evaluator("string_distance")
    >>> evaluator.evaluate_strings(
            prediction="The answer is three",
            reference="three",
        )
    """

    @property
    def requires_input(self) -> bool:
        """This evaluator does not require input."""
        return False

    @property
    def requires_reference(self) -> bool:
        """This evaluator does not require a reference."""
        return True

    @property
    def input_keys(self) -> list[str]:
        """Get the input keys.

        Returns:
            The input keys.
        """
        return ["reference", "prediction"]

    @property
    def evaluation_name(self) -> str:
        """Get the evaluation name.

        Returns:
            The evaluation name.
        """
        return f"{self.distance.value}_distance"

    @override
    def _call(
        self,
        inputs: dict[str, Any],
        run_manager: CallbackManagerForChainRun | None = None,
    ) -> dict[str, Any]:
        """Compute the string distance between the prediction and the reference.

        Args:
            inputs: The input values.
            run_manager: The callback manager.

        Returns:
            The evaluation results containing the score.
        """
        return {"score": self.compute_metric(inputs["reference"], inputs["prediction"])}

    @override
    async def _acall(
        self,
        inputs: dict[str, Any],
        run_manager: AsyncCallbackManagerForChainRun | None = None,
    ) -> dict[str, Any]:
        """Compute the string distance between the prediction and the reference.

        Args:
            inputs: The input values.
            run_manager: The callback manager.

        Returns:
            The evaluation results containing the score.

Frequently Asked Questions

What is the StringDistanceEvalChain class?
StringDistanceEvalChain is a class in the langchain codebase, defined in libs/langchain/langchain_classic/evaluation/string_distance/base.py.
Where is StringDistanceEvalChain defined?
StringDistanceEvalChain is defined in libs/langchain/langchain_classic/evaluation/string_distance/base.py at line 165.
What does StringDistanceEvalChain extend?
StringDistanceEvalChain extends StringEvaluator, _RapidFuzzChainMixin.

Analyze Your Own Codebase

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

Try Supermodel Free