Spring / Spring AI interview questions
What is the role of MetadataEnricher and KeywordMetadataEnricher in Spring AI?
Metadata enrichers are DocumentTransformer implementations that augment each Document's metadata map before it is stored in the VectorStore. Richer metadata improves retrieval quality because metadata filter expressions in SearchRequest can then precisely target relevant subsets — for example, filtering by document category, author, or auto-extracted keywords rather than doing a pure vector similarity search over everything.
KeywordMetadataEnricher is the most commonly used enricher. It sends each document's content to the LLM and asks it to extract the top-N keywords, then stores those keywords in the document's metadata under a configurable key.
KeywordMetadataEnricher enricher = new KeywordMetadataEnricher(
chatModel, // the LLM does the extraction
5 // extract 5 keywords per document
);
List<Document> enriched = enricher.apply(splitDocs);
// Each doc's metadata now contains: {"excerpt_keywords": "Spring AI, RAG, VectorStore, ..."}
// Now you can filter by keyword at retrieval time
Filter.Expression kwFilter = new Filter.ExpressionBuilder()
.contains("excerpt_keywords", "RAG")
.build();SummaryMetadataEnricher is a similar enricher that generates short summaries of adjacent document windows and stores them as metadata, improving contextual retrieval for long documents where individual chunks lack enough surrounding context to score highly on their own.
Both enrichers make LLM calls per document, adding latency and cost to the ingestion pipeline. Run them during the initial bulk ingestion and cache the enriched documents rather than re-enriching on every pipeline run.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
