Interface EmbeddingModelListener


@Experimental public interface EmbeddingModelListener
An EmbeddingModel listener that listens for requests, responses and errors.

Threading — these callbacks must not block. They are always invoked synchronously, on the model's own threads: on the synchronous API (embed) the caller's thread; on the asynchronous API (embedAsync), onRequest(EmbeddingModelRequestContext) runs on the thread that starts the call and onResponse(EmbeddingModelResponseContext)/onError(EmbeddingModelErrorContext) on the transport's I/O worker thread that reads the response (for HTTP models, the JDK HTTP client's HttpClient-* workers). Blocking in a callback — a synchronous database write, a synchronous HTTP call to an observability backend, synchronous file logging — stalls that worker and, under concurrency, degrades throughput for all in-flight calls. Keep these methods non-blocking; if a callback must perform blocking I/O, offload it to your own executor.

Since:
1.11.0
  • Method Details

    • onRequest

      default void onRequest(EmbeddingModelRequestContext requestContext)
      This method is called before the request is executed against the embedding model.
      Parameters:
      requestContext - The request context. It contains the input and attributes. The attributes can be used to pass data between methods of this listener or between multiple listeners.
    • onResponse

      default void onResponse(EmbeddingModelResponseContext responseContext)
      This method is called after a successful embedding operation completes.
      Parameters:
      responseContext - The response context. It contains the response, corresponding request and attributes. The attributes can be used to pass data between methods of this listener or between multiple listeners.
    • onError

      default void onError(EmbeddingModelErrorContext errorContext)
      This method is called when an error occurs during interaction with the embedding model.
      Parameters:
      errorContext - The error context. It contains the error, corresponding request and attributes. The attributes can be used to pass data between methods of this listener or between multiple listeners.