Class CohereScoringModel
- All Implemented Interfaces:
ScoringModel
ScoringModel that uses
Cohere Rerank API.-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuilder()The model's default per-call parameters, applied byScoringModel.score(ScoringRequest)andScoringModel.scoreAsync(ScoringRequest)to every request and overridden by any parameters set on the request itself.doScore(ScoringRequest scoringRequest) The provider hook behindScoringModel.score(ScoringRequest).doScoreAsync(ScoringRequest scoringRequest) Genuinely non-blocking counterpart ofdoScore(ScoringRequest), used by the asynchronous and reactive RAG flow.The listeners notified before each call ofScoringModel.score(ScoringRequest)andScoringModel.scoreAsync(ScoringRequest), after each successful call and when a call fails.provider()TheModelProviderof this scoring model (for exampleModelProvider.COHERE).scoreAll(List<TextSegment> segments, String query) Scores all providedTextSegments against a given query.static CohereScoringModelwithApiKey(String apiKey) Deprecated, for removal: This API element is subject to removal in a future version.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ScoringModel
score, score, score, scoreAsync
-
Constructor Details
-
CohereScoringModel
-
CohereScoringModel
-
-
Method Details
-
withApiKey
Deprecated, for removal: This API element is subject to removal in a future version.Please usebuilder()instead, and explicitly set the model name and, if necessary, other parameters. -
builder
-
defaultRequestParameters
Description copied from interface:ScoringModelThe model's default per-call parameters, applied byScoringModel.score(ScoringRequest)andScoringModel.scoreAsync(ScoringRequest)to every request and overridden by any parameters set on the request itself. The default isScoringRequestParameters.EMPTY.- Specified by:
defaultRequestParametersin interfaceScoringModel
-
listeners
Description copied from interface:ScoringModelThe listeners notified before each call ofScoringModel.score(ScoringRequest)andScoringModel.scoreAsync(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.- Specified by:
listenersin interfaceScoringModel
-
provider
Description copied from interface:ScoringModelTheModelProviderof this scoring model (for exampleModelProvider.COHERE). It is made available to thelisteners. Defaults toModelProvider.OTHER.- Specified by:
providerin interfaceScoringModel
-
scoreAll
Description copied from interface:ScoringModelScores all providedTextSegments against a given query.- Specified by:
scoreAllin interfaceScoringModel- 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.
-
doScore
Description copied from interface:ScoringModelThe provider hook behindScoringModel.score(ScoringRequest).The default scores the documents with
ScoringModel.scoreAll(List, String), so a model that implements onlyScoringModel.scoreAll(List, String)also supportsScoringModel.score(ScoringRequest). To do so, the default turns each document into aTextSegment, and aTextSegmentcannot be blank: a model that implements onlyScoringModel.scoreAll(List, String)therefore cannot score blank documents throughScoringModel.score(ScoringRequest), and such a request fails with anIllegalArgumentException.To support
listeners, override this method and implementScoringModel.scoreAll(List, String)by callingScoringModel.score(ScoringRequest), so that the listeners are also notified whenScoringModel.scoreAll(List, String)is called. Never makeScoringModel.scoreAll(List, String)callScoringModel.score(ScoringRequest)without overriding this method: each method would call the other.- Specified by:
doScorein interfaceScoringModel- Parameters:
scoringRequest- the request, with the default parameters already applied.- Returns:
- the scores, in the order of
ScoringRequest.documents(), and the response metadata.
-
doScoreAsync
Genuinely non-blocking counterpart ofdoScore(ScoringRequest), used by the asynchronous and reactive RAG flow. The underlying HTTP call is dispatched asynchronously (no thread is parked while it is in flight), and cancelling the returned future aborts the in-flight call (best-effort).Like
doScore(ScoringRequest), a failed request is retried up tomaxRetriestimes (retry-around-future, composing futures without parking a thread); a cancellation is never retried.- Specified by:
doScoreAsyncin interfaceScoringModel- Parameters:
scoringRequest- the (already defaults-applied) request to score.- Returns:
- a
CompletableFutureof the scores, in the order ofScoringRequest.documents().
-
builder()instead, and explicitly set the model name and, if necessary, other parameters.