Skip to main content
Sentence Transformer reranker provides local reranking using HuggingFace cross-encoder models, perfect for privacy-focused deployments where you want to keep data on-premises.

Models

Any HuggingFace cross-encoder model can be used. Popular choices include:
  • cross-encoder/ms-marco-MiniLM-L-6-v2: Default, good balance of speed and accuracy
  • cross-encoder/ms-marco-TinyBERT-L-2-v2: Fastest, smaller model size
  • cross-encoder/ms-marco-electra-base: Higher accuracy, larger model
  • cross-encoder/stsb-distilroberta-base: Good for semantic similarity tasks

Installation

Configuration

Python

TypeScript (self-hosted)

The TypeScript OSS SDK (mem0ai/oss) runs this reranker locally with Transformers.js. Because it executes ONNX weights, the default model is the ONNX mirror of the Python default: Xenova/ms-marco-MiniLM-L-6-v2. Point model at any ONNX-exported cross-encoder on the Hub (a raw cross-encoder/... PyTorch checkpoint will not load in this runtime).
batchSize and showProgressBar are accepted for parity with the Python SDK but are no-ops in the TypeScript runtime, because a search reranks a small candidate set in a single in-process forward pass. The model downloads once and is cached in-process.

GPU Acceleration

For better performance, use GPU acceleration:
Python

Usage Example

Python

Custom Models

You can use any HuggingFace cross-encoder model:
Python

Configuration Parameters

Advantages

  • Privacy: Complete local processing, no external API calls
  • Cost: No per-token charges after initial model download
  • Customization: Use any HuggingFace cross-encoder model
  • Offline: Works without internet connection after model download

Performance Considerations

  • First Run: Model download may take time initially
  • Memory Usage: Models require GPU/CPU memory
  • Batch Size: Optimize batch size based on available memory
  • Device: GPU acceleration significantly improves speed

Best Practices

  1. Model Selection: Choose model based on accuracy vs speed requirements
  2. Device Management: Use GPU when available for better performance
  3. Batch Processing: Process multiple documents together for efficiency
  4. Memory Monitoring: Monitor system memory usage with larger models