← Back to all projects

LangChain4j

LLM integration written in Java conventions — annotated interfaces, POJOs, type safety

OfficialApache-2.0
Stars
13k
Forks
2.5k
Open issues
864
Last commit
28 Aug 2026

What is LangChain4j?

The headline feature is AI Services: you declare a Java interface, annotate it, and the library supplies the implementation that builds the prompt, calls the model and maps the reply back onto your return type. Underneath, a plain ChatModel API is there whenever the declarative layer gets in the way, and RAG, tool calling and integrations for Spring Boot, Quarkus, Micronaut and Helidon are first-party. Despite the name it is not a port of the Python library, so material from that ecosystem does not transfer.

What can you do with LangChain4j?

  • Declare an interface and get the implementation — AI Services turn an annotated Java interface into a working client: the prompt template, the model call and the conversion of the reply into your declared return type are all generated, so the calling code stays ordinary Java.
  • Drop to the primitives when you need to — ChatModel with UserMessage and AiMessage gives direct control over the exchange. The two layers coexist, so the declarative shortcut is never a one-way door.
  • Let the model call your methods — Tool calling binds Java methods to the model's function-calling interface, including code the model generates at run time, with the arguments arriving as typed parameters.
  • Build retrieval without leaving the JVM — Document loading, splitting, embedding, storage and retrieval are covered in one library, along with re-ranking and query transformation, across more than thirty embedding stores.
  • Wire it into the framework you already run — Spring Boot, Quarkus, Micronaut and Helidon all have official starters, so configuration, dependency injection and lifecycle follow the conventions of the host framework rather than the library's.

Before you choose LangChain4j

  • Despite the name it is not a port of the Python LangChain but an independent design, so chains, tutorials and community examples from that ecosystem do not carry across.

Star history

21 Aug to 28 Aug · +49

12.9k13k

Frequently asked questions

Is LangChain4j free for commercial use?

LangChain4j is released under the Apache-2.0 licence — OSI-approved open source, which permits commercial use.

How can LangChain4j be deployed?

LangChain4j is available as Self-hosted / Runs locally.

Documentation

Reproduced from the langchain4j/langchain4j README, published under Apache-2.0. Read the original ↗

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.