Class EmbeddingModelListenerUtils
java.lang.Object
dev.langchain4j.model.embedding.EmbeddingModelListenerUtils
-
Method Summary
Modifier and TypeMethodDescriptionwithListeners(EmbeddingModel model, TextSegment textSegment, Supplier<Response<Embedding>> operation) Single-embedding overload ofwithListeners(EmbeddingModel, List, Supplier), for providers that overrideEmbeddingModel.embed(TextSegment)with a dedicated API call.withListeners(EmbeddingModel model, List<TextSegment> textSegments, Supplier<Response<List<Embedding>>> operation) Notifies the model'slistenersaround a raw batch embeddingoperationthat does not itself route throughEmbeddingModel.embed(EmbeddingRequest).
-
Method Details
-
withListeners
public static Response<List<Embedding>> withListeners(EmbeddingModel model, List<TextSegment> textSegments, Supplier<Response<List<Embedding>>> operation) Notifies the model'slistenersaround a raw batch embeddingoperationthat does not itself route throughEmbeddingModel.embed(EmbeddingRequest).A provider that overrides
EmbeddingModel.embedAll(List)to apply batch-specific behavior the request/response API does not carry (for example a document title fromTextSegmentmetadata) can wrap the actual API call with this method so that listeners are still notified consistently. Callers must ensure the wrappedoperationdoes not itself dispatch listeners, otherwise listeners are notified twice.- Parameters:
model- the embedding model whose listeners are notified.textSegments- the segments being embedded.operation- the raw embedding call.- Returns:
- the result of
operation.
-
withListeners
public static Response<Embedding> withListeners(EmbeddingModel model, TextSegment textSegment, Supplier<Response<Embedding>> operation) Single-embedding overload ofwithListeners(EmbeddingModel, List, Supplier), for providers that overrideEmbeddingModel.embed(TextSegment)with a dedicated API call.- Parameters:
model- the embedding model whose listeners are notified.textSegment- the segment being embedded.operation- the raw embedding call.- Returns:
- the result of
operation.
-