Home / Function/ load_qa_with_sources_chain() — langchain Function Reference

load_qa_with_sources_chain() — langchain Function Reference

Architecture documentation for the load_qa_with_sources_chain() function in loading.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  0ba4012c_28c8_01cd_504b_0c3333fde496["load_qa_with_sources_chain()"]
  bca47bc4_997d_4fc4_b050_2e6593c54792["loading.py"]
  0ba4012c_28c8_01cd_504b_0c3333fde496 -->|defined in| bca47bc4_997d_4fc4_b050_2e6593c54792
  style 0ba4012c_28c8_01cd_504b_0c3333fde496 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/qa_with_sources/loading.py lines 182–214

def load_qa_with_sources_chain(
    llm: BaseLanguageModel,
    chain_type: str = "stuff",
    verbose: bool | None = None,  # noqa: FBT001
    **kwargs: Any,
) -> BaseCombineDocumentsChain:
    """Load a question answering with sources chain.

    Args:
        llm: Language Model to use in the chain.
        chain_type: Type of document combining chain to use. Should be one of "stuff",
            "map_reduce", "refine" and "map_rerank".
        verbose: Whether chains should be run in verbose mode or not. Note that this
            applies to all chains that make up the final chain.
        **kwargs: Additional keyword arguments.

    Returns:
        A chain to use for question answering with sources.
    """
    loader_mapping: Mapping[str, LoadingCallable] = {
        "stuff": _load_stuff_chain,
        "map_reduce": _load_map_reduce_chain,
        "refine": _load_refine_chain,
        "map_rerank": _load_map_rerank_chain,
    }
    if chain_type not in loader_mapping:
        msg = (
            f"Got unsupported chain type: {chain_type}. "
            f"Should be one of {loader_mapping.keys()}"
        )
        raise ValueError(msg)
    _func: LoadingCallable = loader_mapping[chain_type]
    return _func(llm, verbose=verbose, **kwargs)

Subdomains

Frequently Asked Questions

What does load_qa_with_sources_chain() do?
load_qa_with_sources_chain() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/qa_with_sources/loading.py.
Where is load_qa_with_sources_chain() defined?
load_qa_with_sources_chain() is defined in libs/langchain/langchain_classic/chains/qa_with_sources/loading.py at line 182.

Analyze Your Own Codebase

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

Try Supermodel Free