Component
Core / Python SDK
Description
Use Case
The current reranker layer only supports a fixed set of providers — cohere, sentence_transformer, zero_entropy, llm_reranker, and huggingface (see mem0/utils/factory.py). There is no way to point mem0 at a self-hosted or third-party reranker service that exposes a Cohere/Jina-compatible HTTP /rerank endpoint (e.g. self-deployed bge-reranker, Jina Reranker, Voyage, SiliconFlow, Together, vLLM-hosted rerankers, internal corporate gateways, etc.).
Concretely, the current limitations are:
RerankerFactory.provider_to_class is a hardcoded allow-list — anything else raises Unsupported reranker provider (factory.py:221-246).
BaseRerankerConfig exposes only provider / model / api_key / top_k; there is no base_url / endpoint field (base.py:5-17).
RerankerConfig sets model_config = {"extra": "forbid"} (config.py:12), so users can't even sneak extra fields through.
- The existing
CohereReranker constructs cohere.Client(api_key) without a base URL (cohere_reranker.py:32), so it can't be repointed at a Cohere-compatible self-hosted gateway either.
As a result, configuring a custom reranker via the /configure REST endpoint (or via MemoryConfig in code) is impossible today, even though the equivalent already works on the LLM/embedding side via openai_base_url / custom OpenAI-compatible providers.
Proposed Solution
Add a new provider, e.g. openai_compatible (or custom), that speaks the standard rerank HTTP contract:
POST {base_url}/rerank
Authorization: Bearer {api_key}
{
"model": "...",
"query": "...",
"documents": ["...", "..."],
"top_n": N
}
Concrete changes:
mem0/configs/rerankers/openai_compatible.py — new config class extending BaseRerankerConfig with base_url: str and (optional) timeout, headers.
mem0/reranker/openai_compatible_reranker.py — new reranker that POSTs to {base_url}/rerank using httpx, maps results[].index and relevance_score back onto the input docs (same shape as CohereReranker.rerank returns).
- Register
"openai_compatible" in RerankerFactory.provider_to_class in factory.py:221.
- Tests under
tests/reranker/openai_compatible/ mocking the HTTP call.
- Doc page under
docs/components/rerankers/ (with Use when ... description, and an entry in docs/llms.txt).
Example usage after the change:
config = {
"reranker": {
"provider": "openai_compatible",
"config": {
"base_url": "https://my-reranker.internal/v1",
"api_key": "sk-...",
"model": "bge-reranker-v2-m3",
"top_k": 10,
},
},
}
m = Memory.from_config(config)
And the equivalent via the server's POST /configure:
{
"reranker": {
"provider": "openai_compatible",
"config": {
"base_url": "https://my-reranker.internal/v1",
"api_key": "sk-...",
"model": "bge-reranker-v2-m3"
}
}
}
I'd be happy to send a PR implementing this — please let me know if openai_compatible is the preferred name (vs custom, http, generic)
Component
Core / Python SDK
Description
Use Case
The current reranker layer only supports a fixed set of providers —
cohere,sentence_transformer,zero_entropy,llm_reranker, andhuggingface(seemem0/utils/factory.py). There is no way to point mem0 at a self-hosted or third-party reranker service that exposes a Cohere/Jina-compatible HTTP/rerankendpoint (e.g. self-deployedbge-reranker,Jina Reranker,Voyage,SiliconFlow,Together, vLLM-hosted rerankers, internal corporate gateways, etc.).Concretely, the current limitations are:
RerankerFactory.provider_to_classis a hardcoded allow-list — anything else raisesUnsupported reranker provider(factory.py:221-246).BaseRerankerConfigexposes onlyprovider / model / api_key / top_k; there is nobase_url/endpointfield (base.py:5-17).RerankerConfigsetsmodel_config = {"extra": "forbid"}(config.py:12), so users can't even sneak extra fields through.CohereRerankerconstructscohere.Client(api_key)without a base URL (cohere_reranker.py:32), so it can't be repointed at a Cohere-compatible self-hosted gateway either.As a result, configuring a custom reranker via the
/configureREST endpoint (or viaMemoryConfigin code) is impossible today, even though the equivalent already works on the LLM/embedding side viaopenai_base_url/ custom OpenAI-compatible providers.Proposed Solution
Add a new provider, e.g.
openai_compatible(orcustom), that speaks the standard rerank HTTP contract:Concrete changes:
mem0/configs/rerankers/openai_compatible.py— new config class extendingBaseRerankerConfigwithbase_url: strand (optional)timeout,headers.mem0/reranker/openai_compatible_reranker.py— new reranker that POSTs to{base_url}/rerankusinghttpx, mapsresults[].indexandrelevance_scoreback onto the input docs (same shape asCohereReranker.rerankreturns)."openai_compatible"inRerankerFactory.provider_to_classin factory.py:221.tests/reranker/openai_compatible/mocking the HTTP call.docs/components/rerankers/(withUse when ...description, and an entry indocs/llms.txt).Example usage after the change:
And the equivalent via the server's
POST /configure:{ "reranker": { "provider": "openai_compatible", "config": { "base_url": "https://my-reranker.internal/v1", "api_key": "sk-...", "model": "bge-reranker-v2-m3" } } }I'd be happy to send a PR implementing this — please let me know if
openai_compatibleis the preferred name (vscustom,http,generic)