Class OnnxScoringModel
- All Implemented Interfaces:
ScoringModel, AutoCloseable
Many models (e.g., from HuggingFace) can be used, as long as they are in the ONNX format.
Load only model files you trust. ONNX runtime parses the model file with native code, and a crafted model file can exploit flaws in the runtime, for example to read other files on your machine or to crash the JVM.
-
Constructor Summary
ConstructorsConstructorDescriptionOnnxScoringModel(String pathToModel, ai.onnxruntime.OrtSession.SessionOptions options, String pathToTokenizer) OnnxScoringModel(String pathToModel, ai.onnxruntime.OrtSession.SessionOptions options, String pathToTokenizer, int modelMaxLength, boolean normalize) OnnxScoringModel(String pathToModel, String pathToTokenizer) OnnxScoringModel(String pathToModel, String pathToTokenizer, int modelMaxLength) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()doScore(ScoringRequest request) The provider hook behindScoringModel.score(ScoringRequest).protected dev.langchain4j.model.scoring.onnx.OnnxScoringBertCrossEncodermodel()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, doScoreAsync, listeners, provider, score, score, score, scoreAsync
-
Constructor Details
-
OnnxScoringModel
-
OnnxScoringModel
-
OnnxScoringModel
-
OnnxScoringModel
-
-
Method Details
-
model
protected dev.langchain4j.model.scoring.onnx.OnnxScoringBertCrossEncoder model() -
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.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-