Skip to main content

Text Ranking (Reranking)

1. What is Text Ranking Task?

Text Ranking (commonly referred to as Reranking) is a critical task in natural language processing and information retrieval, especially in Retrieval-Augmented Generation (RAG) systems. A reranking model (Reranker) typically acts as the second stage in a multi-stage retrieval pipeline. It performs deeper semantic matching and precise scoring between the query and candidate documents retrieved in the initial search phase, then re-orders them. This significantly improves retrieval accuracy and the quality of final generated content.

2. Typical Use Cases

  • Retrieval-Augmented Generation (RAG): Re-ranks retrieved knowledge base chunks before passing them to the LLM. It selects the top-K most relevant chunks to filter out noise and improve generation accuracy.
  • Search Engines & Information Retrieval: Combines keyword search (e.g., BM25) and vector-based semantic search, utilizing the reranker to refine search relevance.
  • Question Answering (QA): Ranks candidate answers based on semantic relevance to locate the best response.

3. Key Factors Affecting Reranking Quality

Model Selection

Reranking models typically employ a Cross-Encoder architecture, which performs joint attention over the query and document simultaneously. This yields much higher precision than Bi-Encoder models (used for vector embedding). Common rerankers include BGE-Reranker, Qwen-Reranker, and Jina-Reranker.

4. Sample Code

Here is an example of invoking the Text Ranking API using Python:

import requests
import json

url = "https://xxxxxxxxxxxx.space.opencsg.com/v1/rerank" # Replace with your Endpoint URL
headers = {
'Content-Type': 'application/json'
}
data = {
"query": "What is deep learning?",
"texts": [
"Deep learning is a subset of machine learning based on artificial neural networks.",
"The weather is nice today, perfect for a walk."
],
"top_n": 2
}

response = requests.post(url=url, json=data, headers=headers)
response.raise_for_status()
print(json.dumps(response.json(), indent=2))