Home / File/ base.py — langchain Source File

base.py — langchain Source File

Architecture documentation for base.py, a python file in the langchain codebase. 12 imports, 0 dependents.

File python CoreAbstractions RunnableInterface 12 imports 1 functions 4 classes

Entity Profile

Dependency Diagram

graph LR
  02530704_9a53_33b0_b7e6_7a524bfb049e["base.py"]
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  02530704_9a53_33b0_b7e6_7a524bfb049e --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  b188e880_71c6_b93e_127d_c22666293d37["enum"]
  02530704_9a53_33b0_b7e6_7a524bfb049e --> b188e880_71c6_b93e_127d_c22666293d37
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  02530704_9a53_33b0_b7e6_7a524bfb049e --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  f3bc7443_c889_119d_0744_aacc3620d8d2["langchain_core.callbacks"]
  02530704_9a53_33b0_b7e6_7a524bfb049e --> f3bc7443_c889_119d_0744_aacc3620d8d2
  e8ec017e_6c91_4b34_675f_2a96c5aa9be6["langchain_core.callbacks.manager"]
  02530704_9a53_33b0_b7e6_7a524bfb049e --> e8ec017e_6c91_4b34_675f_2a96c5aa9be6
  f4d905c6_a2b2_eb8f_be9b_7808b72f6a16["langchain_core.utils"]
  02530704_9a53_33b0_b7e6_7a524bfb049e --> f4d905c6_a2b2_eb8f_be9b_7808b72f6a16
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  02530704_9a53_33b0_b7e6_7a524bfb049e --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  02530704_9a53_33b0_b7e6_7a524bfb049e --> 91721f45_4909_e489_8c1f_084f8bd87145
  01158a5b_b299_f45d_92e9_2a7433a1a91a["langchain_classic.chains.base"]
  02530704_9a53_33b0_b7e6_7a524bfb049e --> 01158a5b_b299_f45d_92e9_2a7433a1a91a
  538b302b_528d_b6e6_cf56_04147780d18b["langchain_classic.evaluation.schema"]
  02530704_9a53_33b0_b7e6_7a524bfb049e --> 538b302b_528d_b6e6_cf56_04147780d18b
  52a02ed3_b44b_45aa_e71c_064994c739be["langchain_classic.schema"]
  02530704_9a53_33b0_b7e6_7a524bfb049e --> 52a02ed3_b44b_45aa_e71c_064994c739be
  927b7bf8_8755_9458_b82b_b966efa51e6a["rapidfuzz"]
  02530704_9a53_33b0_b7e6_7a524bfb049e --> 927b7bf8_8755_9458_b82b_b966efa51e6a
  style 02530704_9a53_33b0_b7e6_7a524bfb049e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""String distance evaluators based on the RapidFuzz library."""

from collections.abc import Callable
from enum import Enum
from typing import Any

from langchain_core.callbacks import Callbacks
from langchain_core.callbacks.manager import (
    AsyncCallbackManagerForChainRun,
    CallbackManagerForChainRun,
)
from langchain_core.utils import pre_init
from pydantic import Field
from typing_extensions import override

from langchain_classic.chains.base import Chain
from langchain_classic.evaluation.schema import PairwiseStringEvaluator, StringEvaluator
from langchain_classic.schema import RUN_KEY


def _load_rapidfuzz() -> Any:
    """Load the RapidFuzz library.

    Raises:
        ImportError: If the rapidfuzz library is not installed.

    Returns:
        The `rapidfuzz.distance` module.
    """
    try:
        import rapidfuzz
    except ImportError as e:
        msg = (
            "Please install the rapidfuzz library to use the FuzzyMatchStringEvaluator."
            "Please install it with `pip install rapidfuzz`."
        )
        raise ImportError(msg) from e
    return rapidfuzz.distance


class StringDistance(str, Enum):
    """Distance metric to use.

    Attributes:
        `DAMERAU_LEVENSHTEIN`: The Damerau-Levenshtein distance.
        `LEVENSHTEIN`: The Levenshtein distance.
        `JARO`: The Jaro distance.
        `JARO_WINKLER`: The Jaro-Winkler distance.
        `HAMMING`: The Hamming distance.
        `INDEL`: The Indel distance.
    """

    DAMERAU_LEVENSHTEIN = "damerau_levenshtein"
    LEVENSHTEIN = "levenshtein"
    JARO = "jaro"
    JARO_WINKLER = "jaro_winkler"
    HAMMING = "hamming"
    INDEL = "indel"


// ... (393 more lines)

Subdomains

Functions

Dependencies

  • collections.abc
  • enum
  • langchain_classic.chains.base
  • langchain_classic.evaluation.schema
  • langchain_classic.schema
  • langchain_core.callbacks
  • langchain_core.callbacks.manager
  • langchain_core.utils
  • pydantic
  • rapidfuzz
  • typing
  • typing_extensions

Frequently Asked Questions

What does base.py do?
base.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in base.py?
base.py defines 1 function(s): _load_rapidfuzz.
What does base.py depend on?
base.py imports 12 module(s): collections.abc, enum, langchain_classic.chains.base, langchain_classic.evaluation.schema, langchain_classic.schema, langchain_core.callbacks, langchain_core.callbacks.manager, langchain_core.utils, and 4 more.
Where is base.py in the architecture?
base.py is located at libs/langchain/langchain_classic/evaluation/string_distance/base.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain/langchain_classic/evaluation/string_distance).

Analyze Your Own Codebase

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

Try Supermodel Free