Home / File/ structured_query.py — langchain Source File

structured_query.py — langchain Source File

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

File python CoreAbstractions RunnableInterface 5 imports 2 functions 8 classes

Entity Profile

Dependency Diagram

graph LR
  4b8f6521_b3ed_e363_c7fc_b200f4741ff9["structured_query.py"]
  cccbe73e_4644_7211_4d55_e8fb133a8014["abc"]
  4b8f6521_b3ed_e363_c7fc_b200f4741ff9 --> cccbe73e_4644_7211_4d55_e8fb133a8014
  b188e880_71c6_b93e_127d_c22666293d37["enum"]
  4b8f6521_b3ed_e363_c7fc_b200f4741ff9 --> b188e880_71c6_b93e_127d_c22666293d37
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  4b8f6521_b3ed_e363_c7fc_b200f4741ff9 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  4b8f6521_b3ed_e363_c7fc_b200f4741ff9 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  4b8f6521_b3ed_e363_c7fc_b200f4741ff9 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  style 4b8f6521_b3ed_e363_c7fc_b200f4741ff9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Internal representation of a structured query language."""

from __future__ import annotations

from abc import ABC, abstractmethod
from enum import Enum
from typing import TYPE_CHECKING, Any

from pydantic import BaseModel

if TYPE_CHECKING:
    from collections.abc import Sequence


class Visitor(ABC):
    """Defines interface for IR translation using a visitor pattern."""

    allowed_comparators: Sequence[Comparator] | None = None
    """Allowed comparators for the visitor."""

    allowed_operators: Sequence[Operator] | None = None
    """Allowed operators for the visitor."""

    def _validate_func(self, func: Operator | Comparator) -> None:
        if (
            isinstance(func, Operator)
            and self.allowed_operators is not None
            and func not in self.allowed_operators
        ):
            msg = (
                f"Received disallowed operator {func}. Allowed "
                f"comparators are {self.allowed_operators}"
            )
            raise ValueError(msg)
        if (
            isinstance(func, Comparator)
            and self.allowed_comparators is not None
            and func not in self.allowed_comparators
        ):
            msg = (
                f"Received disallowed comparator {func}. Allowed "
                f"comparators are {self.allowed_comparators}"
            )
            raise ValueError(msg)

    @abstractmethod
    def visit_operation(self, operation: Operation) -> Any:
        """Translate an Operation.

        Args:
            operation: Operation to translate.
        """

    @abstractmethod
    def visit_comparison(self, comparison: Comparison) -> Any:
        """Translate a Comparison.

        Args:
            comparison: Comparison to translate.
        """
// ... (144 more lines)

Subdomains

Dependencies

  • abc
  • collections.abc
  • enum
  • pydantic
  • typing

Frequently Asked Questions

What does structured_query.py do?
structured_query.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 structured_query.py?
structured_query.py defines 2 function(s): _to_snake_case, collections.
What does structured_query.py depend on?
structured_query.py imports 5 module(s): abc, collections.abc, enum, pydantic, typing.
Where is structured_query.py in the architecture?
structured_query.py is located at libs/core/langchain_core/structured_query.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/core/langchain_core).

Analyze Your Own Codebase

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

Try Supermodel Free