Home / Function/ load_query_constructor_chain() — langchain Function Reference

load_query_constructor_chain() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  7c645a0f_77f7_93a6_94ee_217db357131a["load_query_constructor_chain()"]
  7225abf9_cc63_55f0_0ae9_9fa5685b39ff["base.py"]
  7c645a0f_77f7_93a6_94ee_217db357131a -->|defined in| 7225abf9_cc63_55f0_0ae9_9fa5685b39ff
  445d6da1_3574_d2ff_dd74_d9fd7b77b470["get_query_constructor_prompt()"]
  7c645a0f_77f7_93a6_94ee_217db357131a -->|calls| 445d6da1_3574_d2ff_dd74_d9fd7b77b470
  a1a96dfd_ae4c_e804_cc3c_fa1f0626d568["from_components()"]
  7c645a0f_77f7_93a6_94ee_217db357131a -->|calls| a1a96dfd_ae4c_e804_cc3c_fa1f0626d568
  style 7c645a0f_77f7_93a6_94ee_217db357131a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/query_constructor/base.py lines 273–323

def load_query_constructor_chain(
    llm: BaseLanguageModel,
    document_contents: str,
    attribute_info: Sequence[AttributeInfo | dict],
    examples: list | None = None,
    allowed_comparators: Sequence[Comparator] = tuple(Comparator),
    allowed_operators: Sequence[Operator] = tuple(Operator),
    enable_limit: bool = False,  # noqa: FBT001,FBT002
    schema_prompt: BasePromptTemplate | None = None,
    **kwargs: Any,
) -> LLMChain:
    """Load a query constructor chain.

    Args:
        llm: BaseLanguageModel to use for the chain.
        document_contents: The contents of the document to be queried.
        attribute_info: Sequence of attributes in the document.
        examples: Optional list of examples to use for the chain.
        allowed_comparators: Sequence of allowed comparators. Defaults to all
            `Comparator` objects.
        allowed_operators: Sequence of allowed operators. Defaults to all `Operator`
            objects.
        enable_limit: Whether to enable the limit operator.
        schema_prompt: Prompt for describing query schema. Should have string input
            variables allowed_comparators and allowed_operators.
        **kwargs: Arbitrary named params to pass to LLMChain.

    Returns:
        A LLMChain that can be used to construct queries.
    """
    prompt = get_query_constructor_prompt(
        document_contents,
        attribute_info,
        examples=examples,
        allowed_comparators=allowed_comparators,
        allowed_operators=allowed_operators,
        enable_limit=enable_limit,
        schema_prompt=schema_prompt,
    )
    allowed_attributes = [
        ainfo.name if isinstance(ainfo, AttributeInfo) else ainfo["name"]
        for ainfo in attribute_info
    ]
    output_parser = StructuredQueryOutputParser.from_components(
        allowed_comparators=allowed_comparators,
        allowed_operators=allowed_operators,
        allowed_attributes=allowed_attributes,
    )
    # For backwards compatibility.
    prompt.output_parser = output_parser
    return LLMChain(llm=llm, prompt=prompt, output_parser=output_parser, **kwargs)

Subdomains

Frequently Asked Questions

What does load_query_constructor_chain() do?
load_query_constructor_chain() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/query_constructor/base.py.
Where is load_query_constructor_chain() defined?
load_query_constructor_chain() is defined in libs/langchain/langchain_classic/chains/query_constructor/base.py at line 273.
What does load_query_constructor_chain() call?
load_query_constructor_chain() calls 2 function(s): from_components, get_query_constructor_prompt.

Analyze Your Own Codebase

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

Try Supermodel Free