docs/docs/integrations/embedding-stores/hazelcast.md
Hazelcast is a distributed in-memory data grid and computing platform. LangChain4j integrates with Hazelcast through two modules, split so the open-source path stays free of any Enterprise/licensing requirement:
langchain4j-community-hazelcast (open source) — provides HazelcastChatMemoryStore, a
ChatMemoryStore backed by a Hazelcast IMap. Runs against the open-source Community Edition
with no license.langchain4j-community-hazelcast-enterprise (requires Hazelcast Enterprise) — provides
HazelcastEmbeddingStore (vector search via VectorCollection) and
HazelcastCPMapChatMemoryStore (a strongly-consistent, CP-Subsystem-backed chat memory store).
This module re-exports langchain4j-community-hazelcast, so Enterprise consumers also get the
IMap-based store from the single dependency.<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-community-hazelcast</artifactId>
<version>${latest version here}</version>
</dependency>
The Hazelcast dependency is provided, so add the edition you run against. By default this is the
open-source Community Edition:
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>5.7.0</version>
</dependency>
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-community-hazelcast-enterprise</artifactId>
<version>${latest version here}</version>
</dependency>
Or use the BOM to manage versions consistently:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-community-bom</artifactId>
<version>${latest version here}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
:::note
HazelcastEmbeddingStore and HazelcastCPMapChatMemoryStore require Hazelcast Enterprise.
com.hazelcast:hazelcast-enterprise is not on Maven Central — it is pulled in transitively by
langchain4j-community-hazelcast-enterprise, but you must add the Hazelcast release repository and a
valid Enterprise license key:
<repositories>
<repository>
<id>hazelcast-release</id>
<name>Hazelcast Release Repository</name>
<url>https://repository.hazelcast.com/release/</url>
</repository>
</repositories>
Provide the license key via config.setLicenseKey(...) or the HZ_LICENSEKEY environment variable.
HazelcastCPMapChatMemoryStore additionally requires the CP Subsystem to be enabled; it fails fast
otherwise.
:::
HazelcastChatMemoryStore (open source) stores each chat memory as a JSON-serialised list of
ChatMessages in a Hazelcast IMap. The HazelcastInstance you supply may be an embedded member or
a thin client — the builder does not distinguish.
// Embedded member
HazelcastInstance hz = Hazelcast.newHazelcastInstance(new Config());
ChatMemoryStore store = HazelcastChatMemoryStore.builder()
.hazelcastInstance(hz)
.name("chatMemory") // optional, defaults to "chatMemory"
.build();
// Client connecting to an external cluster
ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().addAddress("hazelcast-host:5701");
HazelcastInstance hzClient = HazelcastClient.newHazelcastClient(clientConfig);
ChatMemoryStore store = HazelcastChatMemoryStore.builder()
.hazelcastInstance(hzClient)
.build();
You can also wrap a pre-configured IMap directly with
HazelcastChatMemoryStore.create(IMap<String, String>).
HazelcastCPMapChatMemoryStore (Enterprise) is an alternative backed by a CPMap in the
CP Subsystem. It is
linearizable (strongly consistent, Raft-backed), avoiding lost updates when the same memoryId
is updated concurrently. The CP Subsystem must be enabled on the instance.
Config config = new Config();
config.getCPSubsystemConfig().setCPMemberCount(3); // CP Subsystem must be enabled
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
ChatMemoryStore store = HazelcastCPMapChatMemoryStore.builder()
.hazelcastInstance(hz)
.name("chatMemory")
.build();
Trade-offs versus the IMap store: a CPMap is not partitioned (it must fit within each CP
member's RAM, default 100 MB total) and has no TTL/eviction. It suits many small conversations;
prefer the IMap-based store for unbounded history across a very large user population.
HazelcastEmbeddingStore (Enterprise) is backed by a Hazelcast VectorCollection. The vector index
dimension must match the embedding model in use; the metric defaults to COSINE.
HazelcastInstance hz = Hazelcast.newHazelcastInstance(new Config());
EmbeddingStore<TextSegment> store = HazelcastEmbeddingStore.builder()
.hazelcastInstance(hz)
.collectionName("embeddings") // optional, defaults to "embeddings"
.dimension(384) // required, must match the embedding model
.metric(Metric.COSINE) // optional, defaults to COSINE
.build();
You can also wrap a pre-configured VectorCollection with
HazelcastEmbeddingStore.create(VectorCollection<String, TextSegmentDocument>). The relevance score
returned by search(...) is Hazelcast's already-normalised COSINE score, used directly.
removeAll(Filter) is not supported — VectorCollection has no server-side predicate delete;
it throws UnsupportedFeatureException. Removal by id, removeAll(Collection<String>) and
removeAll() are supported.EmbeddingSearchRequest
carries a filter, it is applied client-side after retrieval (a warning is logged), which may
return fewer than maxResults matches.HazelcastChatMemoryStore — IMap-based (AP), open sourceHazelcastCPMapChatMemoryStore — CPMap-based (CP, linearizable), EnterpriseHazelcastEmbeddingStore — VectorCollection-based vector store, Enterprise