Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:24kchengYe MemoMind Cross Encoder Model

From Leeroopedia
Knowledge Sources
Domains Infrastructure, Retrieval
Last Updated 2026-10-28 14:45 GMT

Overview

Cross-encoder reranking model (default: cross-encoder/ms-marco-MiniLM-L-6-v2) for neural re-ranking of search results with recency and temporal boosts.

Description

This environment provides the cross-encoder model used to re-rank merged search candidates from the hybrid retrieval pipeline. The cross-encoder takes query-document pairs and produces relevance scores (logits), which are sigmoid-normalized to [0,1]. Recency and temporal proximity are applied as multiplicative boosts (±10% each via `alpha=0.2`). Multiple backends are supported: local (SentenceTransformers, default), Cohere (`rerank-english-v3.0`), TEI, flashrank, ZeroEntropy, and LiteLLM. The production Docker image pre-downloads `cross-encoder/ms-marco-MiniLM-L-6-v2` (80MB, ~80ms/100 pairs on CPU).

Usage

Use this environment for the reranking phase of the recall pipeline — after RRF merges semantic/BM25/graph/temporal results, the cross-encoder re-scores the top candidates. Required by the `CrossEncoderReranker_rerank` implementation.

System Requirements

Category Requirement Notes
OS Linux / macOS CPU-only in production Docker
Hardware 2GB+ RAM (local) ms-marco-MiniLM-L-6-v2 is 80MB; CPU inference ~80ms/100 pairs
Disk 200MB+ for model cache `HF_HOME=/models` in Docker
GPU Optional (CUDA or MPS) Auto-detected; CPU fallback supported

Dependencies

Python Packages

  • `sentence-transformers` >= 2.2 — Local cross-encoder model
  • `torch` — Backend (CPU-only in production Docker)
  • `numpy` — Sigmoid normalization of cross-encoder logits
  • `httpx` — HTTP client for remote reranker APIs (Cohere, TEI, LiteLLM, ZeroEntropy)

Models

  • `cross-encoder/ms-marco-MiniLM-L-6-v2` — Default local model (80MB, fast)
  • `ms-marco-MiniLM-L-12-v2` — flashrank default (better quality, slower)
  • `rerank-english-v3.0` — Cohere reranker API
  • `jina-reranker-v2` — Requires `trust_remote_code=true`

Credentials

For `local` provider:

  • `HINDSIGHT_API_RERANKER_PROVIDER`: `local` (default)
  • `HINDSIGHT_API_RERANKER_LOCAL_MODEL`: Model name (default: `cross-encoder/ms-marco-MiniLM-L-6-v2`)
  • `HINDSIGHT_API_RERANKER_LOCAL_FORCE_CPU`: Force CPU (default: `false`)
  • `HINDSIGHT_API_RERANKER_LOCAL_MAX_CONCURRENT`: Max concurrent CPU reranking (default: 4 — prevents thrashing)
  • `HINDSIGHT_API_RERANKER_LOCAL_TRUST_REMOTE_CODE`: Allow custom model code (default: `false`)
  • `HINDSIGHT_API_RERANKER_MAX_CANDIDATES`: Max candidates to rerank (default: 300)

For `cohere` provider:

  • `HINDSIGHT_API_RERANKER_COHERE_API_KEY`: Cohere API key
  • `HINDSIGHT_API_RERANKER_COHERE_MODEL`: Model (default: `rerank-english-v3.0`)

For `tei` provider:

  • `HINDSIGHT_API_RERANKER_TEI_URL`: TEI server URL
  • `HINDSIGHT_API_RERANKER_TEI_BATCH_SIZE`: Batch size (default: 128)
  • `HINDSIGHT_API_RERANKER_TEI_MAX_CONCURRENT`: Max concurrent (default: 8)

For `flashrank` provider:

  • `HINDSIGHT_API_RERANKER_FLASHRANK_MODEL`: Model (default: `ms-marco-MiniLM-L-12-v2`)
  • `HINDSIGHT_API_RERANKER_FLASHRANK_CACHE_DIR`: Cache directory (optional)

For `zeroentropy` provider:

  • `HINDSIGHT_API_RERANKER_ZEROENTROPY_API_KEY`: ZeroEntropy API key
  • `HINDSIGHT_API_RERANKER_ZEROENTROPY_MODEL`: Model (default: `zerank-2`)

Quick Install

# Local reranker (SentenceTransformers + CPU torch)
pip install sentence-transformers numpy
pip install torch --index-url https://download.pytorch.org/whl/cpu

# Pre-download production model
python -c "from huggingface_hub import snapshot_download; snapshot_download('cross-encoder/ms-marco-MiniLM-L-6-v2')"

Code Evidence

Reranker defaults from `config.py:385-396`:

DEFAULT_RERANKER_PROVIDER = "local"
DEFAULT_RERANKER_LOCAL_MODEL = "cross-encoder/ms-marco-MiniLM-L-6-v2"
DEFAULT_RERANKER_LOCAL_FORCE_CPU = False
DEFAULT_RERANKER_LOCAL_MAX_CONCURRENT = 4  # Limit concurrent CPU-bound reranking
DEFAULT_RERANKER_LOCAL_TRUST_REMOTE_CODE = False  # Security: disabled by default
DEFAULT_RERANKER_MAX_CANDIDATES = 300

Cross-encoder initialization (lazy) from `reranking.py:95-109`:

async def ensure_initialized(self):
    if self._initialized:
        return
    cross_encoder = self.cross_encoder
    # For local providers, run in thread pool to avoid blocking event loop
    if cross_encoder.provider_name == "local":
        loop = asyncio.get_event_loop()
        await loop.run_in_executor(None, lambda: asyncio.run(cross_encoder.initialize()))
    else:
        await cross_encoder.initialize()
    self._initialized = True

Candidate limit enforcement from `memory_engine.py:2931-2936`:

reranker_max_candidates = get_config().reranker_max_candidates
if len(merged_candidates) > reranker_max_candidates:
    pre_filtered_count = len(merged_candidates) - reranker_max_candidates
    merged_candidates = merged_candidates[:reranker_max_candidates]

Score normalization from `reranking.py:154-161`:

def sigmoid(x):
    return 1 / (1 + np.exp(-x))
normalized_scores = [sigmoid(score) for score in scores]

Common Errors

Error Message Cause Solution
`sentence-transformers is required` Package not installed `pip install sentence-transformers`
Slow reranking / CPU thrashing Too many concurrent reranking tasks Reduce `HINDSIGHT_API_RERANKER_LOCAL_MAX_CONCURRENT` (default 4)
Model not found HuggingFace model not cached Pre-download model or set `HF_HOME`
MPS instability (macOS daemon) Apple Silicon MPS issues in daemon mode Set `HINDSIGHT_API_RERANKER_LOCAL_FORCE_CPU=true`

Compatibility Notes

  • Lazy initialization: The reranker is lazily initialized (`HINDSIGHT_API_LAZY_RERANKER` flag) to avoid loading the model on startup if reranking is not used.
  • CPU concurrency limit: `RERANKER_LOCAL_MAX_CONCURRENT=4` prevents CPU thrashing — increase only on multi-core machines.
  • trust_remote_code: Disabled by default. Required for `jina-reranker-v2` and similar custom-architecture models.
  • macOS daemon mode: Use `FORCE_CPU=true` to avoid MPS/XPC instability.
  • max_candidates: Default 300; candidates beyond this are pre-filtered by RRF score before reranking.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment