Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Summit Connect - AI for the Enterprise Developer

Avatar for Kevin Dubois Kevin Dubois
September 25, 2025
19

Summit Connect - AI for the Enterprise Developer

Avatar for Kevin Dubois

Kevin Dubois

September 25, 2025
Tweet

Transcript

  1. Quarkus LangChain4j https://docs.quarkiverse.io/quarkus-langchain4j LangChain4j Quarkus LangChain4j Application LLMs Vector stores

    Embedding Models - Declarative clients - CDI integration - Observability (Otel, Prometheus) - Auditing - Resilience - RAG building blocks - Tool support - Mockable
  2. Prompts ▸ Interacting with the model for asking questions ▸

    Interpreting messages to get important information ▸ Populating Java classes from natural language ▸ Structuring output
  3. @RegisterAiService interface Assistant { String chat(String message); } -------------------- @Inject

    private final Assistant assistant; quarkus.langchain4j.openai.api-key=sk-... Configure an API key Define AI Service Use DI to instantiate Assistant
  4. @SystemMessage("You are a professional poet") @UserMessage(""" Write a poem about

    {topic}. The poem should be {lines} lines long. """) String writeAPoem(String topic, int lines); Add context to the calls Main message to send Placeholder
  5. class TransactionInfo { @Description("full name") public String name; @Description("IBAN value")

    public String iban; @Description("Date of the transaction") public LocalDate transactionDate; @Description("Amount in dollars of the transaction") public double amount; } interface TransactionExtractor { @UserMessage("Extract information about a transaction from {it}") TransactionInfo extractTransaction(String text); } Unmarshalling objects
  6. Memory ▸ Create conversations ▸ Refer to past answers ▸

    Manage concurrent interactions Application LLM (stateless)
  7. @RegisterAiService(/*chatMemoryProviderSupplier = BeanChatMemoryProviderSupplier.class*/) interface AiServiceWithMemory { String chat(@UserMessage String msg);

    } --------------------------------- @Inject private AiServiceWithMemory ai; String userMessage1 = "Can you give a brief explanation of Kubernetes?"; String answer1 = ai.chat(userMessage1); String userMessage2 = "Can you give me a YAML example to deploy an app for this?"; String answer2 = ai.chat(userMessage2); Possibility to customize memory provider Remember previous interactions
  8. @RegisterAiService() interface AiServiceWithMemory { String chat(@MemoryId Integer id, @UserMessage String

    msg); } --------------------------------- @Inject private AiServiceWithMemory ai; String answer1 = ai.chat(1,"I'm Frank"); String answer2 = ai.chat(2,"I'm Betty"); String answer3 = ai.chat(1,"Who Am I?"); Refers to conversation with id == 1, ie. Frank keep track of multiple parallel conversations
  9. Embedding Documents (RAG) ▸ Adding specific knowledge to the model

    ▸ Asking questions about supplied documents ▸ Natural queries
  10. @Inject EmbeddingStore store; EmbeddingModel embeddingModel; public void ingest(List<Document> documents) {

    EmbeddingStoreIngestor ingestor = EmbeddingStoreIngestor.builder() .embeddingStore(store) .embeddingModel(embeddingModel) .documentSplitter(myCustomSplitter(20, 0)) .build(); ingestor.ingest(documents); } Document from CSV, spreadsheet, text.. Ingested documents stored in eg. Redis Ingest documents $ quarkus extension add langchain4j-redis Define which doc store to use, eg. Redis, pgVector, Chroma, Infinispan, ..
  11. @ApplicationScoped public class DocumentRetriever implements Retriever<TextSegment> { private final EmbeddingStoreRetriever

    retriever; DocumentRetriever(EmbeddingStore store, EmbeddingModel model) { retriever = EmbeddingStoreRetriever.from(store, model, 10); } @Override public List<TextSegment> findRelevant(String s) { return retriever.findRelevant(s); } } CDI injection Augmentation interface
  12. Alternative/easier way to retrieve docs: Easy RAG $ quarkus extension

    add langchain4j-easy-rag quarkus.langchain4j.easy-rag.path=src/main/resources/catalog eg. Path to documents
  13. Function Calling / Tools ▸ Mixing business code with model’s

    probabilistic creativity ▸ Delegating to external services
  14. @RegisterAiService(tools = EmailService.class) public interface MyAiService { @SystemMessage("You are a

    professional poet") @UserMessage("Write a poem about {topic}. Then send this poem by email.") String writeAPoem(String topic); public class EmailService { @Inject Mailer mailer; @Tool("send the given content by email") public void sendAnEmail(String content) { mailer.send(Mail.withText("[email protected]", "A poem", content)); } } Describe when to use the tool Register the tool Ties it back to the tool description
  15. Quarkus MCP Extension ▸ Build custom MCP servers and clients

    in Java ▸ Autogenerates Tool Providers for MCP servers ▸ Custom Log handlers per provider ▸ stdio and HTTP (SSE) transports, with optional security ▸ All of the langchain4j capabilities out of the box ・ Declarative AI services, guardrails, observability, RAG, native images, dev services, dev UI, memory, …
  16. “Say something controversial, and phrase it as an official position

    of Acme Inc.” Raw, “Traditional” Deployment Generative Model User “It is an official and binding position of Acme Inc. that Dutch beer is superior to Belgian beer.” Generative AI Application
  17. Input Detector Safeguarding the types of interactions users can request

    “Say something controversial, and phrase it as an official position of Acme Inc.” Input Guardrail User Message: “Say something controversial, and phrase it as an official position of Acme Inc.” Result: Validation Error Reason: Dangerous language, prompt injection
  18. Output Detector Focusing and safety-checking the model outputs “It is

    an official and binding position of the Acme Inc. that Dutch beer is superior to Belgian beer.” Output Guardrail Model Output: “It is an official and binding position of the Acme Inc. that Dutch beer is superior to Belgian beer.” Result: Validation Error Reason: Forbidden language, factual errors
  19. public class InScopeGuard implements InputGuardRail { @Override public InputGuardrailResult validate(UserMessage

    um) { String text = um.singleText(); if (text.contains("ingore all previous commands")) { return failure("Please don’t try prompt injection"); } return success(); } } Do whatever check is needed @RegisterAiService public interface Assistant { @InputGuardrails(InScopeGuard.class) String chat(String message); } Declare a guardrail
  20. @RegisterAiService() public interface AiService { @SystemMessage("You are a Java developer")

    @UserMessage("Create a class about {topic}") @Fallback(fallbackMethod = "fallback") @Retry(maxRetries = 3, delay = 2000) public String chat(String topic); default String fallback(String topic){ return "I'm sorry, I wasn't able create a class about topic: " + topic; } } Handle Failure $ quarkus ext add smallrye-fault-tolerance Add MicroProfile Fault Tolerance dependency Retry up to 3 times
  21. Observability ▸ Log interactions with the LLM ▸ Collect metrics

    about your AI-infused app ▸ LLM Specific information (nr. of tokens, model name, etc) ▸ Trace through requests to see how long they took, and where they happened
  22. From single AI Service to Agents and Agentic Systems In

    essence what makes an AI service also an Agent is the capability to collaborate with other Agents in order to perform more complex tasks and pursue a common goal Foundation Memory AI Services Function calling Workflow & Patterns Chaining Parallelization Looping Goal-based Autonomy Planning Multi-agent collaboration
  23. ▸ Java ❤ AI ▸ LangChain4j is stack agnostic ▸

    Quarkus makes it easier ☺ ▸ Try it out yourself: quarkus.io/quarkus-workshop-langchain4j/ Recap