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
| Parameter | Type | Default | Description |
|---|---|---|---|
| query | str | The query to rank the documents against. | |
| documents | List[Document] | The list of documents to rank. | |
| top_k | Optional[int] | None | The number of documents to return. |
Outputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| documents | List[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:
| Parameter | Type | Default | Description |
|---|---|---|---|
| model | Optional[str] | None | Ranking model to use. |
| truncate | Optional[Union[RankerTruncateMode, str]] | None | Truncation strategy to use. Can be "NONE", "END", or RankerTruncateMode. Defaults to NIM's default. |
| api_key | Optional[Secret] | Secret.from_env_var('NVIDIA_API_KEY') | API key for the NVIDIA NIM. |
| api_url | str | os.getenv('NVIDIA_API_URL', DEFAULT_API_URL) | Custom API URL for the NVIDIA NIM. |
| top_k | int | 5 | Number of documents to return. |
| query_prefix | str | A 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_prefix | str | A 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_embed | Optional[List[str]] | None | List of metadata fields to embed with the document. |
| embedding_separator | str | \n | Separator to concatenate metadata fields to the document. |
| timeout | Optional[float] | None | Timeout 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
| query | str | The query to rank the documents against. | |
| documents | List[Document] | The list of documents to rank. | |
| top_k | Optional[int] | None | The number of documents to return. |
Was this page helpful?