redis-vl-dotnet
ONNX Reranker
RedisVL.Rerankers.Onnx provides OnnxTextReranker, an ITextReranker implementation that scores query-plus-document pairs locally with ONNX Runtime.
Package contents
-
OnnxTextRerankerfor local cross-encoder reranking -
OnnxRerankerOptionsfor model asset and runtime configuration -
OnnxRuntimeSessionOptionsfor ONNX Runtime session tuning -
OnnxRerankerPackageas the package marker type
Local model assets
This package does not bundle model files. Applications must provide:
-
a local
model.onnxfile -
a local Hugging Face
tokenizer.jsonfile
The reference workflow assumes a BERT-style cross-encoder tokenizer shape:
-
[CLS] query [SEP] document [SEP] -
input_ids -
attention_mask -
token_type_idswhen the model expects them
Request options
OnnxRerankerOptions currently supports:
-
ModelPathfor the local ONNX model file -
TokenizerPathfor the local tokenizer definition -
MaxSequenceLengthwith a default of512 -
ScoreThresholdwhen the application wants to drop low-scoring matches after inference -
SessionOptionsfor local ONNX Runtime tuning such as graph optimization, execution mode, and thread counts
ScoreThreshold is optional because score calibration can vary across exported cross-encoder models.
Example workflow
/examples/OnnxRerankerExample shows the expected integration pattern:
-
load an initial candidate set
-
print the original candidate order
-
rerank those candidates with
OnnxTextReranker -
print the local ONNX-adjusted order
Run it from the repository root after setting local asset paths:
export ONNX_RERANKER_MODEL_PATH=/path/to/model.onnx
export ONNX_RERANKER_TOKENIZER_PATH=/path/to/tokenizer.json
dotnet run --project examples/OnnxRerankerExample/OnnxRerankerExample.csproj