Rerank
Adapted from the Griptape AI Framework documentation.
Overview
Rerank Drivers can be used to rerank search results for a particular query. Every Rerank Driver implements the following methods that can be used directly:
run(query: str, artifacts: list[TextArtifact])
reranks a list of TextArtifact based on the original query.
Rerank Drivers can also be used with a RagEngine's Rerank Module.
Rerank Drivers
Local
The LocalRerankDriver uses a simple relatedness calculation.
from griptape.artifacts import TextArtifact from griptape.drivers.rerank.local import LocalRerankDriver rerank_driver = LocalRerankDriver() artifacts = rerank_driver.run( "What is the capital of France?", [ TextArtifact("Hotdog"), TextArtifact("San Francisco"), TextArtifact("Paris"), TextArtifact("Baguette"), TextArtifact("French Hotdog"), ], ) for artifact in artifacts: print(artifact.value)
Paris San Francisco Baguette French Hotdog Hotdog
Cohere
The CohereRerankDriver uses Cohere's Rerank model.
import os from griptape.artifacts import TextArtifact from griptape.drivers.rerank.cohere import CohereRerankDriver rerank_driver = CohereRerankDriver( api_key=os.environ["COHERE_API_KEY"], ) artifacts = rerank_driver.run( "Where is NYC located?", [ TextArtifact("NYC Media"), TextArtifact("New York City Police Department"), TextArtifact("New York City"), TextArtifact("New York City Subway"), ], ) for artifact in artifacts: print(artifact.value)
New York City NYC Media New York City Police Department New York City Subway
Nvidia NIM
The NvidiaNimRerankDriver uses the Nvidia NIM Reranking API.
from griptape.artifacts import TextArtifact from griptape.drivers.rerank.nvidia_nim import NvidiaNimRerankDriver rerank_driver = NvidiaNimRerankDriver( model="nvidia/bert-base-uncased", base_url="http://localhost:8000", ) artifacts = rerank_driver.run( "Where is NYC located?", [ TextArtifact("NYC Media"), TextArtifact("New York City Police Department"), TextArtifact("New York City"), TextArtifact("New York City Subway"), ], ) for artifact in artifacts: print(artifact.value)
- On this page
- Overview
- Rerank Drivers
Could this page be better? Report a problem or suggest an addition!