Reranker
- interface RerankerInterface
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Service\ Rerank\ Reranker Interface
Neutral cross-encoder reranking protocol (ADR-075: Neutral cross-encoder reranker protocol): scores retrieval candidates against a query. Candidates go in as plain
id/textshapes and scores come back as plainid/scoreshapes — no consumer DTOs cross the boundary. Consumers own DTO mapping, the ordering merge, the degradation policy on failure, and any score-threshold gate.The container service is factory-built from the extension configuration: an empty
rerankerEndpointresolves toNullReranker, a configured endpoint toHttpReranker.- rerank ( string $query, array $candidates) : array
-
Score each (query, candidate text) pair. Returns one entry per scored candidate in input order; an entry the backend failed to score may be omitted — merge by
id.- param string $query
-
The query the candidates are scored against
- param array $candidates
-
list<array{id: string, text: string}> - throws
-
RerankerExceptionwhen the reranker backend is unreachable or answers outside the protocol
- Returns
-
list<array{id: string, score: float}>
- class HttpReranker
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Service\ Rerank\ Http Reranker
Speaks the cross-encoder sidecar contract (
Build/reranker):POST {endpoint}/rerankwith{"query", "documents"}, scores returned in input order. Pools above the sidecar's batch cap (128 documents) are split into sequential requests. The score scale is model-specific (defaultBAAI/bge-reranker-v2-m3).
- class NullReranker
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Service\ Rerank\ Null Reranker
Selected when no sidecar endpoint is configured. Returns one entry per candidate in input order with a uniform score of
0.0— no ranking signal, shape-identical toHttpReranker.
- class RerankerException
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Service\ Rerank\ Exception\ Reranker Exception
Typed failure of the reranker backend: unreachable endpoint (code
1784750001), non-200 status (1784750002), invalid JSON (1784750003), or a response missing thescoresarray (1784750004). ImplementsNrLlmExceptionInterface(ADR-053); the caller decides how to degrade — nr_llm never silently falls back.
Configuration
Extension configuration keys (nr_llm):
rerankerEndpoint— base URL of the cross-encoder sidecar, e.g.http://reranker:8081. Empty (default) disables reranking.rerankerTimeout— request timeout in seconds (default 30; a CPU cross-encoder can be slow for a wide candidate pool).
See Build/reranker/README.md for running the sidecar.