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
Copied
  • 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);
}
Copied
  • 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) { 
    }
}
Copied
  • Injects the same named content retriever bean directly into another Helidon declarative service.

Configuration properties:

Configuration options

KeyKindTypeDefault ValueDescription
display-nameVALUEString Display name for this content retriever configuration
embedding-modelVALUEString Explicit embedding model to use in the content retriever
embedding-storeVALUEString Embedding store to use in the content retriever
enabledVALUEBooleantrueIf set to false, component will be disabled even if configured
max-resultsVALUEInteger Maximum number of results to return from the retriever
min-scoreVALUEDouble Minimum score threshold for retrieved results
typeVALUEi.h.i.l.ContentRetrieverTypeEMBEDDING_STORE_CONTENT_RETRIEVERType 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 
Copied
  • 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")); 
    }
}
Copied
  • 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:

Configuration options

KeyKindTypeDefault ValueDescription
enabledVALUEBooleantrueWhether this embedding store component is enabled
from-fileVALUEPath Path to a JSON file used to initialize the in-memory embedding store via InMemoryEmbeddingStore.fromFile

Additional Information