Skip to content

API Reference parrot.rerankers.abstract

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

parrot.rerankers.abstract

View source

Abstract base class for relevance rerankers.

This module defines the AbstractReranker ABC that all reranker implementations must subclass. It follows the same async-first lifecycle pattern as AbstractClient and AbstractStore:

  • One required async method: rerank().
  • Two optional lifecycle hooks: load() and cleanup().

Class AbstractReranker

Abstract base class for relevance rerankers.

All reranker implementations must subclass this class and implement the rerank() method. The optional load() and cleanup() lifecycle hooks default to no-ops and can be overridden to manage heavy resources (e.g. GPU memory, model downloads).

Contract: On internal failure, implementations MUST NOT raise from rerank(). Instead they MUST return the input documents wrapped as RerankedDocument with rerank_score=float('nan') and the original ordering preserved, allowing the caller to apply a safe fallback policy.

Method AbstractReranker.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. If None, return all documents reranked.

Returns: list[RerankedDocument] — Reranked documents in descending score order. Length is min(top_n, len(documents)) when top_n is set, or len(documents) otherwise. On internal failure the implementation MUST NOT raise; it MUST return the input documents wrapped as RerankedDocument with rerank_score=float('nan') and the original ordering preserved.

Method AbstractReranker.load

Eager model load.

Called to explicitly load/warm-up the model before the first rerank() call. Default implementation is a no-op; subclasses override this to perform expensive initialisation.

load() -> None

Method AbstractReranker.cleanup

Release resources (GPU memory, executors, etc.).

Called when the reranker is no longer needed. Default implementation is a no-op; subclasses override to release GPU memory or thread pools.

cleanup() -> None

Alias RerankedDocument

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

Alias SearchResult

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

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