Class DecisionScoringModel
java.lang.Object
dev.langchain4j.model.scoring.DecisionScoringModel
- All Implemented Interfaces:
ScoringModel
A
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()doScoreAsync(ScoringRequest request) The provider hook behindScoringModel.scoreAsync(ScoringRequest).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, 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
-
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.
-
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
-