Annotation Interface Ai.Service

Enclosing class:
Ai

@Target(TYPE) @Retention(RUNTIME) public static @interface Ai.Service
Annotation to define a langChain4J service. A langChain4J service aggregates various components that support functionalities like chat, memory management, moderation, content retrieval, and tool-based augmentations.

The primary components include:

  • dev.langchain4j.model.chat.ChatLanguageModel or dev.langchain4j.model.chat.StreamingChatLanguageModel - Models that handle chat-based language interactions.
  • dev.langchain4j.memory.ChatMemory or dev.langchain4j.memory.chat.ChatMemoryProvider - Components for storing and managing chat memory.
  • dev.langchain4j.model.moderation.ModerationModel - Model for moderating chat content.
  • dev.langchain4j.rag.content.retriever.ContentRetriever - Retrieves relevant content to support responses .
  • dev.langchain4j.rag.RetrievalAugmentor - Enhances retrieval processes with additional context.
  • Service methods annotated with dev.langchain4j.agent.tool.Tool - Tool methods that further extend service capabilities.

If the autoDiscovery parameter is set to true (the default value), components are automatically added from the CDI registry. Components explicitly specified using corresponding annotations are prioritized over automatically discovered ones.

If autoDiscovery is set to false, only components explicitly specified using annotations are included in the service, allowing manual control over the service composition.

At a minimum, either a dev.langchain4j.model.chat.ChatLanguageModel or dev.langchain4j.model.chat.StreamingChatLanguageModel is required for the service to function effectively.

  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Specifies whether to use auto-discovery mode to locate service components or to rely on manual component specification.
  • Element Details

    • autoDiscovery

      boolean autoDiscovery
      Specifies whether to use auto-discovery mode to locate service components or to rely on manual component specification.
      Returns:
      true if auto-discovery is enabled, false if manual discovery mode is used.
      Default:
      true