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

Implementation:24kchengYe MemoMind CrossEncoderReranker rerank

From Leeroopedia
Knowledge Sources
Domains Information_Retrieval, NLP
Last Updated 2026-10-28 00:00 GMT

Overview

Wrapper for cross-encoder neural reranking of RRF-fused search candidates with recency and temporal proximity boosts, provided by the MemoMind recall pipeline.

Description

The CrossEncoderReranker class and apply_combined_scoring function form the reranking stage of the recall pipeline. After RRF fusion produces merged candidates, the cross-encoder jointly encodes query-document pairs to produce more accurate relevance scores.

The reranking process:

  1. Pair preparation: query-document pairs are prepared with date information prepended ("[Date: June 5, 2024 (2024-06-05)] doc_text")
  2. Cross-encoder scoring: the model returns logits, normalized to [0,1] via sigmoid
  3. Combined scoring: apply_combined_scoring multiplies the normalized cross-encoder score by recency_boost and temporal_boost

The default local model is cross-encoder/ms-marco-MiniLM-L-6-v2. The cross-encoder is configurable via environment variables (see cross_encoder.py) and supports both local and API providers. Lazy initialization avoids loading the model until first use.

Usage

Import these functions when you need to rerank retrieval results with a neural model and apply temporal boosts. They are called by the recall pipeline after RRF fusion.

Code Reference

Source Location

  • Repository: MemoMind
  • File: engine/hindsight_api/engine/search/reranking.py
  • Lines: CrossEncoderReranker.rerank at L111-177; apply_combined_scoring at L18-69

Signature

class CrossEncoderReranker:
    def __init__(self, cross_encoder=None):
        ...

    async def ensure_initialized(self):
        ...

    async def rerank(
        self, query: str, candidates: list[MergedCandidate]
    ) -> list[ScoredResult]:
        ...

def apply_combined_scoring(
    scored_results: list[ScoredResult],
    now: datetime,
    recency_alpha: float = 0.2,
    temporal_alpha: float = 0.2,
) -> None:

Import

from hindsight_api.engine.search.reranking import CrossEncoderReranker, apply_combined_scoring

I/O Contract

Inputs

Name Type Required Description
query str Yes Search query
candidates list[MergedCandidate] Yes Merged candidates from RRF
now datetime Yes Current UTC time for recency calculation
recency_alpha float No Max recency adjustment (default 0.2 -> +/-10%)
temporal_alpha float No Max temporal adjustment (default 0.2 -> +/-10%)

Outputs

Name Type Description
scored_results list[ScoredResult] Results sorted by combined_score (mutated in-place by apply_combined_scoring)

Usage Examples

Reranking with Combined Scoring

import asyncio
from datetime import datetime, timezone
from hindsight_api.engine.search.reranking import CrossEncoderReranker, apply_combined_scoring

async def main():
    reranker = CrossEncoderReranker()
    await reranker.ensure_initialized()

    # Rerank RRF-fused candidates
    scored = await reranker.rerank(query="What did I learn about ML?", candidates=merged)

    # Apply recency and temporal boosts
    apply_combined_scoring(scored, now=datetime.now(timezone.utc))

    for result in scored[:10]:
        print(f"combined={result.combined_score:.4f} ce={result.cross_encoder_score_normalized:.4f} "
              f"recency={result.recency:.2f} temporal={result.temporal:.2f}")

asyncio.run(main())

Related Pages

Implements Principle

Requires Environment

Uses Heuristics

Page Connections

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