01. Cross Encoder Reranker

Cross encoder reranker is a technique used to improve the performance of search enhancement generation (RAG) systems. This document describes how to implement reranker in retriever using the crossing encoder model of the Hugging Face.

Key features and how it works

purpose

  • Re-rank the searched documents to top the documents most relevant to the question

structure

  • Receive and process questions and documents simultaneously

How it works

  • Directly output similarities using questions and documents as one input

  • Simultaneously analyze questions and documents through the Self-attention mechanism

Advantages

  • More accurate similarities can be measured

  • Explore semantic similarities between questions and documents

Limit point

  • High operating costs and long time

  • Difficulty applying directly to large sets of documents

Actual use

  • In general, reranking only for the top k documents in the initial search

  • After quickly extracting candidates with Bi-encoder, use them in a way that increases accuracy with Cross encoder

implementation

  • Using a cross encoder model from Hugging Face or a model like BAAI/bge-reranker

  • Easily integrated through CrossEncoderReranker components in frames such as LangChain

The main advantages of Reranker

  1. Measure more accurate similarities

  2. Exploring in-depth semantic similarities

  3. Search results improvement

  4. RAG system performance improvement

  5. Flexible integration

  6. Various pre-learning models available

Set the number of documents when using Reranker

  • Generally running for the top 5~10 documents

  • The optimal number of documents needs to be determined through experimentation and evaluation

Trade-offs when using Reranker

  1. Accuracy vs processing time

  2. Performance improvement vs calculation cost

  3. Search speed vs relevance accuracy

  4. Meet system requirements

  5. Data set characteristics consideration A simple example will explain how to implement Cross Encoder Reranker.

Copy

Copy

Copy

Now the basics retriever for ContextualCompressionRetriever I'll wrap it up with. CrossEncoderReranker has HuggingFaceCrossEncoder Use to rearrange the returned results. -Multilingual support BGE Reranker: bge-reranker-v2-m3

Copy

Copy

Copy

Copy

Last updated