Introduction

This guide extends the R2R local RAG cookbook by demonstrating how to run R2R with reranking. Search with reranking enhances traditional search by applying additional downstream ranking powered by language models. This technique refines the results, leading to more accurate and contextually relevant outcomes.

Currently, reranking is only supported when running with local embedding models. Start with the local RAG cookbook if you haven’t already!

To get started, we will need to add a dependency for running embedding models on our local machine. This dependency, sentence-transformers can installed by R2R with the adjusted command below:

pip install 'r2r[local-embedding]'
local-embedding includes a large dependency that is currently NOT included in the default R2R Docker image, so reranking is not yet compatible with Docker.

Configuration

To run R2R with local embedding and reranking, override the default config.json with the following settings:

To populate the database with sample files:

python -m r2r.examples.quickstart ingest_files --config_name=local_ollama --no-media

Run a basic search:

python -m r2r.examples.quickstart search --query="Who was Aristotle?" --config_name=local_ollama

To execute a reranked search:

python -m r2r.examples.quickstart search --query="Who was Aristotle?" --config_name=local_ollama_rerank

Summary

The reranked search in R2R significantly improves the quality and relevance of search results by adding an additional reranking step powered by language models. This process:

  1. Uses traditional and semantic search methods to retrieve initial results
  2. Refines these results using a reranking model
  3. Evaluates the context and relevance of each result
  4. Prioritizes the most pertinent documents

This approach leverages both the empirical strengths of traditional keyword searches and the nuanced understanding provided by modern semantic models, resulting in a highly accurate and contextually relevant search experience.

For detailed setup and basic functionality, refer back to the R2R Quickstart. For more advanced usage and customization options, join the R2R Discord community.