← プロジェクト一覧に戻る

LangChain4j

型安全・POJO・アノテーションというJavaの流儀で書かれたLLM連携ライブラリ

公式Apache-2.0
スター
13k
フォーク
2.5k
オープンIssue
864
最終コミット
2026年8月28日

LangChain4jとは

看板機能はAI Servicesです。Javaのインターフェースを宣言してアノテーションを付けると、プロンプトの組み立て、モデルの呼び出し、返り値の型へのマッピングまでを実装として提供してくれます。その下には素のChatModel APIがあり、宣言的な層が邪魔になったときはいつでも降りられます。RAG、ツール呼び出し、Spring Boot・Quarkus・Micronaut・Helidonとの統合はいずれも公式提供です。名前は似ていますがPython版の移植ではないため、あちらの資料はそのままは通用しません。

LangChain4jで何ができますか?

  • インターフェースを宣言すれば実装が手に入る — AI Servicesは、アノテーションを付けたJavaのインターフェースを動くクライアントに変えます。プロンプトの雛形、モデル呼び出し、宣言した返り値型への変換までが生成されるため、呼び出す側のコードは普通のJavaのままです。
  • 必要なときは低レベルAPIへ降りる — ChatModelとUserMessage、AiMessageを使えばやり取りを直接制御できます。2つの層は共存しており、宣言的な近道を選んでも後戻りできなくなることはありません。
  • モデルに自分のメソッドを呼ばせる — ツール呼び出しはJavaのメソッドをモデルの関数呼び出しに結び付けます。実行時にモデルが生成したコードも対象にでき、引数は型の付いたパラメータとして渡ってきます。
  • JVMの中だけで検索を組む — 文書の読み込み、分割、埋め込み、保存、検索が1つのライブラリで完結し、再ランキングやクエリ変換も含まれます。埋め込みの保存先は30種類以上に対応しています。
  • 今動いているフレームワークに組み込む — Spring Boot、Quarkus、Micronaut、Helidonのいずれにも公式のスターターがあり、設定・DI・ライフサイクルはライブラリ側ではなくホスト側の作法に従います。

LangChain4jを選ぶ前に

  • 名前に反してPython版LangChainの移植ではなく独立した設計です。あちらのチェーン、チュートリアル、コミュニティ事例はそのままは持ち込めません。

スター推移

8月21日〜8月28日 · +49

12.9k13k

よくある質問

LangChain4jは商用利用できますか?

LangChain4jはApache-2.0ライセンスで公開されています。OSI承認のオープンソースライセンスで、商用利用が認められています。

LangChain4jはどの形で使えますか?

LangChain4jはセルフホスト・ローカル実行の形で利用できます。

ドキュメント

langchain4j/langchain4j のREADMEより転載(Apache-2.0)。 原文を読む ↗

LangChain4j: idiomatic, open-source Java library for building LLM-powered applications on the JVM

Introduction

Welcome!

The goal of LangChain4j is to simplify integrating LLMs into Java applications.

Here’s how:

  1. Unified APIs: LLM providers (like OpenAI or Google Vertex AI) and embedding (vector) stores (such as Pinecone or Milvus) use proprietary APIs. LangChain4j offers a unified API to avoid the need for learning and implementing specific APIs for each of them. To experiment with different LLMs or embedding stores, you can easily switch between them without the need to rewrite your code. LangChain4j currently supports 20+ popular LLM providers and 30+ embedding stores.
  2. Comprehensive Toolbox: Since early 2023, the community has been building numerous LLM-powered applications, identifying common abstractions, patterns, and techniques. LangChain4j has refined these into practical code. Our toolbox includes tools ranging from low-level prompt templating, chat memory management, and function calling to high-level patterns like Agents and RAG. For each abstraction, we provide an interface along with multiple ready-to-use implementations based on common techniques. Whether you’re building a chatbot or developing a RAG with a complete pipeline from data ingestion to retrieval, LangChain4j offers a wide variety of options.
  3. Numerous Examples: These examples showcase how to begin creating various LLM-powered applications, providing inspiration and enabling you to start building quickly.

LangChain4j began development in early 2023 amid the ChatGPT hype. We noticed a lack of Java counterparts to the numerous Python and JavaScript LLM libraries and frameworks, and we had to fix that!

Despite the name, LangChain4j is not a Java port of LangChain (Python) — it is built for Java, not ported to it. It is an idiomatic Java library designed from the ground up around Java conventions: type safety, POJOs, annotations, interfaces, dependency injection, fluent APIs, and first-class integrations with Quarkus, Spring Boot, Helidon, and Micronaut. Its API, internals, and release cycle are independent of the Python LangChain project.

We actively monitor community developments, aiming to quickly incorporate new techniques and integrations, ensuring you stay up-to-date. The library is under active development. While some features are still being worked on, the core functionality is in place, allowing you to start building LLM-powered apps now!

Documentation

Documentation can be found here.

The documentation chatbot (experimental) can be found here.

Getting Started

Getting started guide can be found here.

Code Examples

Please see examples of how LangChain4j can be used in langchain4j-examples repo:

Useful Materials

Useful materials can be found here.

Get Help

Please use Discord or GitHub discussions to get help.

Request Features

Please let us know what features you need by opening an issue.

Contribute

Contribution guidelines can be found here.

LangChain4j
AIに聞く
GitHub