Skip to content

API Reference parrot.rerankers.local

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.rerankers.local

View source

Local cross-encoder reranker implementation.

This module provides LocalCrossEncoderReranker, a production-grade in-process reranker that loads a HuggingFace cross-encoder model once and scores (query, passage) pairs via batched forward passes.

Supported models:

  • BAAI/bge-reranker-v2-m3 (default, 568M params, multilingual)
  • jinaai/jina-reranker-v2-base-multilingual (278M, requires trust_remote_code=True)
  • cross-encoder/ms-marco-MiniLM-L-12-v2 (33M, English-only, fast CI path)

Device/precision autodetection:

  • GPU available → FP16 (model.half())
  • CPU only → INT8 (torch.quantization.quantize_dynamic on nn.Linear)
  • Override via RerankerConfig.device / RerankerConfig.precision

Alias AbstractReranker

Re-exported from parrot.rerankers.abstract.AbstractReranker.

Class LocalCrossEncoderReranker

In-process cross-encoder reranker using HuggingFace models.

Loads the model eagerly at construction time with optional warmup so that the first real rerank() call does not pay cold-start latency.

A process-wide model cache (keyed by (model_name, device, precision)) ensures that two bots configured with the same reranker share one model in memory. A per-device ThreadPoolExecutor(max_workers=1) serialises GPU access to prevent OOM under concurrent requests.

Parameter Type Default Description
config Optional[RerankerConfig] None A RerankerConfig instance. If None, kwargs are used to build one (e.g. model_name="...", device="cpu").
**kwargs {} Forwarded to RerankerConfig when config is None.

Method LocalCrossEncoderReranker.rerank

Score (query, document) pairs and return them sorted by relevance.

rerank(query: str, documents: list[SearchResult], top_n: Optional[int] = None) -> list[RerankedDocument]

Parameter Type Default Description
query str User query text.
documents list[SearchResult] Candidate documents from upstream retrieval.
top_n Optional[int] None If set, return only the top N results. None returns all.

Returns: list[RerankedDocument] — RerankedDocument list sorted by descending rerank_score. On failure, returns the original ordering with rerank_score=NaN.

Method LocalCrossEncoderReranker.cleanup

Shut down the per-device ThreadPoolExecutor.

Does NOT evict the model from the process cache — the model is shared across all instances that use the same (model_name, device, precision) triple and should not be unloaded unilaterally.

cleanup() -> None

Alias RerankedDocument

Re-exported from parrot.rerankers.models.RerankedDocument.

Alias RerankerConfig

Re-exported from parrot.rerankers.models.RerankerConfig.

Alias SearchResult

Re-exported from parrot.models.stores.SearchResult.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally