multi_query.py — langchain Source File
Architecture documentation for multi_query.py, a python file in the langchain codebase. 13 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR c54859a9_d46f_e8aa_2ff3_33f3cd5a6746["multi_query.py"] a327e534_84f6_5308_58ca_5727d5eda0cf["asyncio"] c54859a9_d46f_e8aa_2ff3_33f3cd5a6746 --> a327e534_84f6_5308_58ca_5727d5eda0cf 2a7f66a7_8738_3d47_375b_70fcaa6ac169["logging"] c54859a9_d46f_e8aa_2ff3_33f3cd5a6746 --> 2a7f66a7_8738_3d47_375b_70fcaa6ac169 cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] c54859a9_d46f_e8aa_2ff3_33f3cd5a6746 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 f3bc7443_c889_119d_0744_aacc3620d8d2["langchain_core.callbacks"] c54859a9_d46f_e8aa_2ff3_33f3cd5a6746 --> f3bc7443_c889_119d_0744_aacc3620d8d2 c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"] c54859a9_d46f_e8aa_2ff3_33f3cd5a6746 --> c554676d_b731_47b2_a98f_c1c2d537c0aa ba43b74d_3099_7e1c_aac3_cf594720469e["langchain_core.language_models"] c54859a9_d46f_e8aa_2ff3_33f3cd5a6746 --> ba43b74d_3099_7e1c_aac3_cf594720469e 83d7c7fd_1989_762c_9cf3_cecb50ada22b["langchain_core.output_parsers"] c54859a9_d46f_e8aa_2ff3_33f3cd5a6746 --> 83d7c7fd_1989_762c_9cf3_cecb50ada22b e6b4f61e_7b98_6666_3641_26b069517d4a["langchain_core.prompts"] c54859a9_d46f_e8aa_2ff3_33f3cd5a6746 --> e6b4f61e_7b98_6666_3641_26b069517d4a c17bcf07_a2ef_b992_448f_5088d46a1e79["langchain_core.prompts.prompt"] c54859a9_d46f_e8aa_2ff3_33f3cd5a6746 --> c17bcf07_a2ef_b992_448f_5088d46a1e79 38bc5323_3713_7377_32f8_091293bea54b["langchain_core.retrievers"] c54859a9_d46f_e8aa_2ff3_33f3cd5a6746 --> 38bc5323_3713_7377_32f8_091293bea54b 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c["langchain_core.runnables"] c54859a9_d46f_e8aa_2ff3_33f3cd5a6746 --> 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c 91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"] c54859a9_d46f_e8aa_2ff3_33f3cd5a6746 --> 91721f45_4909_e489_8c1f_084f8bd87145 31974615_0d58_bd26_13f1_776e0a9d1413["langchain_classic.chains.llm"] c54859a9_d46f_e8aa_2ff3_33f3cd5a6746 --> 31974615_0d58_bd26_13f1_776e0a9d1413 style c54859a9_d46f_e8aa_2ff3_33f3cd5a6746 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import asyncio
import logging
from collections.abc import Sequence
from langchain_core.callbacks import (
AsyncCallbackManagerForRetrieverRun,
CallbackManagerForRetrieverRun,
)
from langchain_core.documents import Document
from langchain_core.language_models import BaseLanguageModel
from langchain_core.output_parsers import BaseOutputParser
from langchain_core.prompts import BasePromptTemplate
from langchain_core.prompts.prompt import PromptTemplate
from langchain_core.retrievers import BaseRetriever
from langchain_core.runnables import Runnable
from typing_extensions import override
from langchain_classic.chains.llm import LLMChain
logger = logging.getLogger(__name__)
class LineListOutputParser(BaseOutputParser[list[str]]):
"""Output parser for a list of lines."""
@override
def parse(self, text: str) -> list[str]:
lines = text.strip().split("\n")
return list(filter(None, lines)) # Remove empty lines
# Default prompt
DEFAULT_QUERY_PROMPT = PromptTemplate(
input_variables=["question"],
template="""You are an AI language model assistant. Your task is
to generate 3 different versions of the given user
question to retrieve relevant documents from a vector database.
By generating multiple perspectives on the user question,
your goal is to help the user overcome some of the limitations
of distance-based similarity search. Provide these alternative
questions separated by newlines. Original question: {question}""",
)
def _unique_documents(documents: Sequence[Document]) -> list[Document]:
return [doc for i, doc in enumerate(documents) if doc not in documents[:i]]
class MultiQueryRetriever(BaseRetriever):
"""Given a query, use an LLM to write a set of queries.
Retrieve docs for each query. Return the unique union of all retrieved docs.
"""
retriever: BaseRetriever
llm_chain: Runnable
verbose: bool = True
parser_key: str = "lines"
"""DEPRECATED. parser_key is no longer used and should not be specified."""
include_original: bool = False
// ... (181 more lines)
Domain
Subdomains
Functions
Dependencies
- asyncio
- collections.abc
- langchain_classic.chains.llm
- langchain_core.callbacks
- langchain_core.documents
- langchain_core.language_models
- langchain_core.output_parsers
- langchain_core.prompts
- langchain_core.prompts.prompt
- langchain_core.retrievers
- langchain_core.runnables
- logging
- typing_extensions
Source
Frequently Asked Questions
What does multi_query.py do?
multi_query.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in multi_query.py?
multi_query.py defines 1 function(s): _unique_documents.
What does multi_query.py depend on?
multi_query.py imports 13 module(s): asyncio, collections.abc, langchain_classic.chains.llm, langchain_core.callbacks, langchain_core.documents, langchain_core.language_models, langchain_core.output_parsers, langchain_core.prompts, and 5 more.
Where is multi_query.py in the architecture?
multi_query.py is located at libs/langchain/langchain_classic/retrievers/multi_query.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/langchain/langchain_classic/retrievers).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free