Contents
Maven Coordinates
No additional dependencies are required beyond the LangChain4j integration core dependencies.
Content Retriever
Provider key: lc4j-content-retriever.
In LangChain4j RAG, ContentRetriever is the component that takes a user query, retrieves relevant content from an underlying data source, and returns ranked content used to augment the prompt.
In Helidon, this provider creates LangChain4j content retrievers from configuration. If type is not set, Helidon uses the default embedding-store-content-retriever (ContentRetrieverType.EMBEDDING_STORE_CONTENT_RETRIEVER) and wires it using the configured embedding model and embedding store.
In a typical RAG setup (see RAG), a named retriever references:
an
EmbeddingModel(embedding-model)an
EmbeddingStore<TextSegment>(embedding-store)
Each entry under langchain4j.content-retrievers becomes a named singleton declarative service bean in the Helidon service registry. You can attach it to AI services or agents using @Ai.ContentRetriever("name"), or inject it directly by name.
langchain4j:
content-retrievers:
foo-bar-content-retriever:
provider: lc4j-content-retriever
type: embedding-store-content-retriever
embedding-store: foo-bar-inmemory-embedding-store
embedding-model: foo-bar-embedding-model
max-results: 10
min-score: 0.6- Selects the built-in content retriever provider.
- Explicitly selects the default LangChain4j embedding-store-backed retriever type.
- Names the embedding store bean used for similarity search.
- Sets the embedding model used to convert incoming query text to vectors.
@Ai.Service
@Ai.ChatModel("foo-bar-chat-model")
@Ai.ContentRetriever("foo-bar-content-retriever")
public interface FooBarExpert {
String askFoo(String foo);
}- Binds this AI service to the named content retriever bean from configuration.
@Service.Singleton
public class RetrieverConsumer {
RetrieverConsumer(@Service.Named("foo-bar-content-retriever") ContentRetriever retriever) {
}
}- Injects the same named content retriever bean directly into another Helidon declarative service.
Configuration properties:
Configuration options
| Key | Kind | Type | Default Value | Description |
|---|---|---|---|---|
display-name | VALUE | String | Display name for this content retriever configuration | |
embedding-model | VALUE | String | Explicit embedding model to use in the content retriever | |
embedding-store | VALUE | String | Embedding store to use in the content retriever | |
enabled | VALUE | Boolean | true | If set to false, component will be disabled even if configured |
max-results | VALUE | Integer | Maximum number of results to return from the retriever | |
min-score | VALUE | Double | Minimum score threshold for retrieved results | |
type | VALUE | i.h.i.l.ContentRetrieverType | EMBEDDING_STORE_CONTENT_RETRIEVER | Type of content retriever to create |
In-Memory Embedding Store
Provider key: lc4j-in-memory.
In LangChain4j in-memory embedding store integration, InMemoryEmbeddingStore is an in-process vector store implementation suitable for local or lightweight use cases.
In Helidon, this provider creates InMemoryEmbeddingStore<TextSegment> instances from langchain4j.embedding-stores.<name> configuration entries.
Each entry becomes a named singleton declarative service bean in the Helidon service registry. That named embedding store can be referenced by configured content retrievers and can also be injected by name into other service beans.
If from-file is configured, Helidon initializes the store by loading previously persisted embeddings and segments using LangChain4j InMemoryEmbeddingStore.fromFile(…). If from-file is not configured, the store starts empty.
langchain4j:
embedding-stores:
foo-bar-inmemory-embedding-store:
provider: lc4j-in-memory
# optional: preload persisted store content
from-file: "target/foo-bar-inmemory-embedding-store.json"
content-retrievers:
foo-bar-content-retriever:
provider: lc4j-content-retriever
embedding-model: foo-bar-embedding-model
embedding-store: foo-bar-inmemory-embedding-store - Selects the built-in LangChain4j in-memory embedding store provider.
- Loads previously persisted embeddings and text segments during startup.
- Connects the retriever to the named in-memory embedding store bean.
@Service.Singleton
public class EmbeddingStoreLifecycle {
private final InMemoryEmbeddingStore<TextSegment> store;
EmbeddingStoreLifecycle(@Service.Named("foo-bar-inmemory-embedding-store")
InMemoryEmbeddingStore<TextSegment> store) {
this.store = store;
}
@Service.PreDestroy
void persistEmbeddingStore() {
store.serializeToFile(Path.of("target/foo-bar-inmemory-embedding-store.json"));
}
}- Invoked by Helidon when the singleton service bean is being shut down.
- Persists current in-memory embeddings and segments to JSON file; the same file can be loaded on next startup using
from-file.
Configuration properties: