Home / Function/ aquery_with_sources() — langchain Function Reference

aquery_with_sources() — langchain Function Reference

Architecture documentation for the aquery_with_sources() function in vectorstore.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  cfdcfa60_c372_85e1_e1b0_be142c0be2c0["aquery_with_sources()"]
  25510f58_8b5d_fdd1_6cd7_3afc1a3d7a49["VectorStoreIndexWrapper"]
  cfdcfa60_c372_85e1_e1b0_be142c0be2c0 -->|defined in| 25510f58_8b5d_fdd1_6cd7_3afc1a3d7a49
  style cfdcfa60_c372_85e1_e1b0_be142c0be2c0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/indexes/vectorstore.py lines 139–172

    async def aquery_with_sources(
        self,
        question: str,
        llm: BaseLanguageModel | None = None,
        retriever_kwargs: dict[str, Any] | None = None,
        **kwargs: Any,
    ) -> dict:
        """Asynchronously query the `VectorStore` and retrieve the answer and sources.

        Args:
            question: The question or prompt to query.
            llm: The language model to use. Must not be `None`.
            retriever_kwargs: Optional keyword arguments for the retriever.
            **kwargs: Additional keyword arguments forwarded to the chain.

        Returns:
            `dict` containing the answer and source documents.
        """
        if llm is None:
            msg = (
                "This API has been changed to require an LLM. "
                "Please provide an llm to use for querying the vectorstore.\n"
                "For example,\n"
                "from langchain_openai import OpenAI\n"
                "model = OpenAI(temperature=0)"
            )
            raise NotImplementedError(msg)
        retriever_kwargs = retriever_kwargs or {}
        chain = RetrievalQAWithSourcesChain.from_chain_type(
            llm,
            retriever=self.vectorstore.as_retriever(**retriever_kwargs),
            **kwargs,
        )
        return await chain.ainvoke({chain.question_key: question})

Domain

Subdomains

Frequently Asked Questions

What does aquery_with_sources() do?
aquery_with_sources() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/indexes/vectorstore.py.
Where is aquery_with_sources() defined?
aquery_with_sources() is defined in libs/langchain/langchain_classic/indexes/vectorstore.py at line 139.

Analyze Your Own Codebase

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

Try Supermodel Free