feat(reranker): add OpenAI/Cohere-compatible custom reranker endpoint#5342
Open
sanidhyasin wants to merge 1 commit into
Open
feat(reranker): add OpenAI/Cohere-compatible custom reranker endpoint#5342sanidhyasin wants to merge 1 commit into
sanidhyasin wants to merge 1 commit into
Conversation
0594c4b to
841c593
Compare
Adds an `openai_compatible` reranker provider that speaks the standard
Cohere/Jina-style `/rerank` HTTP contract, so Mem0 can be pointed at any
self-hosted or third-party reranker (bge-reranker, Jina, Voyage,
SiliconFlow, Together, vLLM-hosted rerankers, internal gateways) the same
way `openai_base_url` works on the LLM/embedding side.
- new `OpenAICompatibleRerankerConfig` with `base_url` / `timeout` / `headers`
- new `OpenAICompatibleReranker` that POSTs to `{base_url}/rerank` via httpx,
maps `index` + `relevance_score`/`score` back onto input docs, applies
`top_k`, and falls back to original order on failure
- register `openai_compatible` in `RerankerFactory`
- unit tests covering config validation, request shaping, score mapping,
top_k truncation, bare-list responses, env-var base_url, and error fallback
- docs page, config reference, nav entry, and llms.txt index
Closes mem0ai#5149
841c593 to
f8c7803
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked Issue
Closes #5149
Description
The reranker layer currently only supports a fixed allow-list of providers (
cohere,sentence_transformer,zero_entropy,llm_reranker,huggingface). There is no way to point Mem0 at a self-hosted or third-party reranker that exposes a Cohere/Jina-compatible/rerankHTTP endpoint (e.g. self-deployedbge-reranker, Jina, Voyage, SiliconFlow, Together, vLLM-hosted rerankers, or internal corporate gateways) — even though the equivalent already works on the LLM/embedding side viaopenai_base_url.This PR adds a new
openai_compatiblereranker provider that speaks the standard rerank HTTP contract:Changes
mem0/configs/rerankers/openai_compatible.py—OpenAICompatibleRerankerConfigextendingBaseRerankerConfigwithbase_url(required),timeout, andheaders.mem0/reranker/openai_compatible_reranker.py—OpenAICompatibleRerankerthat POSTs to{base_url}/rerankusinghttpx, maps each result'sindex+relevance_score/scoreback onto the input documents (same return shape asCohereReranker), appliestop_k, and falls back to the original order on failure (consistent with existing rerankers).mem0/utils/factory.py— register"openai_compatible"inRerankerFactory.provider_to_class.tests/rerankers/test_openai_compatible_reranker.pymocking the HTTP call (config validation, request shaping, score mapping/sorting,top_ktruncation, bare-list responses, env-varbase_url, error fallback, and factory wiring).docs/components/rerankers/models/openai_compatible.mdx, an entry indocs/components/rerankers/config.mdx, nav entry indocs/docs.json, anddocs/llms.txtindex line (verified in sync viascripts/check-llms-txt-coverage.py).Example usage
Type of Change
Breaking Changes
N/A — purely additive; a new opt-in provider with no change to existing providers or defaults.
Test Coverage
All 43 tests in
tests/rerankers/pass (12 new), andruff checkis clean on the changed files.Checklist