Class ProviderSelector

java.lang.Object
org.episteme.core.technical.algorithm.ProviderSelector

public final class ProviderSelector extends Object
Context-aware provider selector.

Unlike AlgorithmManager.getProvider(Class) which uses static priority, ProviderSelector uses AlgorithmProvider.score(OperationContext) to pick the best provider for a specific operation.

OperationContext ctx = new OperationContext.Builder()
    .dataSize(1_000_000)
    .addHint(OperationContext.Hint.SPARSE)
    .build();

LinearAlgebraProvider best = ProviderSelector.select(
    LinearAlgebraProvider.class, ctx);
Since:
1.2
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Method Details

    • select

      public static <P extends AlgorithmProvider> P select(Class<P> providerClass, OperationContext context)
      Selects the best provider for the given operation context.

      Scores all available providers via AlgorithmProvider.score(OperationContext) and returns the one with the highest score.

      Type Parameters:
      P - the provider type
      Parameters:
      providerClass - the interface class of the provider
      context - the operation context describing data characteristics
      Returns:
      the best-scoring available provider
      Throws:
      NoSuchElementException - if no provider is available
    • select

      public static <P extends AlgorithmProvider> P select(Class<P> providerClass, OperationContext context, Predicate<P> filter)
      Selects the best provider for the given operation context, with an optional filter.
    • execute

      public static <P extends AlgorithmProvider, R> R execute(Class<P> providerClass, OperationContext context, Function<P,R> operation)
      Executes an operation using the best available provider, with automatic fallback.

      Iterates through all available providers (sorted by score) and attempts the operation. If a provider fails, it logs the warning and tries the next best provider.

      Type Parameters:
      P - the provider type
      R - the return type
      Parameters:
      providerClass - the interface class of the provider
      context - the operation context
      operation - the operation to execute
      Returns:
      the result of the operation
      Throws:
      RuntimeException - if all providers fail
    • select

      public static <P extends AlgorithmProvider> P select(Class<P> providerClass)
      Selects using static priority (delegates to AlgorithmManager).

      Convenience method for when no operation context is available.