BaseDocumentCompressor#
- class langchain_core.documents.compressor.BaseDocumentCompressor[source]#
Bases:
BaseModel
,ABC
Base class for document compressors.
This abstraction is primarily used for post-processing of retrieved documents.
Documents 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.
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
- async acompress_documents(documents: Sequence[Document], query: str, callbacks: List[BaseCallbackHandler] | BaseCallbackManager | None = None) Sequence[Document] [source]#
Async compress retrieved documents given the query context.
- Parameters:
documents (Sequence[Document]) – The retrieved documents.
query (str) – The query context.
callbacks (List[BaseCallbackHandler] | BaseCallbackManager | None) – Optional callbacks to run during compression.
- Returns:
The compressed documents.
- Return type:
Sequence[Document]
- abstract compress_documents(documents: Sequence[Document], query: str, callbacks: List[BaseCallbackHandler] | BaseCallbackManager | None = None) Sequence[Document] [source]#
Compress retrieved documents given the query context.
- Parameters:
documents (Sequence[Document]) – The retrieved documents.
query (str) – The query context.
callbacks (List[BaseCallbackHandler] | BaseCallbackManager | None) – Optional callbacks to run during compression.
- Returns:
The compressed documents.
- Return type:
Sequence[Document]