Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

JinaRanker

Re-ranks documents by their relevance to a query using Jina AI cross-encoder reranker models.

Key Features

  • Re-ranks documents using Jina AI reranker models.
  • Applies a cross-encoder model that directly compares query-document pairs for higher precision.
  • Configurable top_k to return only the most relevant documents.
  • Filters results by minimum similarity score using score_threshold.
  • Works after any initial retrieval step to improve result quality before generation.

Configuration

Authentication

Create a secret with your Jina API key. Use JINA_API_KEY as the secret key. For instructions, see Create Secrets. Get your API key from Jina AI.

  1. Drag the JinaRanker component onto the canvas from the Component Library.
  2. Click the component to open the configuration panel.
  3. On the General tab:
    1. Enter the name of the Jina reranker model to use, such as jina-reranker-v1-base-en. For available models, see Jina AI.
  4. Go to the Advanced tab to configure the API key and the maximum number of documents to return (top_k).

Connections

JinaRanker accepts a query string, a documents list, and optional top_k and score_threshold values as inputs. It outputs the re-ranked documents list sorted by relevance.

Connect a Retriever to its documents input. Connect its documents output to PromptBuilder to include the ranked results in a generation prompt.

Usage Example

This example shows a RAG pipeline that retrieves documents, re-ranks them using Jina, and generates an answer.

components:
InMemoryBM25Retriever:
type: haystack.components.retrievers.in_memory.bm25_retriever.InMemoryBM25Retriever
init_parameters:
document_store:
type: haystack.document_stores.in_memory.document_store.InMemoryDocumentStore
init_parameters:
bm25_tokenization_regex: (?u)\b\w\w+\b
bm25_algorithm: BM25L
bm25_parameters:
embedding_similarity_function: dot_product
index: 'default'
async_executor:
top_k: 10
JinaRanker:
type: haystack_integrations.components.rankers.jina.ranker.JinaRanker
init_parameters:
api_key:
type: env_var
env_vars:
- JINA_API_KEY
strict: false
model: jina-reranker-v1-base-en
top_k: 3
PromptBuilder:
type: haystack.components.builders.prompt_builder.PromptBuilder
init_parameters:
template: "Given the following documents, answer the question.\n\nDocuments:\n{% for doc in documents %}{{ doc.content }}\n{% endfor %}\n\nQuestion: {{ query }}"
OpenAIGenerator:
type: haystack.components.generators.openai.OpenAIGenerator
init_parameters:
api_key:
type: env_var
env_vars:
- OPENAI_API_KEY
strict: false
model: gpt-4o-mini
AnswerBuilder:
type: haystack.components.builders.answer_builder.AnswerBuilder
init_parameters:
pattern:
reference_pattern:
last_message_only: false
return_only_referenced_documents: true

connections:
- sender: InMemoryBM25Retriever.documents
receiver: JinaRanker.documents
- sender: JinaRanker.documents
receiver: PromptBuilder.documents
- sender: PromptBuilder.prompt
receiver: OpenAIGenerator.prompt
- sender: OpenAIGenerator.replies
receiver: AnswerBuilder.replies
- sender: JinaRanker.documents
receiver: AnswerBuilder.documents

max_runs_per_component: 100

metadata: {}

inputs:
query:
- InMemoryBM25Retriever.query
- JinaRanker.query
- PromptBuilder.query
- AnswerBuilder.query

outputs:
answers: AnswerBuilder.answers

Parameters

Inputs

ParameterTypeDefaultDescription
querystrQuery string.
documentsList[Document]List of Documents.
top_kOptional[int]NoneThe maximum number of Documents you want the Ranker to return.
score_thresholdOptional[float]NoneIf provided only returns documents with a score above this threshold.

Outputs

ParameterTypeDefaultDescription
documentsList[Document]A dictionary with the following keys: - documents: List of Documents most similar to the given query in descending order of similarity.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
api_keySecretSecret.from_env_var('JINA_API_KEY')The Jina API key. It can be explicitly provided or automatically read from the environment variable JINA_API_KEY (recommended).
modelstrjina-reranker-v1-base-enThe name of the Jina model to use. Check the list of available models on https://jina.ai/reranker/
top_kOptional[int]NoneThe maximum number of Documents to return per query. If None, all documents are returned
score_thresholdOptional[float]NoneIf provided only returns documents with a score above this threshold.

Run Method Parameters

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
querystrQuery string.
documentsList[Document]List of Documents.
top_kOptional[int]NoneThe maximum number of Documents you want the Ranker to return.
score_thresholdOptional[float]NoneIf provided only returns documents with a score above this threshold.