Class RetrievalUtils

java.lang.Object
io.micronaut.langchain4j.utils.RetrievalUtils

@Internal public final class RetrievalUtils extends Object
Resolves the retrieval augmented generation (RAG) configuration of an AI or agentic service.

Retrieval is explicit: it is configured only when the application declares a RetrievalAugmentor bean or a ContentRetriever bean. A RetrievalAugmentor takes precedence over a ContentRetriever. For either type, a bean named after the service is preferred over the default bean.

  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    configureRetrieval(@NonNull io.micronaut.context.BeanContext beanContext, @Nullable String name, @NonNull Consumer<dev.langchain4j.rag.RetrievalAugmentor> augmentorConfigurer, @NonNull Consumer<dev.langchain4j.rag.content.retriever.ContentRetriever> retrieverConfigurer)
    Configures retrieval for a service.
    static <T> T
    findByNameOrDefault(@NonNull io.micronaut.context.BeanContext beanContext, @Nullable String name, @NonNull io.micronaut.core.type.Argument<T> beanType)
    Finds a bean qualified by the given name, falling back to the default bean.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • configureRetrieval

      public static void configureRetrieval(@NonNull @NonNull io.micronaut.context.BeanContext beanContext, @Nullable @Nullable String name, @NonNull @NonNull Consumer<dev.langchain4j.rag.RetrievalAugmentor> augmentorConfigurer, @NonNull @NonNull Consumer<dev.langchain4j.rag.content.retriever.ContentRetriever> retrieverConfigurer)
      Configures retrieval for a service. At most one of the two configurers is invoked.
      Parameters:
      beanContext - The bean context
      name - The service name used as a qualifier, may be null
      augmentorConfigurer - Invoked with the RetrievalAugmentor bean if one resolves
      retrieverConfigurer - Invoked with the ContentRetriever bean if one resolves and no augmentor does
    • findByNameOrDefault

      @Nullable public static <T> T findByNameOrDefault(@NonNull @NonNull io.micronaut.context.BeanContext beanContext, @Nullable @Nullable String name, @NonNull @NonNull io.micronaut.core.type.Argument<T> beanType)
      Finds a bean qualified by the given name, falling back to the default bean.
      Type Parameters:
      T - The bean type
      Parameters:
      beanContext - The bean context
      name - The bean name, may be null
      beanType - The bean type
      Returns:
      The bean, or null if none exists or the default lookup is ambiguous