Skip to main content
This example combines three retrieval techniques:
  1. Agentic RAG: Agent decides when to search the knowledge base
  2. Hybrid search: Combines vector similarity with keyword matching
  3. Reranking: Reorders results using a dedicated ranking model

Why Combine These Techniques

The three techniques cover complementary retrieval and ranking stages.

How Reranking Works

After hybrid search returns initial results, the reranker:
  1. Takes the query and candidate documents
  2. Scores each document for relevance using a cross-encoder model
  3. Reorders results so the most relevant appear first
Cohere’s rerank-v3.5 is trained specifically for this task.

Example

agentic_rag.py

Usage

1

Set up your virtual environment

2

Install dependencies

3

Export your API keys

4

Run Agent

Configuration Options

Different Rerankers

Choose one reranker:
For the Infinity option, start the reranker server in a separate terminal:
Use the selected reranker in LanceDB:

Adjusting Results

Next Steps

Hybrid Search

Combine vector and keyword search

Embedders

Choose the right embedding model