Home / Function/ from_llm() — langchain Function Reference

from_llm() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  9e496278_57fb_59d0_5515_73d4b88ce4cd["from_llm()"]
  714ad545_01d2_22ce_704e_4b6490f7b443["SelfQueryRetriever"]
  9e496278_57fb_59d0_5515_73d4b88ce4cd -->|defined in| 714ad545_01d2_22ce_704e_4b6490f7b443
  37be2200_dcdd_071b_8e29_a55020a76e50["_get_builtin_translator()"]
  9e496278_57fb_59d0_5515_73d4b88ce4cd -->|calls| 37be2200_dcdd_071b_8e29_a55020a76e50
  style 9e496278_57fb_59d0_5515_73d4b88ce4cd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/retrievers/self_query/base.py lines 342–407

    def from_llm(
        cls,
        llm: BaseLanguageModel,
        vectorstore: VectorStore,
        document_contents: str,
        metadata_field_info: Sequence[AttributeInfo | dict],
        structured_query_translator: Visitor | None = None,
        chain_kwargs: dict | None = None,
        enable_limit: bool = False,  # noqa: FBT001,FBT002
        use_original_query: bool = False,  # noqa: FBT001,FBT002
        **kwargs: Any,
    ) -> "SelfQueryRetriever":
        """Create a SelfQueryRetriever from an LLM and a vector store.

        Args:
            llm: The language model to use for generating queries.
            vectorstore: The vector store to use for retrieving documents.
            document_contents: Description of the page contents of the document to be
                queried.
            metadata_field_info: Metadata field information for the documents.
            structured_query_translator: Optional translator for turning internal query
                language into `VectorStore` search params.
            chain_kwargs: Additional keyword arguments for the query constructor.
            enable_limit: Whether to enable the limit operator.
            use_original_query: Whether to use the original query instead of the revised
                query from the LLM.
            **kwargs: Additional keyword arguments for the SelfQueryRetriever.

        Returns:
            An instance of SelfQueryRetriever.
        """
        if structured_query_translator is None:
            structured_query_translator = _get_builtin_translator(vectorstore)
        chain_kwargs = chain_kwargs or {}

        if (
            "allowed_comparators" not in chain_kwargs
            and structured_query_translator.allowed_comparators is not None
        ):
            chain_kwargs["allowed_comparators"] = (
                structured_query_translator.allowed_comparators
            )
        if (
            "allowed_operators" not in chain_kwargs
            and structured_query_translator.allowed_operators is not None
        ):
            chain_kwargs["allowed_operators"] = (
                structured_query_translator.allowed_operators
            )
        query_constructor = load_query_constructor_runnable(
            llm,
            document_contents,
            metadata_field_info,
            enable_limit=enable_limit,
            **chain_kwargs,
        )
        query_constructor = query_constructor.with_config(
            run_name=QUERY_CONSTRUCTOR_RUN_NAME,
        )
        return cls(
            query_constructor=query_constructor,
            vectorstore=vectorstore,
            use_original_query=use_original_query,
            structured_query_translator=structured_query_translator,
            **kwargs,
        )

Domain

Subdomains

Frequently Asked Questions

What does from_llm() do?
from_llm() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/retrievers/self_query/base.py.
Where is from_llm() defined?
from_llm() is defined in libs/langchain/langchain_classic/retrievers/self_query/base.py at line 342.
What does from_llm() call?
from_llm() calls 1 function(s): _get_builtin_translator.

Analyze Your Own Codebase

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

Try Supermodel Free