AI / LangChain4j interview questions
What is the ContentRetriever and RetrievalAugmentor in LangChain4j advanced RAG?
LangChain4j's advanced RAG API introduces a cleaner abstraction hierarchy above the basic EmbeddingStoreContentRetriever. The two key interfaces are ContentRetriever and RetrievalAugmentor.
ContentRetriever is the interface responsible for fetching relevant content given a query. Multiple implementations are available:
EmbeddingStoreContentRetriever— retrieves via vector similarity from an EmbeddingStoreWebSearchContentRetriever— fetches live web results (e.g., via Tavily, Google) for up-to-date informationSqlDatabaseContentRetriever— generates and executes SQL to retrieve structured data (text-to-SQL RAG)
RetrievalAugmentor is the higher-level orchestrator that sits between the user query and the LLM call. The default implementation, DefaultRetrievalAugmentor, exposes a full pipeline with configurable stages:
- Query transformer — Rewrites or decomposes the original query (e.g., query compression using conversation history, or HyDE — Hypothetical Document Embeddings)
- Query router — Routes queries to one or more ContentRetrievers based on the query type
- Content aggregator — Merges results from multiple retrievers
- Content injector — Formats retrieved content for injection into the prompt
RetrievalAugmentor augmentor = DefaultRetrievalAugmentor.builder() .queryTransformer(new CompressingQueryTransformer(chatModel)) .contentRetriever(EmbeddingStoreContentRetriever.from(store)) .contentInjector(DefaultContentInjector.builder() .promptTemplate(PromptTemplate.from("Context:\n{{contents}}\n\nQuestion: {{userMessage}}")) .build()) .build();
More Related questions...