Interface Reranker
Providers advertise the model identifiers they support through
supports(String) and are discovered with ServiceLoader.
TnsAI deliberately does not bundle or impersonate a cross-encoder model: provider
modules own model inference, credentials, transport, and lifecycle management.
Implementations may reorder or remove candidates, but must not introduce
documents that were not present in Reranker.Request.documents(). The runtime
validates that invariant and applies Reranker.Request.topN() after the provider
returns.
Thread safety
Implementations must be thread-safe. A single provider
instance is shared by every agent thread for the JVM's lifetime: the
retrieval SPI that owns reranking is memoised in an
AtomicReference by
RetrievalSpi.find(), and it resolves the provider from a registry
built once from ServiceLoader. Providers must therefore
keep no per-request mutable state in fields; per-call state belongs in
locals derived from the Reranker.Request.
- Since:
- 0.13.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordImmutable input passed to aRerankerprovider. -
Method Summary
Modifier and TypeMethodDescriptionstatic RerankernoOp()Returns the null-object reranker: it advertises no model and returns candidates in the order it received them.rerank(Reranker.Request request) Reranks retrieved candidates for the original user query.booleanReturns whether this provider supports the exact model identifier.
-
Method Details
-
noOp
Returns the null-object reranker: it advertises no model and returns candidates in the order it received them.Lets a call site hold a
Rerankerwhether or not@Search.rerankis enabled, so the disabled case needs nonullsentinel.supports(String)answersfalsefor every identifier, so the no-op can never win provider resolution and mask a genuinely missing provider.- Returns:
- the shared no-op instance (never null)
- Since:
- 0.13.0
-
supports
Returns whether this provider supports the exact model identifier.Model identifiers are case-sensitive provider contracts. Providers should return
false, rather than throw, for unknown identifiers. The answer must be local — no network call — because Role initialization checks provider support before dispatch and the runtime rechecks it on every retrieval dispatch before consulting the result cache.- Parameters:
model- model identifier from@Search.rerankerModel- Returns:
truewhen this provider can serve the model
-
rerank
Reranks retrieved candidates for the original user query.Returning an empty list for a non-empty
Reranker.Request.documents()is in contract — a provider applying a relevance threshold may legitimately reject every candidate — but the runtime logs it at WARN, because from the caller's side it is indistinguishable from a provider that dropped the candidates by accident.- Parameters:
request- immutable reranking request- Returns:
- candidates in relevance order, optionally filtered
-