How to Run bge-reranker-base Locally in 2026: Transformers, ONNX Runtime and Optimum

Guides Last updated  9 min read By Q4KM

Quick Answer

To run BAAI/bge-reranker-base from BAAI locally as of November 2026, use Hugging Face’s Transformers as the top pick, with an estimated hardware budget of a CPU and RAM exceeding the model’s 1.1 GB F32 weight size to accommodate runtime overhead [1][3]. The ranking is Transformers (Hugging Face), ONNX Runtime (Microsoft), and Optimum (Hugging Face) [3][4][5].

Key Takeaways

How do the local runtimes for bge-reranker-base compare?

Runtime Maker License GitHub stars (date) Latest release (date) Best for
Transformers [3] Hugging Face [3] Apache-2.0 [3] 169,019 (2026-11-16) [3] v5.23.0 (2026-11-13) [3] —
ONNX Runtime [4] Microsoft [4] MIT [4] 22,325 (2026-11-16) [4] v1.32.0 (2026-11-13) [4] —
Optimum [5] Hugging Face [5] Apache-2.0 [5] 3,522 (2026-11-16) [5] v2.3.0 (2026-08-04) [5] —

How do you run bge-reranker-base locally step by step?

1. Transformers

Transformers from Hugging Face can run BAAI/bge-reranker-base using the Python workflow below. The example loads the tokenizer and sequence classification model, then scores candidate passages paired with the same query.

Create and activate a Python environment for your system before running the block. The installation includes PyTorch because the script uses it directly, alongside Transformers v5.23.0 [3]. Run the installation and script from the same environment so the Python interpreter can find both packages.

python -m pip install torch "transformers==5.23.0"  # [3]

python - <<'PY'
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer

model_id = "BAAI/bge-reranker-base"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id)
model.eval()

pairs = [
    ["How can I run AI locally?", "Run a model on your own computer."],
    ["How can I run AI locally?", "A guide to planting tomatoes."],
]
inputs = tokenizer(
    pairs,
    padding=True,
    truncation=True,
    max_length=514,  # Context length: [1]
    return_tensors="pt",
)

with torch.no_grad():
    scores = model(**inputs).logits.flatten().tolist()

for pair, score in zip(pairs, scores):
    print(f"{score}: {pair[-1]}")
PY

Successful execution prints a score beside each candidate passage and returns to the shell without an exception. The output contains scores rather than a generated answer. Keep each score attached to its passage when incorporating the example into a retrieval pipeline. Replace the sample query and passages with your own inputs to check the complete scoring path.

The published F32 weight size is 1.1 GB [1]. Runtime RAM consumption is not established by that file size, so measure memory use with your intended inputs.

A practical gotcha is truncation: the model’s context length is 514 tokens [1], and the example enables input truncation. Long query–passage pairs may lose text before scoring. Check what survives tokenization when evaluating long passages.

2. ONNX Runtime

ONNX Runtime from Microsoft runs BAAI/bge-reranker-base through the ONNX integration in Hugging Face Optimum.[4][5] Use Hugging Face Transformers for tokenization.[3] The installation below includes torch for export and optimum-onnx for the exporter and runtime wrapper; installing onnxruntime alone does not provide those Optimum components.[5]

Run the following in your Python environment. The script exports the model, tokenizes query–passage pairs, and prints their scores through the ONNX wrapper.[5]

python -m pip install torch transformers optimum "optimum-onnx[onnxruntime]"

python - <<'PY'
from transformers import AutoTokenizer
from optimum.onnxruntime import ORTModelForSequenceClassification

tokenizer = AutoTokenizer.from_pretrained("BAAI/bge-reranker-base")
model = ORTModelForSequenceClassification.from_pretrained(
    "BAAI/bge-reranker-base",
    export=True,
)

pairs = [
    ("How do I run a model locally?", "Load the model on your own computer."),
    ("How do I run a model locally?", "Bread dough needs time to rise."),
]
inputs = tokenizer(
    pairs,
    padding=True,
    truncation=True,
    max_length=514,  # [1]
    return_tensors="pt",
)
scores = model(**inputs).logits.flatten().tolist()
for pair, score in zip(pairs, scores):
    print({"passage": pair[-1], "score": score})
PY

A successful first run completes export and prints a passage and numeric score for each example. The printed values come from your run; do not expect a particular score or ordering as an installation check. Reaching the output confirms that tokenization and inference completed for the supplied inputs.

The gotcha is input length: the model’s context length is 514 tokens.[1] The script enables truncation, so longer query–passage inputs can lose text before scoring. Split long passages before passing them to the tokenizer, and inspect the text retained when a result looks surprising.

The repository lists 1.1 GB of F32 weights.[1] That file size does not establish the RAM or VRAM required for export or inference; measure memory use in your environment.

3. Optimum

Optimum from Hugging Face provides a route to run BAAI’s BAAI/bge-reranker-base through Microsoft’s ONNX Runtime. Install PyTorch, Hugging Face’s Transformers, Optimum, and the Optimum ONNX backend with its ONNX Runtime dependency. Installing the core optimum package alone does not supply the complete ONNX workflow. [5]

The example below exports the model, tokenizes a query and document together, and prints the resulting score. Run the installation and Python example in the same environment so that the exporter and model wrapper can find their dependencies. The model identifier must remain exactly BAAI/bge-reranker-base. [1][5]

python -m pip install torch transformers optimum "optimum-onnx[onnxruntime]"

python - <<'PY'
from transformers import AutoTokenizer
from optimum.onnxruntime import ORTModelForSequenceClassification

tokenizer = AutoTokenizer.from_pretrained("BAAI/bge-reranker-base")
model = ORTModelForSequenceClassification.from_pretrained(
    "BAAI/bge-reranker-base",
    export=True,
)

inputs = tokenizer(
    "How can I run AI locally?",
    "You can run a model on your own computer.",
    return_tensors="pt",
    truncation=True,
)
print(model(**inputs).logits.squeeze().tolist())
PY

A successful first run finishes the export and prints a numeric score without an exception. The score confirms that tokenization and inference completed; the example does not establish retrieval quality or performance. Keep the sample query and document unchanged until the workflow runs, then substitute your own text.

The repository lists F32 weights totaling 1.1 GB. [1] That file size does not establish the RAM or VRAM required during export or inference; measure memory use in your environment.

One gotcha is input length: the model’s context length is 514 tokens. [1] The example enables truncation, so review how longer query-document pairs are shortened before using the scores in a retrieval pipeline.

What hardware do you need to run bge-reranker-base?

BAAI’s BAAI/bge-reranker-base has 278 million parameters [1]. At 4-bit precision, its estimated weight memory is 139 MB, calculated as the cited parameter count × 0.5 bytes per parameter [1]. At 8-bit precision, its estimated weight memory is 278 MB, calculated as the cited parameter count × 1 byte per parameter [1]. Both calculations use decimal megabytes and describe weights alone. Treat them as planning estimates, not measured RAM or VRAM requirements for a running model.

Allow 1.1 GB of disk space for the published F32 weight files [1]. Keep additional disk space available for the runtime, dependencies and any converted files you create; the weight-file size does not establish the complete installation size. The repository does not ship GGUF builds [1]. The quantized memory estimates above therefore describe hypothetical weight representations, rather than downloadable artifacts supplied by BAAI. Check your chosen runtime’s conversion support before planning around either representation.

If your GPU has less free memory than the relevant weight estimate, choose CPU execution with available system RAM or use a GPU with more free memory. A GPU that barely clears the estimate still needs a loading check: parameter arithmetic does not establish total runtime memory. Verify memory use with your intended inputs before committing hardware to the deployment.

Which quantization should you choose?

BAAI publishes BAAI/bge-reranker-base with F32 weight files totalling 1.1 GB [1]. The repository ships no GGUF builds or quantized weight files [1]. Start with the supplied weights to establish a reference for checking any conversion.

For 4-bit weights, the estimated storage is 278 million parameters × 0.5 bytes per parameter ≈ 139 MB [1]. The calculation estimates packed parameter storage only. Actual files can include additional data, and the estimate is not a RAM or VRAM requirement. Measure memory use with your intended workload before deciding whether a conversion fits.

Choose that quantization as your default only when memory constraints justify conversion, your chosen workflow supports the model, and evaluation on representative queries produces acceptable rankings. Compare the converted model against the supplied weights using the same queries and candidate passages. A smaller estimated weight footprint alone does not establish suitability.

Move to higher precision if the converted model changes rankings enough to hurt your application, or if the conversion cannot be validated. The repository’s supplied F32 weights provide the reference option [1].

Frequently Asked Questions

What hardware do I need to run BAAI/bge-reranker-base locally?

BAAI’s BAAI/bge-reranker-base has 278 million parameters, a 514-token context length and 1.1 GB of F32 weight files [1]. Weight-file size alone does not establish runtime RAM or VRAM requirements. Measure memory use on your intended machine before buying hardware, and leave room for runtime overhead. Treat any memory budget calculated from the weight size as an estimate, rather than a verified minimum requirement.

How much does running BAAI/bge-reranker-base locally cost?

Build your budget around hardware, electricity and storage rather than assuming a fixed local-running price. BAAI/bge-reranker-base is MIT-licensed, and its F32 weight files occupy 1.1 GB [1]. Neither fact establishes operating cost or runtime memory requirements. Use your electricity tariff and measured power consumption to estimate ongoing expense, then assess whether your existing hardware can handle the workload before budgeting for an upgrade.

Can I use BAAI/bge-reranker-base commercially?

BAAI/bge-reranker-base carries the MIT license, which permits commercial use subject to its terms [1]. Review the license when packaging or distributing your application. Check your software dependencies separately: Hugging Face Transformers and Hugging Face Optimum carry Apache-2.0 licenses [3][5], while Microsoft ONNX Runtime carries the MIT license [4]. Keep the applicable license texts and notices with your deployment records.

How long does local setup take?

Plan for dependency installation, the model download and a successful local test before calling setup complete. BAAI/bge-reranker-base has 1.1 GB of F32 weight files [1], but download size does not establish elapsed setup time. Connection speed, package installation and troubleshooting affect your schedule. For a Hugging Face Transformers setup, include PyTorch in the installation rather than leaving it as a suggested follow-up dependency [3].

Should I use Transformers or look for a GGUF download?

Use the exact repository identifier BAAI/bge-reranker-base when selecting the model. The repository supplies F32 weights and does not ship GGUF builds [1]. For the Hugging Face Transformers route, install both PyTorch and Transformers; the listed Transformers release is v5.23.0 [3]. Keep a successful model load and a working inference call as separate setup checks before integrating the model into your application.

What alternatives to Transformers can I consider?

Evaluate Microsoft ONNX Runtime with Hugging Face Optimum as an alternative tooling path [4][5]. The listed releases are ONNX Runtime v1.32.0 [4] and Optimum v2.3.0 [5]. An export workflow also needs Optimum’s ONNX backend package, optimum-onnx; installing onnxruntime alone does not supply Optimum’s exporter or model wrappers [4][5]. Compare the paths using your own workload before making performance or memory claims.

Sources

  1. BAAI/bge-reranker-base model card (Hugging Face) — 2026-11-11 · bge-reranker-base on Q4KM
  2. Soaring from 4K to 400K: Extending LLM's Context with Activation Beacon — 2024-01-07
  3. huggingface/transformers (GitHub) — 2026-11-16
  4. microsoft/onnxruntime (GitHub) — 2026-11-16
  5. huggingface/optimum (GitHub) — 2026-11-16

Get these models on a hard drive

Skip the downloads. Browse our catalog of 985+ commercially-licensed AI models, available pre-loaded on high-speed drives.

Browse Model Catalog