CrossEncoderReranker#
- class langchain.retrievers.document_compressors.cross_encoder_rerank.CrossEncoderReranker[source]#
Bases:
BaseDocumentCompressor
Document compressor that uses CrossEncoder for reranking.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- param model: BaseCrossEncoder [Required]#
CrossEncoder model to use for scoring similarity between the query and documents.
- param top_n: int = 3#
Number of documents to return.
- async acompress_documents(documents: Sequence[Document], query: str, callbacks: list[BaseCallbackHandler] | BaseCallbackManager | None = None) Sequence[Document] #
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]
- compress_documents(documents: Sequence[Document], query: str, callbacks: list[BaseCallbackHandler] | BaseCallbackManager | None = None) Sequence[Document] [source]#
Rerank documents using CrossEncoder.
- Parameters:
documents (Sequence[Document]) – A sequence of documents to compress.
query (str) – The query to use for compressing the documents.
callbacks (list[BaseCallbackHandler] | BaseCallbackManager | None) – Callbacks to run during the compression process.
- Returns:
A sequence of compressed documents.
- Return type:
Sequence[Document]
Examples using CrossEncoderReranker