Home / Class/ FactWithEvidence Class — langchain Architecture

FactWithEvidence Class — langchain Architecture

Architecture documentation for the FactWithEvidence class in citation_fuzzy_match.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  c34f4615_223b_2b12_36ce_287f11058e32["FactWithEvidence"]
  3fe204c3_507d_e239_ac89_e54bd9ed1a7b["citation_fuzzy_match.py"]
  c34f4615_223b_2b12_36ce_287f11058e32 -->|defined in| 3fe204c3_507d_e239_ac89_e54bd9ed1a7b
  5e2b5a25_eccf_bb19_1eb5_5064cae0ce0a["_get_span()"]
  c34f4615_223b_2b12_36ce_287f11058e32 -->|method| 5e2b5a25_eccf_bb19_1eb5_5064cae0ce0a
  8be70a7e_02e6_604b_b482_cd466d411d5b["get_spans()"]
  c34f4615_223b_2b12_36ce_287f11058e32 -->|method| 8be70a7e_02e6_604b_b482_cd466d411d5b

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/openai_functions/citation_fuzzy_match.py lines 15–57

class FactWithEvidence(BaseModel):
    """Class representing a single statement.

    Each fact has a body and a list of sources.
    If there are multiple facts make sure to break them apart
    such that each one only uses a set of sources that are relevant to it.
    """

    fact: str = Field(..., description="Body of the sentence, as part of a response")
    substring_quote: list[str] = Field(
        ...,
        description=(
            "Each source should be a direct quote from the context, "
            "as a substring of the original content"
        ),
    )

    def _get_span(self, quote: str, context: str, errs: int = 100) -> Iterator[str]:
        import regex

        minor = quote
        major = context

        errs_ = 0
        s = regex.search(f"({minor}){{e<={errs_}}}", major)
        while s is None and errs_ <= errs:
            errs_ += 1
            s = regex.search(f"({minor}){{e<={errs_}}}", major)

        if s is not None:
            yield from s.spans()

    def get_spans(self, context: str) -> Iterator[str]:
        """Get spans of the substring quote in the context.

        Args:
            context: The context in which to find the spans of the substring quote.

        Returns:
            An iterator over the spans of the substring quote in the context.
        """
        for quote in self.substring_quote:
            yield from self._get_span(quote, context)

Frequently Asked Questions

What is the FactWithEvidence class?
FactWithEvidence is a class in the langchain codebase, defined in libs/langchain/langchain_classic/chains/openai_functions/citation_fuzzy_match.py.
Where is FactWithEvidence defined?
FactWithEvidence is defined in libs/langchain/langchain_classic/chains/openai_functions/citation_fuzzy_match.py at line 15.

Analyze Your Own Codebase

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

Try Supermodel Free