Implementation:24kchengYe MemoMind CrossEncoderReranker rerank
| 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:
- Pair preparation: query-document pairs are prepared with date information prepended ("[Date: June 5, 2024 (2024-06-05)] doc_text")
- Cross-encoder scoring: the model returns logits, normalized to [0,1] via sigmoid
- 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())