You’ll use this when…
- Queries are nuanced and require semantic understanding beyond vector distance.
- Large memory collections produce too many near matches to review manually.
- You want consistent scoring across providers by delegating ranking to a dedicated model.
The
Configure it and See it in action snippets below use the Python SDK. The self-hosted TypeScript SDK supports the Cohere, Zero Entropy, Sentence Transformer, Hugging Face, and LLM rerankers; see TypeScript SDK.TypeScript SDK
The self-hosted TypeScript SDK (mem0ai/oss) ships five rerankers: Cohere, Zero Entropy, Sentence Transformer, Hugging Face, and the LLM reranker. Configure one under reranker, then opt in per search with rerank: true. Keys are camelCase (apiKey, not api_key).
Provider SDKs are peer dependencies. Install the one your reranker needs:
Hosted rerankers (Cohere, Zero Entropy)
Both call a hosted API and read their key from config or the provider’s environment variable (COHERE_API_KEY, ZERO_ENTROPY_API_KEY).
Local cross-encoders (Sentence Transformer, Hugging Face)
Both run a cross-encoder locally with Transformers.js: no API key, no network at inference time. Because Transformers.js runs ONNX weights, the default models are the ONNX mirrors of the Python SDK’s defaults (sentence_transformer → Xenova/ms-marco-MiniLM-L-6-v2, huggingface → Xenova/bge-reranker-base). Point model at any ONNX-exported cross-encoder on the Hub to override.
batchSize and showProgressBar are accepted for config parity with the Python SDK but are no-ops in this runtime, because a memory search reranks a small candidate set in a single in-process forward pass. The model is downloaded once and cached in-process on first use.LLM reranker
To score with an LLM instead of a dedicated reranker, use thellm_reranker provider. It builds its own LLM from the reranker’s config (defaulting to openai / gpt-4o-mini) rather than reusing the Memory’s main llm:
config.llm to override the default:
Config reference
rerank is opt-in per search and a no-op when no reranker is configured. If the reranker call fails, Mem0 logs a warning and returns the original vector-ranked results.Feature anatomy
- Initial vector search: Retrieve candidate memories by similarity.
- Reranker pass: A specialized model scores each candidate against the original query.
- Reordered results: Mem0 sorts responses using the reranker’s scores before returning them.
- Optional fallbacks: Toggle reranking per request or disable it entirely if performance or cost becomes a concern.
Supported providers
Supported providers
- Cohere: Multilingual hosted reranker with API-based scoring.
- Sentence Transformer: Local Hugging Face cross-encoders for GPU or CPU.
- Hugging Face: Bring any hosted or on-prem reranker model ID.
- LLM Reranker: Use your preferred LLM (OpenAI, etc.) for prompt-driven scoring.
- Zero Entropy: High-quality neural reranking tuned for retrieval tasks.
Provider comparison
Provider comparison
Configure it
Basic setup
Confirm
results["results"][0]["score"] reflects the reranker output: if the field is missing, the reranker was not applied.Provider-specific options
Keep authentication keys in environment variables when you plug these configs into production projects.
Full stack example
A quick search should now return results with both vector and reranker scores, letting you compare improvements immediately.
Async support
Inspect the async response to confirm reranking still applies; the scores should match the synchronous implementation.
Tune performance and cost
Handle failures gracefully
Migrate from v0.x
See it in action
Basic reranked search
Expect each result to list the reranker-adjusted score so you can compare ordering against baseline vector results.
Toggle reranking per request
You should see the same memories in both lists, but the reranked response will reorder them based on semantic relevance.
Combine with metadata filters
Verify filtered reranked searches still respect every metadata clause: reranking only reorders candidates, it never bypasses filters.
Real-world playbooks
Customer support
Top results should highlight tickets matching the login issue context so agents can respond faster.
Content recommendation
Expect high-scoring recommendations that match both the requested theme and any metadata limits you applied.
Personal assistant
Each workflow keeps the same
m.search(...) signature, so you can template these queries across agents with only the prompt and filters changing.Verify the feature is working
- Inspect result payloads for both
score(vector) and reranker scores; mismatched fields indicate the reranker didn’t execute. - Track latency before and after enabling reranking to ensure SLAs hold.
- Review provider logs or dashboards for throttling or quota warnings.
- Run A/B comparisons (rerank on/off) to validate improved relevance before defaulting to reranked responses.
Best practices
- Start local: Try Sentence Transformer models to prove value before paying for hosted APIs.
- Monitor latency: Add metrics around reranker duration so you notice regressions quickly.
- Control spend: Use
top_kand selective toggles to cap hosted reranker costs. - Keep a fallback: Always catch reranker failures and continue with vector-only ordering.
- Experiment often: Swap providers or models to find the best fit for your domain and language mix.
Configure Rerankers
Review provider fields, defaults, and environment variables before going live.
Build a Custom LLM Reranker
Extend scoring with prompt-tuned LLM rerankers for niche workflows.