Interface ScoringModel
- All Known Implementing Classes:
CohereScoringModel, DecisionScoringModel, JinaScoringModel, OnnxScoringModel, VertexAiScoringModel, VoyageAiScoringModel, WatsonxScoringModel
Useful for identifying the most relevant texts when scoring multiple texts against the same query.
The scoring model can be employed for re-ranking purposes.
To support listeners, an implementation overrides doScore(ScoringRequest) and
implements scoreAll(List, String) by calling score(ScoringRequest). It must never make
scoreAll(List, String) call score(ScoringRequest) without overriding
doScore(ScoringRequest): the default doScore(ScoringRequest) calls
scoreAll(List, String), so each method would call the other.
-
Method Summary
Modifier and TypeMethodDescriptiondefault ScoringRequestParametersThe model's default per-call parameters, applied byscore(ScoringRequest)andscoreAsync(ScoringRequest)to every request and overridden by any parameters set on the request itself.default ScoringResponsedoScore(ScoringRequest request) The provider hook behindscore(ScoringRequest).default CompletableFuture<ScoringResponse> doScoreAsync(ScoringRequest request) The provider hook behindscoreAsync(ScoringRequest).default List<ScoringModelListener> The listeners notified before each call ofscore(ScoringRequest)andscoreAsync(ScoringRequest), after each successful call and when a call fails.default ModelProviderprovider()TheModelProviderof this scoring model (for exampleModelProvider.COHERE).score(TextSegment segment, String query) Scores a givenTextSegmentagainst a given query.default ScoringResponsescore(ScoringRequest request) Scores a given text against a given query.scoreAll(List<TextSegment> segments, String query) Scores all providedTextSegments against a given query.default CompletableFuture<ScoringResponse> scoreAsync(ScoringRequest request) Scores thedocumentsof the given request against itsquerywithout blocking the calling thread — the asynchronous/reactive counterpart ofscore(ScoringRequest), used by the non-blocking RAG flow (seeReRankingContentAggregator).
-
Method Details
-
score
-
score
Scores a givenTextSegmentagainst a given query.- Parameters:
segment- TheTextSegmentto be scored.query- The query against which to score the segment.- Returns:
- the score.
-
scoreAll
Scores all providedTextSegments against a given query.- Parameters:
segments- The list ofTextSegments to score.query- The query against which to score the segments.- Returns:
- the list of scores. The order of scores corresponds to the order of
TextSegments.
-
score
Scores thedocumentsof the given request against itsquery.This applies the model's
default parameters, notifies thelistenersand dispatches todoScore(ScoringRequest).- Parameters:
request- the documents to score, the query, and the per-call parameters.- Returns:
- the scores, in the order of
ScoringRequest.documents(), and the response metadata. - Since:
- 1.24.0
-
doScore
The provider hook behindscore(ScoringRequest).The default scores the documents with
scoreAll(List, String), so a model that implements onlyscoreAll(List, String)also supportsscore(ScoringRequest). To do so, the default turns each document into aTextSegment, and aTextSegmentcannot be blank: a model that implements onlyscoreAll(List, String)therefore cannot score blank documents throughscore(ScoringRequest), and such a request fails with anIllegalArgumentException.To support
listeners, override this method and implementscoreAll(List, String)by callingscore(ScoringRequest), so that the listeners are also notified whenscoreAll(List, String)is called. Never makescoreAll(List, String)callscore(ScoringRequest)without overriding this method: each method would call the other.- Parameters:
request- the request, with the default parameters already applied.- Returns:
- the scores, in the order of
ScoringRequest.documents(), and the response metadata. - Since:
- 1.24.0
-
scoreAsync
Scores thedocumentsof the given request against itsquerywithout blocking the calling thread — the asynchronous/reactive counterpart ofscore(ScoringRequest), used by the non-blocking RAG flow (seeReRankingContentAggregator).This applies the model's
default parameters, notifies thelistenersand dispatches todoScoreAsync(ScoringRequest); a model becomes genuinely non-blocking by overriding the latter. This method never throws: any failure, including an invalid request, completes the returned future exceptionally.When
doScoreAsync(ScoringRequest)is not implemented, the returned future fails with anAsyncNotSupportedException, and the listeners are notified of it as an error (listeners that count errors may want to leave it out). A RAG component built withoffloadBlocking(true)then runs the synchronous call (for examplescoreAll(List, String)) on another thread, which the listeners observe as a separate call; without it, the RAG call fails with anUnsupportedFeatureException. When the returned future is cancelled, the listeners are notified of neither a response nor an error.- Parameters:
request- the documents to score, the query, and the per-call parameters.- Returns:
- a
CompletableFutureof the scores, in the order ofScoringRequest.documents(). - Since:
- 1.20.0
-
doScoreAsync
The provider hook behindscoreAsync(ScoringRequest). The default returns a failed future carryingAsyncNotSupportedException: a scoring model that is not genuinely asynchronous does not pretend to be. A model backed by remote HTTP I/O opts in by overriding this with a genuinely async call (no thread parked), and should abort its in-flight call when the returned future is cancelled (best-effort). A model that has not opted in fails loudly on the async path rather than silently blocking a carrier thread.- Parameters:
request- the (already defaults-applied) request to score.- Returns:
- a
CompletableFutureof the scores, in the order ofScoringRequest.documents(). - Since:
- 1.20.0
-
defaultRequestParameters
The model's default per-call parameters, applied byscore(ScoringRequest)andscoreAsync(ScoringRequest)to every request and overridden by any parameters set on the request itself. The default isScoringRequestParameters.EMPTY.- Since:
- 1.20.0
-
listeners
The listeners notified before each call ofscore(ScoringRequest)andscoreAsync(ScoringRequest), after each successful call and when a call fails. Listeners are configured on the builder of the scoring model. Defaults to an empty list.- Since:
- 1.24.0
-
provider
TheModelProviderof this scoring model (for exampleModelProvider.COHERE). It is made available to thelisteners. Defaults toModelProvider.OTHER.- Since:
- 1.24.0
-