Skip to content

feat(reranker): add Jina v3 reranker support#331

Merged
jundot merged 3 commits intojundot:mainfrom
yes999zc:feat/jina-reranker-support
Mar 21, 2026
Merged

feat(reranker): add Jina v3 reranker support#331
jundot merged 3 commits intojundot:mainfrom
yes999zc:feat/jina-reranker-support

Conversation

@yes999zc
Copy link
Copy Markdown
Contributor

@yes999zc yes999zc commented Mar 21, 2026

What

Add support for Jina v3 reranker models (jinaai/jina-reranker-v3-mlx) to omlx's reranker module.

Why

Issue #326 requested Jina reranker support. The Jina v3 reranker uses <|score_token|> logits for scoring instead of the yes/no token approach used by Qwen3-Reranker, and requires a separate implementation path.

Changes

  • Add JinaForRanking to CAUSAL_LM_RERANKER_ARCHITECTURES in model_discovery.py
  • Add MLXRerankerModel._load_jina_reranker() for loading Jina models via mlx-lm
  • Add MLXRerankerModel._rerank_jina() for reranking using <|score_token|> logits
  • Dispatch to the Jina path when architecture is JinaForRanking
  • Fix token masking and BOS/EOS handling in the Jina rerank implementation
  • Fix token ID resolution to handle different tokenizer formats (str vs Token objects in added_tokens_decoder)

Implementation Notes

  • Jina v3 reranker is based on Qwen3 architecture and uses <|score_token|> and <|rerank_token|> special tokens
  • The scoring extracts logits at the <|score_token|> position at the last token
  • The implementation follows the same pattern as the existing _rerank_causal_lm() but with Jina-specific token handling
  • Falls back to existing reranker implementations for other architectures (no breaking changes)

Validation (Local testing PASSED ✅)

This implementation has been validated with a real jinaai/jina-reranker-v3-mlx model:

  • Syntax checked with omlx's bundled Python environment
  • End-to-end tested with actual model (downloaded via Hugging Face Hub)
  • Functional verification: Model loads successfully, token IDs resolved correctly (<|score_token|> = 151669, <|rerank_token|> = 151671)
  • Reranking works: Produces sensible scores with correct sorting
  • Code patterns: Follows existing patterns in reranker.py

Testing Results

The implementation was tested locally with:

  • Model: jinaai/jina-reranker-v3-mlx
  • Query: "What is artificial intelligence?"
  • Documents: 3 sample texts about AI, ML, and Python
  • Result: Successful loading and reranking with correct token resolution and score sorting

Notes

  • Token ID resolution now handles multiple tokenizer formats (string tokens, Token objects, dict entries)
  • Fallback mechanisms: added_tokens_decoderconvert_tokens_to_idsget_added_vocab

Closes: #326

FocusFlow Dev added 3 commits March 21, 2026 08:48
- Add JinaForRanking to CAUSAL_LM_RERANKER_ARCHITECTURES in model_discovery
- Add MLXRerankerModel._load_jina_reranker() for loading jinaai/jina-reranker-v3-mlx
  via mlx-lm with <|score_token|> and <|rerank_token|> token resolution
- Add MLXRerankerModel._rerank_jina() for reranking using score token logits
- Dispatch to _rerank_jina() when model is JinaForRanking architecture

Closes: jundot#326
- Fix token ID lookup in added_tokens_decoder (handle both str and Token objects)
- Add fallback to convert_tokens_to_ids and get_added_vocab
- Test passes with real jina-reranker-v3-mlx model
@jundot jundot force-pushed the main branch 7 times, most recently from f6faf2f to c2beead Compare March 21, 2026 05:58
Copy link
Copy Markdown
Owner

@jundot jundot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the code. Clean scope, follows the existing _rerank_causal_lm pattern well.

Two bare except: in _load_jina_reranker() should be except Exception: to avoid catching KeyboardInterrupt/SystemExit. I'll fix those in a follow-up commit after merge.

LGTM otherwise.

@jundot jundot merged commit 32be618 into jundot:main Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Jina reranker architecture

2 participants