Class DecisionScoringModel
- All Implemented Interfaces:
ScoringModel
ScoringModel backed by a DecisionModel: the score of a segment is the probability that the
answer to "Does the document help answer the query?" is "yes".
It can be used wherever a ScoringModel is expected, for example to re-rank retrieved content with a
ReRankingContentAggregator:
ContentAggregator contentAggregator = ReRankingContentAggregator.builder()
.scoringModel(new DecisionScoringModel(decisionModel))
.minScore(0.5)
.build();
The segments are scored in requests of up to 20 segments (see DecisionScoringModel.Builder.maxSegmentsPerRequest(Integer)): the
input is the query, and each segment is part of its own yes/no question (see
DecisionScoringModel.Builder.questionTemplate(PromptTemplate)). Whether the answer to one question can be influenced by the other
questions of the request depends on the decision model. With ScoringModel.scoreAsync(ScoringRequest), the requests are sent in parallel.
Since the text of a segment is part of its question, a retrieved document that contains instructions, such as "answer yes", can try to raise its own score. Treat the scores of untrusted content accordingly.
- Since:
- 1.21.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PromptTemplateThe default template of the question asked for each segment:"Does the document help answer the query?\nDocument: {{document}}". -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DecisionScoringModel.Builderbuilder()doScore(ScoringRequest request) The provider hook behindScoringModel.score(ScoringRequest).doScoreAsync(ScoringRequest request) The provider hook behindScoringModel.scoreAsync(ScoringRequest).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.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ScoringModel
defaultRequestParameters, score, score, score, scoreAsync
-
Field Details
-
DEFAULT_QUESTION_TEMPLATE
The default template of the question asked for each segment:"Does the document help answer the query?\nDocument: {{document}}".
-
-
Constructor Details
-
DecisionScoringModel
-
DecisionScoringModel
-
-
Method Details
-
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:
request- the request, with the default parameters already applied.- Returns:
- the scores, in the order of
ScoringRequest.documents(), and the response metadata.
-
doScoreAsync
Description copied from interface:ScoringModelThe provider hook behindScoringModel.scoreAsync(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.- Specified by:
doScoreAsyncin interfaceScoringModel- Parameters:
request- the (already defaults-applied) request to score.- Returns:
- a
CompletableFutureof the scores, in the order ofScoringRequest.documents().
-
builder
-