query_with_sources() — langchain Function Reference
Architecture documentation for the query_with_sources() function in vectorstore.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 29c14884_a8d3_a301_4a65_c48a2f3b2878["query_with_sources()"] 25510f58_8b5d_fdd1_6cd7_3afc1a3d7a49["VectorStoreIndexWrapper"] 29c14884_a8d3_a301_4a65_c48a2f3b2878 -->|defined in| 25510f58_8b5d_fdd1_6cd7_3afc1a3d7a49 style 29c14884_a8d3_a301_4a65_c48a2f3b2878 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/indexes/vectorstore.py lines 104–137
def query_with_sources(
self,
question: str,
llm: BaseLanguageModel | None = None,
retriever_kwargs: dict[str, Any] | None = None,
**kwargs: Any,
) -> dict:
"""Query the `VectorStore` and retrieve the answer along with 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 chain.invoke({chain.question_key: question})
Domain
Subdomains
Source
Frequently Asked Questions
What does query_with_sources() do?
query_with_sources() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/indexes/vectorstore.py.
Where is query_with_sources() defined?
query_with_sources() is defined in libs/langchain/langchain_classic/indexes/vectorstore.py at line 104.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free