refine.py — langchain Source File
Architecture documentation for refine.py, a python file in the langchain codebase. 9 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR ba65fd50_e068_edf8_f90d_8d6d79a29942["refine.py"] 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] ba65fd50_e068_edf8_f90d_8d6d79a29942 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 b19a8b7e_fbee_95b1_65b8_509a1ed3cad7["langchain_core._api"] ba65fd50_e068_edf8_f90d_8d6d79a29942 --> b19a8b7e_fbee_95b1_65b8_509a1ed3cad7 f3bc7443_c889_119d_0744_aacc3620d8d2["langchain_core.callbacks"] ba65fd50_e068_edf8_f90d_8d6d79a29942 --> f3bc7443_c889_119d_0744_aacc3620d8d2 c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"] ba65fd50_e068_edf8_f90d_8d6d79a29942 --> c554676d_b731_47b2_a98f_c1c2d537c0aa e6b4f61e_7b98_6666_3641_26b069517d4a["langchain_core.prompts"] ba65fd50_e068_edf8_f90d_8d6d79a29942 --> e6b4f61e_7b98_6666_3641_26b069517d4a c17bcf07_a2ef_b992_448f_5088d46a1e79["langchain_core.prompts.prompt"] ba65fd50_e068_edf8_f90d_8d6d79a29942 --> c17bcf07_a2ef_b992_448f_5088d46a1e79 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"] ba65fd50_e068_edf8_f90d_8d6d79a29942 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7 a0d4f6c3_2d96_364c_720a_e778ffd171a0["langchain_classic.chains.combine_documents.base"] ba65fd50_e068_edf8_f90d_8d6d79a29942 --> a0d4f6c3_2d96_364c_720a_e778ffd171a0 31974615_0d58_bd26_13f1_776e0a9d1413["langchain_classic.chains.llm"] ba65fd50_e068_edf8_f90d_8d6d79a29942 --> 31974615_0d58_bd26_13f1_776e0a9d1413 style ba65fd50_e068_edf8_f90d_8d6d79a29942 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Combine documents by doing a first pass and then refining on more documents."""
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.prompts import BasePromptTemplate, format_document
from langchain_core.prompts.prompt import PromptTemplate
from pydantic import ConfigDict, Field, model_validator
from langchain_classic.chains.combine_documents.base import (
BaseCombineDocumentsChain,
)
from langchain_classic.chains.llm import LLMChain
def _get_default_document_prompt() -> PromptTemplate:
return PromptTemplate(input_variables=["page_content"], template="{page_content}")
@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/refine_docs_chain/"
),
)
class RefineDocumentsChain(BaseCombineDocumentsChain):
"""Combine documents by doing a first pass and then refining on more documents.
This algorithm first calls `initial_llm_chain` on the first document, passing
that first document in with the variable name `document_variable_name`, and
produces a new variable with the variable name `initial_response_name`.
Then, it loops over every remaining document. This is called the "refine" step.
It calls `refine_llm_chain`,
passing in that document with the variable name `document_variable_name`
as well as the previous response with the variable name `initial_response_name`.
Example:
```python
from langchain_classic.chains import RefineDocumentsChain, LLMChain
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`
// ... (170 more lines)
Domain
Subdomains
Functions
Classes
Dependencies
- langchain_classic.chains.combine_documents.base
- langchain_classic.chains.llm
- langchain_core._api
- langchain_core.callbacks
- langchain_core.documents
- langchain_core.prompts
- langchain_core.prompts.prompt
- pydantic
- typing
Source
Frequently Asked Questions
What does refine.py do?
refine.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in refine.py?
refine.py defines 1 function(s): _get_default_document_prompt.
What does refine.py depend on?
refine.py imports 9 module(s): langchain_classic.chains.combine_documents.base, langchain_classic.chains.llm, langchain_core._api, langchain_core.callbacks, langchain_core.documents, langchain_core.prompts, langchain_core.prompts.prompt, pydantic, and 1 more.
Where is refine.py in the architecture?
refine.py is located at libs/langchain/langchain_classic/chains/combine_documents/refine.py (domain: CoreAbstractions, subdomain: RunnableInterface, 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