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 if the input data cannot be parsed to form a valid model.

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:
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