compressor.py — langchain Source File
Architecture documentation for compressor.py, a python file in the langchain codebase. 7 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 8e4cdb3b_f62f_8d03_f8cd_494435793d84["compressor.py"] cccbe73e_4644_7211_4d55_e8fb133a8014["abc"] 8e4cdb3b_f62f_8d03_f8cd_494435793d84 --> cccbe73e_4644_7211_4d55_e8fb133a8014 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 8e4cdb3b_f62f_8d03_f8cd_494435793d84 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"] 8e4cdb3b_f62f_8d03_f8cd_494435793d84 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c["langchain_core.runnables"] 8e4cdb3b_f62f_8d03_f8cd_494435793d84 --> 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] 8e4cdb3b_f62f_8d03_f8cd_494435793d84 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 f3bc7443_c889_119d_0744_aacc3620d8d2["langchain_core.callbacks"] 8e4cdb3b_f62f_8d03_f8cd_494435793d84 --> f3bc7443_c889_119d_0744_aacc3620d8d2 c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"] 8e4cdb3b_f62f_8d03_f8cd_494435793d84 --> c554676d_b731_47b2_a98f_c1c2d537c0aa style 8e4cdb3b_f62f_8d03_f8cd_494435793d84 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Document compressor."""
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
from pydantic import BaseModel
from langchain_core.runnables import run_in_executor
if TYPE_CHECKING:
from collections.abc import Sequence
from langchain_core.callbacks import Callbacks
from langchain_core.documents import Document
class BaseDocumentCompressor(BaseModel, ABC):
"""Base class for document compressors.
This abstraction is primarily used for post-processing of retrieved documents.
`Document` objects matching a given query are first retrieved.
Then the list of documents can be further processed.
For example, one could re-rank the retrieved documents using an LLM.
!!! note
Users should favor using a `RunnableLambda` instead of sub-classing from this
interface.
"""
@abstractmethod
def compress_documents(
self,
documents: Sequence[Document],
query: str,
callbacks: Callbacks | None = None,
) -> Sequence[Document]:
"""Compress retrieved documents given the query context.
Args:
documents: The retrieved `Document` objects.
query: The query context.
callbacks: Optional `Callbacks` to run during compression.
Returns:
The compressed documents.
"""
async def acompress_documents(
self,
documents: Sequence[Document],
query: str,
callbacks: Callbacks | None = None,
) -> Sequence[Document]:
"""Async compress retrieved documents given the query context.
Args:
documents: The retrieved `Document` objects.
query: The query context.
callbacks: Optional `Callbacks` to run during compression.
Returns:
The compressed documents.
"""
return await run_in_executor(
None, self.compress_documents, documents, query, callbacks
)
Domain
Subdomains
Functions
Classes
Dependencies
- abc
- collections.abc
- langchain_core.callbacks
- langchain_core.documents
- langchain_core.runnables
- pydantic
- typing
Source
Frequently Asked Questions
What does compressor.py do?
compressor.py is a source file in the langchain codebase, written in python. It belongs to the DocumentProcessing domain, DataLoaders subdomain.
What functions are defined in compressor.py?
compressor.py defines 1 function(s): collections.
What does compressor.py depend on?
compressor.py imports 7 module(s): abc, collections.abc, langchain_core.callbacks, langchain_core.documents, langchain_core.runnables, pydantic, typing.
Where is compressor.py in the architecture?
compressor.py is located at libs/core/langchain_core/documents/compressor.py (domain: DocumentProcessing, subdomain: DataLoaders, directory: libs/core/langchain_core/documents).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free