Skip to main content

NvidiaRanker

A component for ranking documents using ranking models provided by

Basic Information

  • Type: haystack_integrations.nvidia.src.haystack_integrations.components.rankers.nvidia.ranker.NvidiaRanker

Inputs

ParameterTypeDefaultDescription
querystrThe query to rank the documents against.
documentsList[Document]The list of documents to rank.
top_kOptional[int]NoneThe number of documents to return.

Outputs

ParameterTypeDefaultDescription
documentsList[Document]A dictionary containing the ranked documents.

Overview

Work in Progress

Bear with us while we're working on adding pipeline examples and most common components connections.

A component for ranking documents using ranking models provided by NVIDIA NIMs.

Usage example:

from haystack_integrations.components.rankers.nvidia import NvidiaRanker
from haystack import Document
from haystack.utils import Secret

ranker = NvidiaRanker(
model="nvidia/nv-rerankqa-mistral-4b-v3",
api_key=Secret.from_env_var("NVIDIA_API_KEY"),
)
ranker.warm_up()

query = "What is the capital of Germany?"
documents = [
Document(content="Berlin is the capital of Germany."),
Document(content="The capital of Germany is Berlin."),
Document(content="Germany's capital is Berlin."),
]

result = ranker.run(query, documents, top_k=2)
print(result["documents"])

Usage Example

components:
NvidiaRanker:
type: nvidia.src.haystack_integrations.components.rankers.nvidia.ranker.NvidiaRanker
init_parameters:

Parameters

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
modelOptional[str]NoneRanking model to use.
truncateOptional[Union[RankerTruncateMode, str]]NoneTruncation strategy to use. Can be "NONE", "END", or RankerTruncateMode. Defaults to NIM's default.
api_keyOptional[Secret]Secret.from_env_var('NVIDIA_API_KEY')API key for the NVIDIA NIM.
api_urlstros.getenv('NVIDIA_API_URL', DEFAULT_API_URL)Custom API URL for the NVIDIA NIM.
top_kint5Number of documents to return.
query_prefixstrA string to add at the beginning of the query text before ranking. Use it to prepend the text with an instruction, as required by reranking models like bge.
document_prefixstrA string to add at the beginning of each document before ranking. You can use it to prepend the document with an instruction, as required by embedding models like bge.
meta_fields_to_embedOptional[List[str]]NoneList of metadata fields to embed with the document.
embedding_separatorstr\nSeparator to concatenate metadata fields to the document.
timeoutOptional[float]NoneTimeout for request calls, if not set it is inferred from the NVIDIA_TIMEOUT environment variable or set to 60 by default.

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
querystrThe query to rank the documents against.
documentsList[Document]The list of documents to rank.
top_kOptional[int]NoneThe number of documents to return.