Skip to content

Commit 36fc832

Browse files
authored
Merge pull request #4 from j-AIWG/add-langchain4j-articles
add articles on langchain4j
2 parents 46c0d65 + af7d3c9 commit 36fc832

15 files changed

Lines changed: 922 additions & 103 deletions

File tree

educational-resource/docs/10-genai/30-using-llms-in-code/30-frameworks/10-langchain4j/20-langchain4j-deepdive-with-code.md

Lines changed: 765 additions & 0 deletions
Large diffs are not rendered by default.

educational-resource/docs/10-genai/30-using-llms-in-code/30-frameworks/10-langchain4j/index.md

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sidebar_position: 10
44
hide_title: true
55

66
level: beginner
7-
status: missing
7+
status: published
88
visibility: public
99

1010
# OPTIONAL TAGS:
@@ -15,10 +15,59 @@ visibility: public
1515
programming-language: "Java" # or others
1616
---
1717

18-
:::note ⚠️ This article is still missing
19-
This content has not been written yet. Help us create it!
20-
:::
18+
# LangChain4j
2119

22-
# Frameworks
20+
LangChain4j is one of the two popular Java libraries for easy interaction with LLMs.
2321

24-
Help us write this landing page
22+
<img src="/java-ai-resource/img/10-genai/30-using-llms-in-code/30-frameworks/langchain4j_logo.png" alt="LangChain4j Logo" style={{width: '30%', display: 'block', margin: 'auto'}} />
23+
24+
<br />
25+
26+
Calling a model is as simple as:
27+
28+
```java
29+
ChatLanguageModel model = OpenAiChatModel.builder()
30+
.apiKey("your key")
31+
.modelName("gpt-4o-mini")
32+
.build();
33+
34+
String answer = model.generate("Hello, how are you?");
35+
System.out.println(answer);
36+
```
37+
38+
And creating an app where the LLM generates Java objects (output parsing), can call tools, has a memory and access to extra context (RAG) would be as simple as:
39+
40+
```java
41+
interface CustomerAssistant {
42+
@SystemMessage("You are a helpful customer service assistant")
43+
@UserMessage("You create a stepwise plan for the user that submitted: {{message}}")
44+
List<String> assist(@MemoryId String customerId, String message);
45+
}
46+
47+
CustomerAssistant assistant = AiServices.builder(CustomerAssistant.class)
48+
.chatLanguageModel(model)
49+
.chatMemory(MessageWindowChatMemory.withMaxMessages(10))
50+
.retrievalAugmentor(DefaultRetrievalAugmentor.builder()
51+
.contentRetriever(serviceTermsEmbeddingStoreRetriever)
52+
.build())
53+
.tools(new BookingManagementTools())
54+
.build();
55+
```
56+
57+
LangChain4j is framework-agnostic: it works standalone (vanilla) and has strong integrations with **Quarkus**, **Spring Boot**, and integrations with **Micronaut** for example.
58+
59+
You can watch an engaging overview of most features in our [LangChain4j overview video](https://www.youtube.com/watch?v=BD1MSLbs9KE).
60+
61+
Read through our [deep dive article](./20-langchain4j-deepdive-with-code.md) to see code examples of these and more advanced features.
62+
63+
Or get your hands dirty and go through our comprehensive, self-explanatory [code tutorial repository](https://github.com/langchain4j/langchain4j-examples/tree/main/tutorials), which includes special folders for [Spring Boot examples](https://github.com/langchain4j/langchain4j-examples/tree/main/spring-boot-example) and [RAG examples](https://github.com/langchain4j/langchain4j-examples/tree/main/rag-examples).
64+
65+
For supported model providers, check out our [model integrations documentation](https://docs.langchain4j.dev/integrations/language-models/), which covers all popular commercial providers like OpenAI's GPT models, Google's Gemini, Anthropic's Claude, etc., as well as local models via Ollama, JLama, and others.
66+
67+
For embedding store integrations, see our [embedding store documentation](https://docs.langchain4j.dev/integrations/embedding-stores/).
68+
69+
You'll find ample examples of how to use each of these features in our [main examples repository](https://github.com/langchain4j/langchain4j-examples).
70+
71+
---
72+
73+
*Written by Lize Raes*

educational-resource/docs/full-sitemap.md

Lines changed: 102 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ n_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j["LangChain4j ☕
8888
n_10_genai_30_using_llms_in_code_30_frameworks --> n_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j
8989
n_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j_10_langchain4j_doc_md["🔗 Langchain4j Documentation ☕️"]
9090
n_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j --> n_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j_10_langchain4j_doc_md
91+
n_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j_20_langchain4j_deepdive_with_code_md["Langchain4j Deep Dive with Code ☕️"]
92+
n_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j --> n_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j_20_langchain4j_deepdive_with_code_md
9193
n_10_genai_40_inference["Inference"]
9294
n_10_genai --> n_10_genai_40_inference
9395
n_10_genai_40_inference_10_local_md["Local"]
@@ -262,6 +264,7 @@ click n_10_genai_30_using_llms_in_code_30_frameworks "/java-ai-resource/docs/gen
262264
click n_10_genai_30_using_llms_in_code_30_frameworks_20_springai_md "/java-ai-resource/docs/genai/using-llms-in-code/frameworks/springai"
263265
click n_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j "/java-ai-resource/docs/genai/using-llms-in-code/frameworks/langchain4j"
264266
click n_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j_10_langchain4j_doc_md "/java-ai-resource/docs/genai/using-llms-in-code/frameworks/langchain4j/langchain4j-doc"
267+
click n_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j_20_langchain4j_deepdive_with_code_md "/java-ai-resource/docs/genai/using-llms-in-code/frameworks/langchain4j/langchain4j-deepdive-with-code"
265268
click n_10_genai_40_inference "/java-ai-resource/docs/genai/inference"
266269
click n_10_genai_40_inference_10_local_md "/java-ai-resource/docs/genai/inference/local"
267270
click n_10_genai_40_inference_20_cloud_md "/java-ai-resource/docs/genai/inference/cloud"
@@ -415,146 +418,148 @@ classDef custom35 fill:#fff2e6;
415418
class n_10_genai_30_using_llms_in_code_30_frameworks custom35;
416419
classDef custom36 fill:#e6ffe6;
417420
class n_10_genai_30_using_llms_in_code_30_frameworks_20_springai_md custom36;
418-
classDef custom37 fill:#e6ffe6;
421+
classDef custom37 fill:#d0f0c0,stroke:green,stroke-width:4px,stroke-dasharray:0;
419422
class n_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j custom37;
420423
classDef custom38 fill:#b3d9ff,stroke:green,stroke-width:4px,stroke-dasharray:0;
421424
class n_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j_10_langchain4j_doc_md custom38;
422-
classDef custom39 fill:#ffe6e6;
423-
class n_10_genai_40_inference custom39;
424-
classDef custom40 fill:#fff2e6;
425-
class n_10_genai_40_inference_10_local_md custom40;
425+
classDef custom39 fill:#b3d9ff,stroke:yellow,stroke-width:4px,stroke-dasharray:0;
426+
class n_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j_20_langchain4j_deepdive_with_code_md custom39;
427+
classDef custom40 fill:#ffe6e6;
428+
class n_10_genai_40_inference custom40;
426429
classDef custom41 fill:#fff2e6;
427-
class n_10_genai_40_inference_20_cloud_md custom41;
428-
classDef custom42 fill:#f0e6ff;
429-
class n_20_ml custom42;
430-
classDef custom43 fill:#ffe6e6;
431-
class n_20_ml_10_fundamentals_md custom43;
430+
class n_10_genai_40_inference_10_local_md custom41;
431+
classDef custom42 fill:#fff2e6;
432+
class n_10_genai_40_inference_20_cloud_md custom42;
433+
classDef custom43 fill:#f0e6ff;
434+
class n_20_ml custom43;
432435
classDef custom44 fill:#ffe6e6;
433-
class n_20_ml_50_gpu_md custom44;
434-
classDef custom45 fill:#ffcccc,stroke:green,stroke-width:4px,stroke-dasharray:0;
435-
class n_20_ml_20_architectures custom45;
436-
classDef custom46 fill:#fff2e6;
437-
class n_20_ml_20_architectures_10_supervised_learning_md custom46;
436+
class n_20_ml_10_fundamentals_md custom44;
437+
classDef custom45 fill:#ffe6e6;
438+
class n_20_ml_50_gpu_md custom45;
439+
classDef custom46 fill:#ffcccc,stroke:green,stroke-width:4px,stroke-dasharray:0;
440+
class n_20_ml_20_architectures custom46;
438441
classDef custom47 fill:#fff2e6;
439-
class n_20_ml_20_architectures_20_unsupervised_learning_md custom47;
442+
class n_20_ml_20_architectures_10_supervised_learning_md custom47;
440443
classDef custom48 fill:#fff2e6;
441-
class n_20_ml_20_architectures_30_reinforcement_learning_md custom48;
444+
class n_20_ml_20_architectures_20_unsupervised_learning_md custom48;
442445
classDef custom49 fill:#fff2e6;
443-
class n_20_ml_20_architectures_40_generative_models_md custom49;
446+
class n_20_ml_20_architectures_30_reinforcement_learning_md custom49;
444447
classDef custom50 fill:#fff2e6;
445-
class n_20_ml_20_architectures_50_foundation_transformer_md custom50;
446-
classDef custom51 fill:#ffe6e6;
447-
class n_20_ml_30_training custom51;
448-
classDef custom52 fill:#fff2e6;
449-
class n_20_ml_30_training_10_basics_md custom52;
448+
class n_20_ml_20_architectures_40_generative_models_md custom50;
449+
classDef custom51 fill:#fff2e6;
450+
class n_20_ml_20_architectures_50_foundation_transformer_md custom51;
451+
classDef custom52 fill:#ffe6e6;
452+
class n_20_ml_30_training custom52;
450453
classDef custom53 fill:#fff2e6;
451-
class n_20_ml_30_training_20_data_prep_md custom53;
454+
class n_20_ml_30_training_10_basics_md custom53;
452455
classDef custom54 fill:#fff2e6;
453-
class n_20_ml_30_training_30_finetuning_md custom54;
456+
class n_20_ml_30_training_20_data_prep_md custom54;
454457
classDef custom55 fill:#fff2e6;
455-
class n_20_ml_30_training_40_evaluation_md custom55;
456-
classDef custom56 fill:#ffe6e6;
457-
class n_20_ml_40_frameworks custom56;
458-
classDef custom57 fill:#fff2e6;
459-
class n_20_ml_40_frameworks_10_deepnetts_md custom57;
458+
class n_20_ml_30_training_30_finetuning_md custom55;
459+
classDef custom56 fill:#fff2e6;
460+
class n_20_ml_30_training_40_evaluation_md custom56;
461+
classDef custom57 fill:#ffe6e6;
462+
class n_20_ml_40_frameworks custom57;
460463
classDef custom58 fill:#fff2e6;
461-
class n_20_ml_40_frameworks_20_deeplearning4j_md custom58;
464+
class n_20_ml_40_frameworks_10_deepnetts_md custom58;
462465
classDef custom59 fill:#fff2e6;
463-
class n_20_ml_40_frameworks_30_djl_md custom59;
466+
class n_20_ml_40_frameworks_20_deeplearning4j_md custom59;
464467
classDef custom60 fill:#fff2e6;
465-
class n_20_ml_40_frameworks_40_project_babylon_md custom60;
466-
classDef custom61 fill:#f0e6ff;
467-
class n_30_agentic_ai custom61;
468-
classDef custom62 fill:#ffe6e6;
469-
class n_30_agentic_ai_10_patterns_md custom62;
468+
class n_20_ml_40_frameworks_30_djl_md custom60;
469+
classDef custom61 fill:#fff2e6;
470+
class n_20_ml_40_frameworks_40_project_babylon_md custom61;
471+
classDef custom62 fill:#f0e6ff;
472+
class n_30_agentic_ai custom62;
470473
classDef custom63 fill:#ffe6e6;
471-
class n_30_agentic_ai_30_applications_md custom63;
474+
class n_30_agentic_ai_10_patterns_md custom63;
472475
classDef custom64 fill:#ffe6e6;
473-
class n_30_agentic_ai_20_frameworks custom64;
474-
classDef custom65 fill:#fff2e6;
475-
class n_30_agentic_ai_20_frameworks_10_adk_md custom65;
476+
class n_30_agentic_ai_30_applications_md custom64;
477+
classDef custom65 fill:#ffe6e6;
478+
class n_30_agentic_ai_20_frameworks custom65;
476479
classDef custom66 fill:#fff2e6;
477-
class n_30_agentic_ai_20_frameworks_20_langgraph4j_md custom66;
480+
class n_30_agentic_ai_20_frameworks_10_adk_md custom66;
478481
classDef custom67 fill:#fff2e6;
479-
class n_30_agentic_ai_20_frameworks_30_jai_workflow_md custom67;
482+
class n_30_agentic_ai_20_frameworks_20_langgraph4j_md custom67;
480483
classDef custom68 fill:#fff2e6;
481-
class n_30_agentic_ai_20_frameworks_40_a2a_protocol_md custom68;
482-
classDef custom69 fill:#f0e6ff;
483-
class n_40_ai_assisted_coding custom69;
484-
classDef custom70 fill:#ffe6e6;
485-
class n_40_ai_assisted_coding_10_coding_tools custom70;
486-
classDef custom71 fill:#fff2e6;
487-
class n_40_ai_assisted_coding_10_coding_tools_10_cursor_md custom71;
484+
class n_30_agentic_ai_20_frameworks_30_jai_workflow_md custom68;
485+
classDef custom69 fill:#fff2e6;
486+
class n_30_agentic_ai_20_frameworks_40_a2a_protocol_md custom69;
487+
classDef custom70 fill:#f0e6ff;
488+
class n_40_ai_assisted_coding custom70;
489+
classDef custom71 fill:#ffe6e6;
490+
class n_40_ai_assisted_coding_10_coding_tools custom71;
488491
classDef custom72 fill:#fff2e6;
489-
class n_40_ai_assisted_coding_10_coding_tools_20_windsurf_md custom72;
492+
class n_40_ai_assisted_coding_10_coding_tools_10_cursor_md custom72;
490493
classDef custom73 fill:#fff2e6;
491-
class n_40_ai_assisted_coding_10_coding_tools_30_qodo_md custom73;
492-
classDef custom74 fill:#ffe6e6;
493-
class n_40_ai_assisted_coding_20_productivity custom74;
494-
classDef custom75 fill:#fff2e6;
495-
class n_40_ai_assisted_coding_20_productivity_10_naboo_md custom75;
496-
classDef custom76 fill:#f0e6ff;
497-
class n_50_ethics custom76;
498-
classDef custom77 fill:#ffe6e6;
499-
class n_50_ethics_10_ethical_ai custom77;
494+
class n_40_ai_assisted_coding_10_coding_tools_20_windsurf_md custom73;
495+
classDef custom74 fill:#fff2e6;
496+
class n_40_ai_assisted_coding_10_coding_tools_30_qodo_md custom74;
497+
classDef custom75 fill:#ffe6e6;
498+
class n_40_ai_assisted_coding_20_productivity custom75;
499+
classDef custom76 fill:#fff2e6;
500+
class n_40_ai_assisted_coding_20_productivity_10_naboo_md custom76;
501+
classDef custom77 fill:#f0e6ff;
502+
class n_50_ethics custom77;
500503
classDef custom78 fill:#ffe6e6;
501-
class n_50_ethics_20_legislation custom78;
504+
class n_50_ethics_10_ethical_ai custom78;
502505
classDef custom79 fill:#ffe6e6;
503-
class n_50_ethics_30_security custom79;
504-
classDef custom80 fill:#f0e6ff;
505-
class n_60_domain_use_cases custom80;
506-
classDef custom81 fill:#ffe6e6;
507-
class n_60_domain_use_cases_10_finance_md custom81;
506+
class n_50_ethics_20_legislation custom79;
507+
classDef custom80 fill:#ffe6e6;
508+
class n_50_ethics_30_security custom80;
509+
classDef custom81 fill:#f0e6ff;
510+
class n_60_domain_use_cases custom81;
508511
classDef custom82 fill:#ffe6e6;
509-
class n_60_domain_use_cases_20_healthcare_md custom82;
512+
class n_60_domain_use_cases_10_finance_md custom82;
510513
classDef custom83 fill:#ffe6e6;
511-
class n_60_domain_use_cases_30_accessibility_md custom83;
514+
class n_60_domain_use_cases_20_healthcare_md custom83;
512515
classDef custom84 fill:#ffe6e6;
513-
class n_60_domain_use_cases_40_scientific_research_md custom84;
516+
class n_60_domain_use_cases_30_accessibility_md custom84;
514517
classDef custom85 fill:#ffe6e6;
515-
class n_60_domain_use_cases_50_education_md custom85;
518+
class n_60_domain_use_cases_40_scientific_research_md custom85;
516519
classDef custom86 fill:#ffe6e6;
517-
class n_60_domain_use_cases_60_ecommerce_md custom86;
520+
class n_60_domain_use_cases_50_education_md custom86;
518521
classDef custom87 fill:#ffe6e6;
519-
class n_60_domain_use_cases_70_legal_md custom87;
520-
classDef custom88 fill:#f0e6ff;
521-
class n_70_learning_paths custom88;
522-
classDef custom89 fill:#ffcccc,stroke:green,stroke-width:4px,stroke-dasharray:0;
523-
class n_70_learning_paths_10_new_to_java_for_ai custom89;
524-
classDef custom90 fill:#fff2e6;
525-
class n_70_learning_paths_10_new_to_java_for_ai_10_welcome_md custom90;
522+
class n_60_domain_use_cases_60_ecommerce_md custom87;
523+
classDef custom88 fill:#ffe6e6;
524+
class n_60_domain_use_cases_70_legal_md custom88;
525+
classDef custom89 fill:#f0e6ff;
526+
class n_70_learning_paths custom89;
527+
classDef custom90 fill:#ffcccc,stroke:green,stroke-width:4px,stroke-dasharray:0;
528+
class n_70_learning_paths_10_new_to_java_for_ai custom90;
526529
classDef custom91 fill:#fff2e6;
527-
class n_70_learning_paths_10_new_to_java_for_ai_20_link_40_ai_assisted_coding_10_coding_tools_md custom91;
530+
class n_70_learning_paths_10_new_to_java_for_ai_10_welcome_md custom91;
528531
classDef custom92 fill:#fff2e6;
529-
class n_70_learning_paths_10_new_to_java_for_ai_30_link_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j_md custom92;
532+
class n_70_learning_paths_10_new_to_java_for_ai_20_link_40_ai_assisted_coding_10_coding_tools_md custom92;
530533
classDef custom93 fill:#fff2e6;
531-
class n_70_learning_paths_10_new_to_java_for_ai_40_your_first_bot_md custom93;
534+
class n_70_learning_paths_10_new_to_java_for_ai_30_link_10_genai_30_using_llms_in_code_30_frameworks_10_langchain4j_md custom93;
532535
classDef custom94 fill:#fff2e6;
533-
class n_70_learning_paths_10_new_to_java_for_ai_50_add_memory_md custom94;
536+
class n_70_learning_paths_10_new_to_java_for_ai_40_your_first_bot_md custom94;
534537
classDef custom95 fill:#fff2e6;
535-
class n_70_learning_paths_10_new_to_java_for_ai_60_link_10_genai_30_using_llms_in_code_20_functionality_30_tool_calling_10_overview_md custom95;
538+
class n_70_learning_paths_10_new_to_java_for_ai_50_add_memory_md custom95;
536539
classDef custom96 fill:#fff2e6;
537-
class n_70_learning_paths_10_new_to_java_for_ai_70_deploy_md custom96;
540+
class n_70_learning_paths_10_new_to_java_for_ai_60_link_10_genai_30_using_llms_in_code_20_functionality_30_tool_calling_10_overview_md custom96;
538541
classDef custom97 fill:#fff2e6;
539-
class n_70_learning_paths_10_new_to_java_for_ai_80_optional_java_tricks_md custom97;
542+
class n_70_learning_paths_10_new_to_java_for_ai_70_deploy_md custom97;
540543
classDef custom98 fill:#fff2e6;
541-
class n_70_learning_paths_10_new_to_java_for_ai_90_now_what_md custom98;
542-
classDef custom99 fill:#ffcccc,stroke:yellow,stroke-width:4px,stroke-dasharray:0;
543-
class n_70_learning_paths_20_finetune_your_first_model custom99;
544-
classDef custom100 fill:#ffcccc,stroke:green,stroke-width:4px,stroke-dasharray:0;
545-
class n_70_learning_paths_30_new_to_java custom100;
544+
class n_70_learning_paths_10_new_to_java_for_ai_80_optional_java_tricks_md custom98;
545+
classDef custom99 fill:#fff2e6;
546+
class n_70_learning_paths_10_new_to_java_for_ai_90_now_what_md custom99;
547+
classDef custom100 fill:#ffcccc,stroke:yellow,stroke-width:4px,stroke-dasharray:0;
548+
class n_70_learning_paths_20_finetune_your_first_model custom100;
546549
classDef custom101 fill:#ffcccc,stroke:green,stroke-width:4px,stroke-dasharray:0;
547-
class n_70_learning_paths_40_new_to_ai custom101;
550+
class n_70_learning_paths_30_new_to_java custom101;
548551
classDef custom102 fill:#ffcccc,stroke:green,stroke-width:4px,stroke-dasharray:0;
549-
class n_70_learning_paths_50_new_to_ml custom102;
550-
classDef custom103 fill:#ffcccc,stroke:yellow,stroke-width:4px,stroke-dasharray:0;
551-
class n_70_learning_paths_60_training_first_model custom103;
552+
class n_70_learning_paths_40_new_to_ai custom102;
553+
classDef custom103 fill:#ffcccc,stroke:green,stroke-width:4px,stroke-dasharray:0;
554+
class n_70_learning_paths_50_new_to_ml custom103;
552555
classDef custom104 fill:#ffcccc,stroke:yellow,stroke-width:4px,stroke-dasharray:0;
553-
class n_70_learning_paths_70_building_first_ai_app custom104;
556+
class n_70_learning_paths_60_training_first_model custom104;
554557
classDef custom105 fill:#ffcccc,stroke:yellow,stroke-width:4px,stroke-dasharray:0;
555-
class n_70_learning_paths_80_langchain4j_tutorial custom105;
558+
class n_70_learning_paths_70_building_first_ai_app custom105;
556559
classDef custom106 fill:#ffcccc,stroke:yellow,stroke-width:4px,stroke-dasharray:0;
557-
class n_70_learning_paths_90_spring_ai_tutorial custom106;
560+
class n_70_learning_paths_80_langchain4j_tutorial custom106;
561+
classDef custom107 fill:#ffcccc,stroke:yellow,stroke-width:4px,stroke-dasharray:0;
562+
class n_70_learning_paths_90_spring_ai_tutorial custom107;
558563
linkStyle default interpolate basis
559564
```
560565

1.4 MB
Loading
259 KB
Loading
142 KB
Loading
7.17 MB
Loading
4.72 MB
Loading
183 KB
Loading
69.9 KB
Loading

0 commit comments

Comments
 (0)