Spring / Spring AI interview questions
What is an EmbeddingModel in Spring AI and why must the same model be used for ingestion and retrieval?
An EmbeddingModel in Spring AI is the abstraction for converting text into a dense float vector — a numerical representation where semantically similar texts produce vectors that are geometrically close. It is used in two places in the RAG lifecycle: during ingestion to embed document chunks, and at query time to embed the user's question so it can be compared against stored document embeddings.
@Service
public class EmbeddingDemo {
private final EmbeddingModel embeddingModel;
public EmbeddingDemo(EmbeddingModel embeddingModel) {
this.embeddingModel = embeddingModel;
}
public float[] vectorise(String text) {
return embeddingModel.embed(text); // returns float[]
}
}Spring AI supports embedding models from OpenAI (text-embedding-3-small, text-embedding-3-large), Azure OpenAI, Google Vertex AI, Mistral, Ollama (e.g. nomic-embed-text), and Amazon Bedrock.
The reason you must use the same model for both ingestion and retrieval is that each embedding model defines its own independent vector space. A vector produced by OpenAI's text-embedding-3-small exists in a 1536-dimensional space with a specific geometric structure. A vector from Ollama's nomic-embed-text lives in a completely different 768-dimensional space. Comparing a query vector from one model against document vectors from another is like comparing GPS coordinates in WGS-84 against coordinates in a local projection — the numbers are incompatible, and similarity scores become meaningless. Spring AI does not enforce this at startup; it is a developer responsibility.
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...
