MCPcopy
hub / github.com/langchain4j/langchain4j

github.com/langchain4j/langchain4j @1.17.1 sqlite

repository ↗ · DeepWiki ↗ · release 1.17.1 ↗
28,491 symbols 168,544 edges 2,892 files 3,976 documented · 14%
README

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

Build Status Nightly Build CODACY

Discord BlueSky X Maven Version

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: - Examples in plain Java - Examples with Quarkus (uses quarkus-langchain4j dependency) - Example with Spring Boot - Examples with Helidon (uses io.helidon.integrations.langchain4j dependency) - Examples with Micronaut (uses micronaut-langchain4j dependency)

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.

Extension points exported contracts — how you extend this code

OvhAiApi (Interface)
@deprecated Do not use anymore, use langchain4j-open-ai module instead [20 implementers]
langchain4j-ovh-ai/src/main/java/dev/langchain4j/model/ovhai/internal/api/OvhAiApi.java
ChatMemoryProvider (Interface)
Provides instances of ChatMemory. Intended to be used with dev.langchain4j.service.AiServices. [10 implementers]
langchain4j/src/main/java/dev/langchain4j/memory/chat/ChatMemoryProvider.java
PromptTemplateFactory (Interface)
A factory for creating prompt templates. [35 implementers]
langchain4j-core/src/main/java/dev/langchain4j/spi/prompt/PromptTemplateFactory.java
AgentListener (Interface)
Listener interface for monitoring agent invocations. [12 implementers]
langchain4j-agentic/src/main/java/dev/langchain4j/agentic/observability/AgentListener.java
HttpClient (Interface)
A client for executing HTTP requests both synchronously and asynchronously. This interface is currently experimental and [61 …
langchain4j-http-client/src/main/java/dev/langchain4j/http/client/HttpClient.java
McpResourceContents (Interface)
A holder for either a 'McpTextResourceContents' or 'McpBlobResourceContents' object from the MCP protocol schema. [61 …
langchain4j-mcp/src/main/java/dev/langchain4j/mcp/client/McpResourceContents.java
MyAiServiceWithClassAnnotation (Interface)
(no doc) [34 implementers]
integration-tests/integration-tests-guardrails/src/test/java/dev/langchain4j/service/guardrail/InputGuardrailOnClassTest.java
AzureCosmosDBNoSqlFilterMapper (Interface)
(no doc) [20 implementers]
langchain4j-azure-cosmos-nosql/src/main/java/dev/langchain4j/rag/content/retriever/azure/cosmos/nosql/AzureCosmosDBNoSqlFilterMapper.java

Core symbols most depended-on inside this repo

build
called by 5328
langchain4j-agentic/src/main/java/dev/langchain4j/agentic/planner/AgenticService.java
isEqualTo
called by 5165
langchain4j-core/src/main/java/dev/langchain4j/store/embedding/filter/MetadataFilterBuilder.java
get
called by 3296
langchain4j-agentic/src/main/java/dev/langchain4j/agentic/internal/A2AService.java
put
called by 2987
langchain4j-core/src/main/java/dev/langchain4j/data/document/Metadata.java
of
called by 2628
langchain4j-bedrock/src/main/java/dev/langchain4j/model/bedrock/AbstractBedrockEmbeddingModel.java
build
called by 1601
langchain4j/src/main/java/dev/langchain4j/service/guardrail/GuardrailService.java
add
called by 1502
langchain4j-core/src/main/java/dev/langchain4j/memory/ChatMemory.java
modelName
called by 1176
langchain4j-core/src/main/java/dev/langchain4j/model/embedding/EmbeddingModel.java

Shape

Method 23,677
Class 3,834
Interface 796
Enum 184

Languages

Java100%

Modules by API surface

langchain4j/src/test/java/dev/langchain4j/service/AiServicesWithToolsIT.java172 symbols
langchain4j/src/test/java/dev/langchain4j/service/common/AbstractAiServiceWithJsonSchemaIT.java143 symbols
langchain4j-agentic/src/test/java/dev/langchain4j/agentic/DeclarativeAgentIT.java142 symbols
langchain4j/src/test/java/dev/langchain4j/service/output/PolymorphicOutputParserTest.java112 symbols
langchain4j-hibernate/src/main/java/dev/langchain4j/store/embedding/hibernate/HibernateEmbeddingStore.java101 symbols
langchain4j-open-ai-official/src/main/java/dev/langchain4j/model/openaiofficial/OpenAiOfficialResponsesStreamingChatModel.java98 symbols
langchain4j/src/test/java/dev/langchain4j/service/common/AbstractAiServiceWithToolsIT.java93 symbols
langchain4j/src/test/java/dev/langchain4j/service/AiServicesIT.java91 symbols
langchain4j-core/src/test/java/dev/langchain4j/agent/tool/ToolSpecificationsTest.java90 symbols
langchain4j-core/src/test/java/dev/langchain4j/model/chat/common/AbstractBaseChatModelIT.java88 symbols
langchain4j/src/test/java/dev/langchain4j/service/AiServicesUserMessageConfigTest.java86 symbols
langchain4j-google-ai-gemini/src/test/java/dev/langchain4j/model/googleai/GoogleAiGeminiBatchEmbeddingModelTest.java73 symbols

Dependencies from manifests, versioned

${coherence.groupId}:coherence
${coherence.groupId}:coherence-bedrock-testing-support
${coherence.groupId}:coherence-bom
${coherence.groupId}:coherence-hnsw
${quarkus.platform.group-id}:${quarkus.platform.artifact-id}
ai.djl.huggingface:tokenizers
ai.djl:api
ai.docling:docling-serve-api
ai.docling:docling-serve-client
ai.docling:docling-testcontainers
ch.qos.logback:logback-classic1.5.32 · 1×
co.elastic.clients:elasticsearch-java

Datastores touched

(mongodb)Database · 1 repos
postgresDatabase · 1 repos
(mysql)Database · 1 repos

For agents

$ claude mcp add langchain4j \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact