LlmReranker class final
Scores candidates by having a model read them against the question.
Why this beats similarity
An embedding measures whether two texts are about the same thing. A model reading both can tell whether one answers the other — a distinction similarity cannot make. A passage titled "Refund policy" that explains why refunds are unavailable in your region is highly similar to "how do I get a refund" and does not answer it.
What it costs
One model call per re-ranking, carrying every candidate. That is real money
and real latency, which is why it belongs after a cheap filter and in
front of a small candidate list — ChainedReranker([ScoreFloorReranker(), LlmReranker(...)]) is the shape that makes sense.
Failure is not fatal
If the model fails, times out or answers in a shape that cannot be read, the retriever's own ordering is returned instead. Re-ranking is an improvement, not a prerequisite: turning a good answer into an error because the optional refinement step failed is the wrong trade, and the caller finds out through the log and lastFailure rather than through an exception.
final reranker = LlmReranker(model: model);
final best = await reranker.rerank(question, candidates, topK: 4);
- Implemented types
Constructors
- LlmReranker({required ChatModel model, String name = 'llm', int maxCandidateChars = 600, String? instructions})
- Creates a model-backed re-ranker.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- instructions → String?
-
Extra guidance appended to the system prompt.
final
- lastFailure → AgenticException?
-
Why the last re-ranking fell back, or
nullif it did not.no setter - maxCandidateChars → int
-
How much of each candidate the model is shown.
final
- model → ChatModel
-
The model that does the judging.
final
- name → String
-
A short name, used in events and traces.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
rerank(
String query, List< RetrievedChunk> results, {int topK = 4, AgenticContext? context}) → Future<List< RetrievedChunk> > -
Reorders
resultsforquery, keeping at mosttopK.override -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited