map_reduce.py — langchain Source File
Architecture documentation for map_reduce.py, a python file in the langchain codebase. 11 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 9d0efda3_e899_f701_7ce6_4b9df7abdb19["map_reduce.py"] feec1ec4_6917_867b_d228_b134d0ff8099["typing"] 9d0efda3_e899_f701_7ce6_4b9df7abdb19 --> feec1ec4_6917_867b_d228_b134d0ff8099 2485b66a_3839_d0b6_ad9c_a4ff40457dc6["langchain_core._api"] 9d0efda3_e899_f701_7ce6_4b9df7abdb19 --> 2485b66a_3839_d0b6_ad9c_a4ff40457dc6 17a62cb3_fefd_6320_b757_b53bb4a1c661["langchain_core.callbacks"] 9d0efda3_e899_f701_7ce6_4b9df7abdb19 --> 17a62cb3_fefd_6320_b757_b53bb4a1c661 6a98b0a5_5607_0043_2e22_a46a464c2d62["langchain_core.documents"] 9d0efda3_e899_f701_7ce6_4b9df7abdb19 --> 6a98b0a5_5607_0043_2e22_a46a464c2d62 a8ec7563_2814_99b3_c6da_61c599efc542["langchain_core.runnables.config"] 9d0efda3_e899_f701_7ce6_4b9df7abdb19 --> a8ec7563_2814_99b3_c6da_61c599efc542 314b1cc1_bd2e_bf43_4c2f_8c292c35f3e7["langchain_core.utils.pydantic"] 9d0efda3_e899_f701_7ce6_4b9df7abdb19 --> 314b1cc1_bd2e_bf43_4c2f_8c292c35f3e7 dd5e7909_a646_84f1_497b_cae69735550e["pydantic"] 9d0efda3_e899_f701_7ce6_4b9df7abdb19 --> dd5e7909_a646_84f1_497b_cae69735550e f85fae70_1011_eaec_151c_4083140ae9e5["typing_extensions"] 9d0efda3_e899_f701_7ce6_4b9df7abdb19 --> f85fae70_1011_eaec_151c_4083140ae9e5 f40facfc_f3e4_c00f_e491_0760270cea61["langchain_classic.chains.combine_documents.base"] 9d0efda3_e899_f701_7ce6_4b9df7abdb19 --> f40facfc_f3e4_c00f_e491_0760270cea61 187399e0_04c4_3d9d_e228_9285c47b7972["langchain_classic.chains.combine_documents.reduce"] 9d0efda3_e899_f701_7ce6_4b9df7abdb19 --> 187399e0_04c4_3d9d_e228_9285c47b7972 4044d59c_c0a5_a371_f49b_bea3da4e20ac["langchain_classic.chains.llm"] 9d0efda3_e899_f701_7ce6_4b9df7abdb19 --> 4044d59c_c0a5_a371_f49b_bea3da4e20ac style 9d0efda3_e899_f701_7ce6_4b9df7abdb19 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Combining documents by mapping a chain over them first, then combining results."""
from __future__ import annotations
from typing import Any
from langchain_core._api import deprecated
from langchain_core.callbacks import Callbacks
from langchain_core.documents import Document
from langchain_core.runnables.config import RunnableConfig
from langchain_core.utils.pydantic import create_model
from pydantic import BaseModel, ConfigDict, model_validator
from typing_extensions import override
from langchain_classic.chains.combine_documents.base import BaseCombineDocumentsChain
from langchain_classic.chains.combine_documents.reduce import ReduceDocumentsChain
from langchain_classic.chains.llm import LLMChain
@deprecated(
since="0.3.1",
removal="1.0",
message=(
"This class is deprecated. Please see the migration guide here for "
"a recommended replacement: "
"https://python.langchain.com/docs/versions/migrating_chains/map_reduce_chain/"
),
)
class MapReduceDocumentsChain(BaseCombineDocumentsChain):
"""Combining documents by mapping a chain over them, then combining results.
We first call `llm_chain` on each document individually, passing in the
`page_content` and any other kwargs. This is the `map` step.
We then process the results of that `map` step in a `reduce` step. This should
likely be a ReduceDocumentsChain.
Example:
```python
from langchain_classic.chains import (
StuffDocumentsChain,
LLMChain,
ReduceDocumentsChain,
MapReduceDocumentsChain,
)
from langchain_core.prompts import PromptTemplate
from langchain_openai import OpenAI
# This controls how each document will be formatted. Specifically,
# it will be passed to `format_document` - see that function for more
# details.
document_prompt = PromptTemplate(
input_variables=["page_content"], template="{page_content}"
)
document_variable_name = "context"
model = OpenAI()
# The prompt here should take as an input variable the
# `document_variable_name`
prompt = PromptTemplate.from_template("Summarize this content: {context}")
llm_chain = LLMChain(llm=model, prompt=prompt)
// ... (235 more lines)
Domain
Subdomains
Classes
Dependencies
- langchain_classic.chains.combine_documents.base
- langchain_classic.chains.combine_documents.reduce
- langchain_classic.chains.llm
- langchain_core._api
- langchain_core.callbacks
- langchain_core.documents
- langchain_core.runnables.config
- langchain_core.utils.pydantic
- pydantic
- typing
- typing_extensions
Source
Frequently Asked Questions
What does map_reduce.py do?
map_reduce.py is a source file in the langchain codebase, written in python. It belongs to the AgentOrchestration domain, ClassicChains subdomain.
What does map_reduce.py depend on?
map_reduce.py imports 11 module(s): langchain_classic.chains.combine_documents.base, langchain_classic.chains.combine_documents.reduce, langchain_classic.chains.llm, langchain_core._api, langchain_core.callbacks, langchain_core.documents, langchain_core.runnables.config, langchain_core.utils.pydantic, and 3 more.
Where is map_reduce.py in the architecture?
map_reduce.py is located at libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py (domain: AgentOrchestration, subdomain: ClassicChains, directory: libs/langchain/langchain_classic/chains/combine_documents).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free