Spring / Spring AI interview questions
What is the Document class in Spring AI and how is it used in RAG?
The Document class is Spring AI's core data carrier for textual content flowing through a RAG pipeline. It wraps a piece of text together with a metadata map and an optional embedding vector, giving every chunk a consistent identity regardless of where it originated.
Key fields:
- id — auto-generated UUID uniquely identifying the chunk.
- content — the plain text of the chunk that gets embedded and later injected into prompts.
- metadata — a
Map<String, Object>carrying provenance data (source filename, page number, URL, creation date). This metadata is preserved through the VectorStore and returned alongside similarity search results, so you can cite sources in answers. - embedding — the float vector populated by the EmbeddingModel; null until the document is embedded.
// Creating a Document manually
Document doc = new Document(
"Spring AI simplifies AI integration in Java applications.",
Map.of("source", "spring-ai-docs.pdf", "page", 1)
);
// After similarity search you can access metadata
List<Document> results = vectorStore.similaritySearch(
SearchRequest.query(question).withTopK(3));
results.forEach(d -> {
System.out.println(d.getContent());
System.out.println("Source: " + d.getMetadata().get("source"));
});When you add documents to a VectorStore via vectorStore.add(docs), the store internally calls the EmbeddingModel to populate the embedding field before persisting. The caller does not need to embed documents separately in the typical flow.
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...
